Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: sync commits from Aspect-internal silo #763

Merged
merged 23 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
44d3451
refactor: drop Pro from Aspect CLI versioning by making Aspect CLI OS…
gregmagolan Sep 28, 2024
a40ba8e
refactor: stamp Aspect CLI with monorepo version scheme <year>.<week>…
gregmagolan Sep 28, 2024
63059f6
fix(cli): support .gitignore ignoring of directories (#6880)
jbedard Oct 1, 2024
caf2b61
fix(cli): support package.json exports/main references to outputted .…
jbedard Oct 2, 2024
2a59789
fix(cli): generated npm package srcs vs deps attributes (#6965)
jbedard Oct 2, 2024
2b3c6ed
refactor(cli): cleanup file type checks (#6966)
jbedard Oct 2, 2024
ee4ee1a
fix(cli): tsconfig rootdir filtering of source files (#6978)
jbedard Oct 2, 2024
7b56040
fix(cli): set npm_package(srcs) as mergeable gazelle attribute (#6984)
jbedard Oct 2, 2024
536b648
fix(cli): support direct import of outputted dts files (#6977)
jbedard Oct 2, 2024
44c6169
feat: added --fixes flag to Aspect CLI lint command (#7015)
gregmagolan Oct 7, 2024
334da8f
refactor(cli): upgrade tree-sitter grammars (#7028)
jbedard Oct 7, 2024
6ea2ae7
fix(cli): treat package.json imports as optional dependencies (#7044)
jbedard Oct 8, 2024
b598099
refactor(cli): remove unnecessary log statement (#6983)
jbedard Oct 9, 2024
ac8855a
test(cli): gazelle triple slash test cases (#7057)
jbedard Oct 9, 2024
bc22bf5
test(cli): data files in non-generated BUILD files (#7058)
jbedard Oct 9, 2024
7731bb1
fix(cli): show correct paths in orion error stack traces (#7034)
jbedard Oct 9, 2024
97eba35
fix(cli): reduce tsconfig paths precedence below pnpm workspace proje…
jbedard Oct 10, 2024
cc1d2b9
refactor(cli): move gazelle gitignore and walk logic to common (#7016)
jbedard Oct 10, 2024
0304de2
feat(cli): set generated BUILD npm package target visibility to publi…
jbedard Oct 14, 2024
b6c9b5f
docs(gazelle): correct deprecated js_generation_mode docs (#7098)
jbedard Oct 17, 2024
0448760
fix(cli): make isFlagInFlagSet more robust incase it is called with '…
jbedard Oct 18, 2024
ac777f6
chore: resolve dependabot alerts from test case pnpm-lock files (#7128)
gregmagolan Oct 21, 2024
8376606
perf(cli): pre-validate aspect-configure glob patterns (#7135)
jbedard Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")

# gazelle:exclude **/*.d.ts

write_source_files(
name = "write_pb_go",
additional_update_targets = [
"//bazel/action_cache:write_pb_go",
"//bazel/analysis:write_pb_go",
"//bazel/buildeventstream:write_pb_go",
"//bazel/command_line:write_pb_go",
"//bazel/failure_details:write_pb_go",
"//bazel/flags:write_pb_go",
"//bazel/invocation_policy:write_pb_go",
"//bazel/options:write_pb_go",
"//bazel/packages_metrics:write_pb_go",
"//bazel/query:write_pb_go",
],
)
36 changes: 18 additions & 18 deletions buildinfo/build_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const (
)

type BuildInfo struct {
BuildTime string
HostName string
GitCommit string
GitStatus string
Release string
IsAspectPro bool
BuildTime string
HostName string
GitCommit string
GitStatus string
Release string
OpenSource bool
}

func New(
Expand All @@ -56,15 +56,15 @@ func New(
gitCommit string,
gitStatus string,
release string,
pro bool,
oss bool,
) *BuildInfo {
return &BuildInfo{
BuildTime: buildTime,
HostName: hostName,
GitCommit: gitCommit,
GitStatus: gitStatus,
Release: release,
IsAspectPro: pro,
BuildTime: buildTime,
HostName: hostName,
GitCommit: gitCommit,
GitStatus: gitStatus,
Release: release,
OpenSource: oss,
}
}

Expand All @@ -75,7 +75,7 @@ func Current() *BuildInfo {
GitCommit,
GitStatus,
Release,
IsAspectPro != "",
OpenSource != "",
)
}

Expand All @@ -101,16 +101,16 @@ func (bi BuildInfo) Version() string {
}

func (bi BuildInfo) Name() string {
if bi.IsAspectPro {
return "Aspect CLI Pro"
if bi.OpenSource {
return "Aspect CLI OSS"
} else {
return "Aspect CLI"
}
}

func (bi BuildInfo) GnuName() string {
if bi.IsAspectPro {
return "aspect pro"
if bi.OpenSource {
return "aspect oss"
} else {
return "aspect"
}
Expand Down
24 changes: 12 additions & 12 deletions buildinfo/build_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func TestNew(t *testing.T) {
g := NewGomegaWithT(t)
actual := buildinfo.New(buildTime, hostName, gitCommit, gitStatus, release, false)
expected := &buildinfo.BuildInfo{
BuildTime: buildTime,
HostName: hostName,
GitCommit: gitCommit,
GitStatus: gitStatus,
Release: release,
IsAspectPro: false,
BuildTime: buildTime,
HostName: hostName,
GitCommit: gitCommit,
GitStatus: gitStatus,
Release: release,
OpenSource: false,
}
g.Expect(actual).To(Equal(expected))
}
Expand All @@ -51,12 +51,12 @@ func TestCurrent(t *testing.T) {
g := NewGomegaWithT(t)
actual := buildinfo.Current()
expected := &buildinfo.BuildInfo{
BuildTime: buildinfo.BuildTime,
HostName: buildinfo.HostName,
GitCommit: buildinfo.GitCommit,
GitStatus: buildinfo.GitStatus,
Release: buildinfo.Release,
IsAspectPro: buildinfo.IsAspectPro != "",
BuildTime: buildinfo.BuildTime,
HostName: buildinfo.HostName,
GitCommit: buildinfo.GitCommit,
GitStatus: buildinfo.GitStatus,
Release: buildinfo.Release,
OpenSource: buildinfo.OpenSource != "",
}
g.Expect(actual).To(Equal(expected))
}
Expand Down
4 changes: 2 additions & 2 deletions buildinfo/stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var GitStatus = "unknown"
// Release is the revision number, if any.
var Release = "no release"

// IsAspectPro indicates if this is an Aspect CLI Pro build
var IsAspectPro = ""
// OpenSource indicates if this is an Aspect CLI OSS build
var OpenSource = ""

func IsStamped() bool {
return BuildTime != "{BUILD_TIMESTAMP}"
Expand Down
1 change: 1 addition & 0 deletions cmd/aspect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"//cmd:__subpackages__",
"//release:__pkg__", # For https://github.com/aspect-build/aspect-cli release
],
x_defs = {"aspect.build/cli/buildinfo.OpenSource": "true"},
deps = [
"//cmd/aspect/root",
"//pkg/aspect/root/config",
Expand Down
9 changes: 4 additions & 5 deletions cmd/aspect/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func NewCmd(
) *cobra.Command {
cmd := &cobra.Command{
Use: "aspect",
Short: buildinfo.Current().Name(),
Short: "Aspect CLI",
SilenceUsage: true,
SilenceErrors: true,
Long: boldCyan.Sprintf(buildinfo.Current().Name()) + ` is a better frontend for running bazel`,
Long: boldCyan.Sprintf("Aspect CLI is a better frontend for running bazel"),
// Suppress timestamps in generated Markdown, for determinism
DisableAutoGenTag: true,
Version: buildinfo.Current().Version(),
Expand All @@ -129,7 +129,6 @@ func NewCmd(
flags.AddGlobalFlags(cmd, defaultInteractive)
cmd.AddGroup(&cobra.Group{ID: "common", Title: "Common Bazel Commands:"})
cmd.AddGroup(&cobra.Group{ID: "aspect", Title: "Commands only in Aspect CLI:"})
cmd.AddGroup(&cobra.Group{ID: "aspect-pro", Title: "Commands only in Aspect CLI Pro:"})
cmd.AddGroup(&cobra.Group{ID: "plugin", Title: "Custom Commands from Plugins:"})
cmd.AddGroup(&cobra.Group{ID: "built-in", Title: "Other Bazel Built-in Commands:"})

Expand Down Expand Up @@ -161,8 +160,8 @@ func NewCmd(
cmd.AddCommand(outputs.NewDefaultCmd())
cmd.SetHelpCommand(help.NewCmd())

if !buildinfo.Current().IsAspectPro {
// Aspect CLI only commands
if buildinfo.Current().OpenSource {
// Aspect CLI OSS command configurations
cmd.AddCommand(lint.NewDefaultCmd(pluginSystem))
cmd.AddCommand(license.NewDefaultCmd())
cmd.AddCommand(configure.NewDefaultCmd())
Expand Down
1 change: 1 addition & 0 deletions cmd/docgen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = ["main.go"],
importpath = "aspect.build/cli/cmd/docgen",
visibility = ["//visibility:private"],
x_defs = {"aspect.build/cli/buildinfo.OpenSource": "true"},
deps = [
"//cmd/aspect/root",
"//pkg/bazel",
Expand Down
7 changes: 4 additions & 3 deletions docs/aspect_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ aspect lint <target patterns> [flags]

```
--diff Show unified diff instead of diff stats for fixes
--fix Apply all patch fixes for lint violations
--fix Auto-apply all fixes
--fixes Request fixes from linters (where supported) (default true)
-h, --help help for lint
--machine Request the machine readable output from linters
--report Output lint reports (default true)
--machine Request machine readable lint reports from linters (where supported)
--report Request lint reports from linters (default true)
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/help/topics/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ enable other projects to declare dependencies on the package.
| Equivalent to `js_files` but for the test `ts_project` rule. |
| `# gazelle:js_npm_package_target_name _name_` | `{dirname}` |
| The format used to generate the name of the `npm_package` rule. |
| `# gazelle:generation_mode update\|create` | `create` |
| `# gazelle:js_generation_mode update\|create` | `create` |
| DEPRECATED: see `generation_mode` directive. |
| `# gazelle:js_custom_files _name_ _glob_` | |
| DEPRECATED:Generate additional custom `ts_project` targets |
Expand Down
2 changes: 2 additions & 0 deletions gazelle/common/git/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ go_library(
importpath = "aspect.build/cli/gazelle/common/git",
visibility = ["//visibility:public"],
deps = [
"//gazelle/common",
"//pkg/logger",
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//rule:go_default_library",
"@com_github_go_git_go_git_v5//plumbing/format/gitignore",
],
)
Expand Down
47 changes: 37 additions & 10 deletions gazelle/common/git/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import (
"path"
"strings"

common "aspect.build/cli/gazelle/common"
BazelLog "aspect.build/cli/pkg/logger"
"github.com/bazelbuild/bazel-gazelle/config"
"github.com/bazelbuild/bazel-gazelle/rule"
gitignore "github.com/go-git/go-git/v5/plumbing/format/gitignore"
)

// TODO: remove and align with gazelle after https://github.com/aspect-build/aspect-cli/issues/755

// Must align with patched bazel-gazelle
const ASPECT_GITIGNORE = "__aspect:gitignore"

type isGitIgnoredFunc = func(string, bool) bool

// Directive to enable/disable gitignore support
const Directive_GitIgnore = "gitignore"

Expand All @@ -23,7 +29,7 @@ const enabledExt = Directive_GitIgnore
const lastConfiguredExt = "gitignore:dir"
const ignorePatternsExt = "gitignore:patterns"

func CollectIgnoreFiles(c *config.Config, rel string) {
func collectIgnoreFiles(c *config.Config, rel string) {
// Only parse once per directory.
if lastCollected, hasCollected := c.Exts[lastConfiguredExt]; hasCollected && lastCollected == rel {
return
Expand All @@ -42,12 +48,33 @@ func CollectIgnoreFiles(c *config.Config, rel string) {
}
}

func EnableGitignore(c *config.Config, enabled bool) {
c.Exts[enabledExt] = enabled
if enabled {
c.Exts[ASPECT_GITIGNORE] = createMatcherFunc(c)
} else {
c.Exts[ASPECT_GITIGNORE] = nil
func ReadGitConfig(c *config.Config, rel string, f *rule.File) {
// Enable .gitignore support by default in Aspect gazelle languages.
// TODO: default to false and encourage use of .bazelignore instead
if rel == "" {
_, exists := c.Exts[enabledExt]
if !exists {
c.Exts[enabledExt] = true
}
}

// Collect ignore files within this config directory.
collectIgnoreFiles(c, rel)

// Collect config from directives within this BUILD.
if f != nil {
for _, d := range f.Directives {
switch d.Key {
case Directive_GitIgnore:
enabled := common.ReadEnabled(d)
c.Exts[enabledExt] = enabled
if enabled {
c.Exts[ASPECT_GITIGNORE] = createMatcherFunc(c)
} else {
c.Exts[ASPECT_GITIGNORE] = nil
}
}
}
}
}

Expand Down Expand Up @@ -97,14 +124,14 @@ func parseIgnore(rel string, ignoreReader io.Reader) []gitignore.Pattern {
return matcherPatterns
}

func createMatcherFunc(c *config.Config) func(string) bool {
func createMatcherFunc(c *config.Config) isGitIgnoredFunc {
patterns, patternsFound := c.Exts[ignorePatternsExt]
if !patternsFound {
return nil
}

matcher := gitignore.NewMatcher(patterns.([]gitignore.Pattern))
return func(s string) bool {
return matcher.Match(strings.Split(s, "/"), false)
return func(s string, isDir bool) bool {
return matcher.Match(strings.Split(s, "/"), isDir)
}
}
24 changes: 22 additions & 2 deletions gazelle/common/git/gitignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ func TestGitIgnore(t *testing.T) {
shouldMatch := func(what string, c *config.Config, matches ...string) {
matcher := createMatcherFunc(c)
for _, m := range matches {
if !(matcher != nil && matcher(m)) {
// Use trailing slash in test data to indicate directory
isDir := strings.HasSuffix(m, "/")
m = strings.TrimSuffix(m, "/")

if !(matcher != nil && matcher(m, isDir)) {
t.Error(fmt.Sprintf("%s should match '%s'", what, m))
}
}
}
shouldNotMatch := func(what string, c *config.Config, matches ...string) {
matcher := createMatcherFunc(c)
for _, m := range matches {
if matcher != nil && matcher(m) {
// Use trailing slash in test data to indicate directory
isDir := strings.HasSuffix(m, "/")
m = strings.TrimSuffix(m, "/")

if matcher != nil && matcher(m, isDir) {
t.Error(fmt.Sprintf("%s should NOT match '%s'", what, m))
}
}
Expand Down Expand Up @@ -183,6 +191,18 @@ func TestGitIgnore(t *testing.T) {
shouldMatch("double wildcard", c, "subdir/x.starstar.ts", "subdir/a/b/c/x.starstar.ts", "subdir/a/.starstar.ts")
shouldNotMatch("double wildcard different subdir", c, "startstar.ts", ".startstar.ts", "a/starstar.ts")
})

t.Run("dir specific matches", func(t *testing.T) {
c := config.New()
addIgnoreFileContent(c, "", `
**/node_modules/
**/foo.js/
`)

shouldMatch("dir pattern", c, "node_modules/", "a/b/node_modules/")
shouldMatch("dir pattern that looks like a file", c, "foo.js/", "a/b/foo.js/")
shouldNotMatch("ending file that looks like dir", c, "node_modules", "x/node_modules", "foo.js", "x/foo.js")
})
}

// Util method to invoke GitIgnore.AddIgnore() with the trimmed string
Expand Down
4 changes: 3 additions & 1 deletion gazelle/common/starlark/utils/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func evalCallbackString(stack starlark.CallStack) string {
fmt.Fprintf(out, "Traceback (most recent call last):\n")
}
for _, fr := range stack {
fmt.Fprintf(out, " %s: in %s\n", strings.TrimLeft(fr.Pos.String(), strip), fr.Name)
p := strings.TrimPrefix(fr.Pos.String(), strip)
p = strings.Trim(p, " \n\r\t/\\")
fmt.Fprintf(out, " %s: in %s\n", p, fr.Name)
}
return out.String()
}
Expand Down
Loading
Loading