diff --git a/WORKSPACE b/WORKSPACE index f94b75b7a..23ec04ae0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -129,6 +129,10 @@ go_register_toolchains(version = "1.22.3") http_archive( name = "bazel_gazelle", + patch_args = ["-p1"], + patches = [ + "//:patches/bazelbuild_bazel-gazelle_aspect-cli.patch", + ], sha256 = "d76bf7a60fd8b050444090dfa2837a4eaf9829e1165618ee35dceca5cbdf58d5", # Ensure this version always matches the version of @com_github_bazelbuild_bazel_gazelle set in deps.bzl. # @@ -163,6 +167,22 @@ protoc_toolchains( version = "v21.7", ) +http_archive( + name = "rules_python", + integrity = "sha256-bERKXOYmJB6fdw/0TFPBLWen8f+81eG2p0EAneLkBAo=", + strip_prefix = "rules_python-49cdf7d3fe000076d6432a34238e5d25f5b598d0", + # NB: version matches go.mod where we fetch the rules_python/gazelle Go package. + url = "https://github.com/bazelbuild/rules_python/archive/49cdf7d3fe000076d6432a34238e5d25f5b598d0.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +load("@rules_python//gazelle:deps.bzl", "python_stdlib_list_deps") + +python_stdlib_list_deps() + load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") load("//:go.bzl", _go_repositories = "deps") diff --git a/cmd/aspect/configure/configure.go b/cmd/aspect/configure/configure.go index 59b8de010..774cc3f15 100644 --- a/cmd/aspect/configure/configure.go +++ b/cmd/aspect/configure/configure.go @@ -30,8 +30,9 @@ func NewDefaultCmd() *cobra.Command { } func NewCmd(streams ioutils.Streams) *cobra.Command { - v := configure.New(streams) - + return NewCmdWithConfigure(streams, configure.New(streams)) +} +func NewCmdWithConfigure(streams ioutils.Streams, v *configure.Configure) *cobra.Command { cmd := &cobra.Command{ Use: "configure", Short: "Auto-configure Bazel by updating BUILD files", @@ -46,13 +47,17 @@ Run 'aspect help directives' for more documentation on directives. So far these languages are supported: - Go and Protocol Buffers, thanks to code from [gazelle] +- Python, thanks to code from [rules_python] - JavaScript (including TypeScript) - Kotlin (experimental, see https://github.com/aspect-build/aspect-cli/issues/474) +- Starlark, thanks to code from [bazel-skylib] configure is based on [gazelle]. We are very grateful to the authors of that software. The advantage of configure in Aspect CLI is that you don't need to compile the tooling before running it. [gazelle]: https://github.com/bazelbuild/bazel-gazelle +[rules_python]: https://github.com/bazelbuild/rules_python/tree/main/gazelle +[bazel-skylib]: https://github.com/bazelbuild/bazel-skylib/tree/main/gazelle To change the behavior of configure, you add "directives" to your BUILD files, which are comments in a special syntax. diff --git a/cmd/aspect/lint/lint.go b/cmd/aspect/lint/lint.go index 82d5b7ab5..ae408616e 100644 --- a/cmd/aspect/lint/lint.go +++ b/cmd/aspect/lint/lint.go @@ -28,10 +28,10 @@ import ( ) func NewDefaultCmd(pluginSystem system.PluginSystem) *cobra.Command { - return NewCmd(ioutils.DefaultStreams, pluginSystem, bazel.WorkspaceFromWd, []lint.LintHandler{}) + return NewCmd(ioutils.DefaultStreams, pluginSystem, bazel.WorkspaceFromWd, []lint.LintResultsHandler{}) } -func NewCmd(streams ioutils.Streams, pluginSystem system.PluginSystem, bzl bazel.Bazel, lintHandlers []lint.LintHandler) *cobra.Command { +func NewCmd(streams ioutils.Streams, pluginSystem system.PluginSystem, bzl bazel.Bazel, lintHandlers []lint.LintResultsHandler) *cobra.Command { cmd := &cobra.Command{ Use: "lint ", Args: cobra.MinimumNArgs(1), diff --git a/cmd/aspect/root/root.go b/cmd/aspect/root/root.go index 9a846ad62..c1f913cf6 100644 --- a/cmd/aspect/root/root.go +++ b/cmd/aspect/root/root.go @@ -73,11 +73,14 @@ func NewDefaultCmd(pluginSystem system.PluginSystem) *cobra.Command { func CheckAspectLockVersionFlag(args []string) bool { for _, arg := range args { - if arg == "--"+flags.AspectLockVersion { + if arg == "--"+flags.AspectLockVersion+"=false" { + return false + } + if arg == "--"+flags.AspectLockVersion+"=true" || arg == "--"+flags.AspectLockVersion { return true } } - return false + return flags.AspectLockVersionDefault() } func CheckAspectDisablePluginsFlag(args []string) bool { @@ -156,13 +159,13 @@ func NewCmd( cmd.AddCommand(test.NewDefaultCmd(pluginSystem)) cmd.AddCommand(version.NewDefaultCmd()) cmd.AddCommand(outputs.NewDefaultCmd()) - cmd.AddCommand(configure.NewDefaultCmd()) cmd.SetHelpCommand(help.NewCmd()) if !buildinfo.Current().IsAspectPro { // Aspect CLI only commands cmd.AddCommand(lint.NewDefaultCmd(pluginSystem)) cmd.AddCommand(license.NewDefaultCmd()) + cmd.AddCommand(configure.NewDefaultCmd()) } // ### "Additional help topic commands" which are not runnable diff --git a/docs/aspect_configure.md b/docs/aspect_configure.md index a588ccfc3..debfedc0f 100644 --- a/docs/aspect_configure.md +++ b/docs/aspect_configure.md @@ -18,13 +18,17 @@ Run 'aspect help directives' for more documentation on directives. So far these languages are supported: - Go and Protocol Buffers, thanks to code from [gazelle] +- Python, thanks to code from [rules_python] - JavaScript (including TypeScript) - Kotlin (experimental, see https://github.com/aspect-build/aspect-cli/issues/474) +- Starlark, thanks to code from [bazel-skylib] configure is based on [gazelle]. We are very grateful to the authors of that software. The advantage of configure in Aspect CLI is that you don't need to compile the tooling before running it. [gazelle]: https://github.com/bazelbuild/bazel-gazelle +[rules_python]: https://github.com/bazelbuild/rules_python/tree/main/gazelle +[bazel-skylib]: https://github.com/bazelbuild/bazel-skylib/tree/main/gazelle To change the behavior of configure, you add "directives" to your BUILD files, which are comments in a special syntax. diff --git a/docs/help/topics/directives.md b/docs/help/topics/directives.md index 47024453e..3df7334c4 100644 --- a/docs/help/topics/directives.md +++ b/docs/help/topics/directives.md @@ -65,8 +65,8 @@ 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:js_tsconfig _filename_` | `tsconfig.json` | -| Path to a `tsconfig.json` file used to help generate TypeScript rules.
This value is inherited by sub-directories and applied relative to each BUILD.
The `ts_project(tsconfig)` attribute is *NOT* set and must be done manually if necessary | +| `# gazelle:js_tsconfig enabled\|disabled` | `enabled` | +| Enable generation of `ts_config` rules.
This value is inherited by sub-directories and applied relative to each BUILD.
The `ts_project(tsconfig)` attribute is *NOT* set and must be done manually if necessary | | `# gazelle:js_custom_files _name_ _glob_` | | Generate additional custom `ts_project` targets | | `# gazelle:js_custom_test_files _name_ _glob_` | | Generate additional custom `ts_project` testonly targets | diff --git a/gazelle/common/BUILD.bazel b/gazelle/common/BUILD.bazel index df7fc5e31..1e51348a0 100644 --- a/gazelle/common/BUILD.bazel +++ b/gazelle/common/BUILD.bazel @@ -14,6 +14,7 @@ go_library( deps = [ "//gazelle/common/git", "//pkg/logger", + "@bazel_gazelle//config:go_default_library", "@bazel_gazelle//label:go_default_library", "@bazel_gazelle//language:go_default_library", "@bazel_gazelle//rule:go_default_library", diff --git a/gazelle/common/bazel.go b/gazelle/common/bazel.go index c1ae0931c..f2ab85035 100644 --- a/gazelle/common/bazel.go +++ b/gazelle/common/bazel.go @@ -3,12 +3,11 @@ package gazelle import ( "os" "path" + + "github.com/bazelbuild/bazel-gazelle/config" ) var ( - // BUILD file names. - buildFileNames = []string{"BUILD", "BUILD.bazel"} - // A set of already-seen Bazel packages so we avoid doing // disk IO over and over to determine if a directory is a Bazel package. isPackageCache = make(map[string]bool) @@ -16,7 +15,11 @@ var ( // IsBazelPackage determines if the directory is a Bazel package by probing for // the existence of a known BUILD file name. -func IsBazelPackage(dir string) bool { +func IsBazelPackage(config *config.Config, dir string) bool { + return HasBUILDFile(config.ValidBuildFileNames, dir) +} + +func HasBUILDFile(buildFileNames []string, dir string) bool { if isPkg, cached := isPackageCache[dir]; cached { return isPkg } @@ -31,12 +34,3 @@ func IsBazelPackage(dir string) bool { isPackageCache[dir] = false return false } - -func isBuildFile(filename string) bool { - for _, buildFilename := range buildFileNames { - if filename == buildFilename { - return true - } - } - return false -} diff --git a/gazelle/common/excludes.go b/gazelle/common/excludes.go index e86535098..833d96763 100644 --- a/gazelle/common/excludes.go +++ b/gazelle/common/excludes.go @@ -9,7 +9,7 @@ import ( ) // Required for using go:linkname below for using the private isExcluded. -// https://github.com/bazelbuild/bazel-gazelle/blob/v0.28.0/walk/config.go#L54-L73 +// walkConfig: https://github.com/bazelbuild/bazel-gazelle/blob/v0.37.0/walk/config.go#L41-L46 type walkConfig struct { excludes []string // Below are fields that are not used by the isExcluded function but match the walkConfig @@ -19,6 +19,8 @@ type walkConfig struct { _ sync.Once // loadOnce sync.Once } +// isExcluded: https://github.com/bazelbuild/bazel-gazelle/blob/v0.37.0/walk/config.go#L54-L59 +// //go:linkname isExcluded github.com/bazelbuild/bazel-gazelle/walk.(*walkConfig).isExcluded func isExcluded(wc *walkConfig, rel, base string) bool diff --git a/gazelle/common/git/BUILD.bazel b/gazelle/common/git/BUILD.bazel index f00e684c8..22353371f 100644 --- a/gazelle/common/git/BUILD.bazel +++ b/gazelle/common/git/BUILD.bazel @@ -8,7 +8,7 @@ go_library( deps = [ "//pkg/logger", "@bazel_gazelle//config:go_default_library", - "@com_github_go_git_go_git//plumbing/format/gitignore", + "@com_github_go_git_go_git_v5//plumbing/format/gitignore", ], ) diff --git a/gazelle/common/git/gitignore.go b/gazelle/common/git/gitignore.go index a8355639f..e18cb8a4a 100644 --- a/gazelle/common/git/gitignore.go +++ b/gazelle/common/git/gitignore.go @@ -9,12 +9,9 @@ import ( BazelLog "aspect.build/cli/pkg/logger" "github.com/bazelbuild/bazel-gazelle/config" - gitignore "github.com/go-git/go-git/plumbing/format/gitignore" + gitignore "github.com/go-git/go-git/v5/plumbing/format/gitignore" ) -// Ignore files following .gitignore syntax for files gazelle will ignore. -var bazelIgnoreFiles = []string{".bazelignore", ".gitignore"} - // Wrap the ignore files along with the relative path they were loaded from // to enable quick-exit checks. type ignoreEntry struct { @@ -34,15 +31,12 @@ func NewGitIgnore() *GitIgnore { func (i *GitIgnore) CollectIgnoreFiles(c *config.Config, rel string) { // Collect gitignore style ignore files in this directory. - for _, ignoreFileName := range bazelIgnoreFiles { - ignoreRelPath := path.Join(rel, ignoreFileName) - ignoreFilePath := path.Join(c.RepoRoot, ignoreRelPath) + ignoreFilePath := path.Join(c.RepoRoot, rel, ".gitignore") - if ignoreReader, ignoreErr := os.Open(ignoreFilePath); ignoreErr == nil { - BazelLog.Tracef("Add ignore file %s", ignoreRelPath) + if ignoreReader, ignoreErr := os.Open(ignoreFilePath); ignoreErr == nil { + BazelLog.Tracef("Add ignore file %s/.gitignore", rel) - i.addIgnore(rel, ignoreReader) - } + i.addIgnore(rel, ignoreReader) } } diff --git a/gazelle/common/starlark/BUILD.bazel b/gazelle/common/starlark/BUILD.bazel index e6bb2ef03..bfed08e5d 100644 --- a/gazelle/common/starlark/BUILD.bazel +++ b/gazelle/common/starlark/BUILD.bazel @@ -12,6 +12,7 @@ go_library( "//gazelle/common", "//gazelle/common/starlark/stdlib", "//pkg/logger", + "@bazel_gazelle//config:go_default_library", "@com_github_bazelbuild_buildtools//build:go_default_library", "@com_github_yargevad_filepathx//:filepathx", "@net_starlark_go//lib/json", diff --git a/gazelle/common/starlark/eval.go b/gazelle/common/starlark/eval.go index 4b387d79f..f1c6d2ba7 100644 --- a/gazelle/common/starlark/eval.go +++ b/gazelle/common/starlark/eval.go @@ -27,7 +27,7 @@ var thread = &starlark.Thread{ }, } -func Eval(starpath string, libs map[string]starlark.Value, locals map[string]interface{}) (starlark.StringDict, error) { +func Eval(starpath string, libs starlark.StringDict, locals map[string]interface{}) (starlark.StringDict, error) { // Predeclared libs in addition to the go.starlark.net/starlark standard library: // * https://github.com/google/starlark-go/blob/f86470692795f8abcf9f837a3c53cf031c5a3d7e/starlark/library.go#L36-L73 // * https://github.com/google/starlark-go/blob/f86470692795f8abcf9f837a3c53cf031c5a3d7e/cmd/starlark/starlark.go#L96-L100 diff --git a/gazelle/common/starlark/glob.go b/gazelle/common/starlark/glob.go index 1d3ce6d54..77fad1d71 100644 --- a/gazelle/common/starlark/glob.go +++ b/gazelle/common/starlark/glob.go @@ -24,6 +24,7 @@ import ( common "aspect.build/cli/gazelle/common" BazelLog "aspect.build/cli/pkg/logger" + "github.com/bazelbuild/bazel-gazelle/config" bzl "github.com/bazelbuild/buildtools/build" ) @@ -231,7 +232,7 @@ func (pt *BazelPackageTree) AddPath(parts []string) { if !isFile { dir := path.Join(parts[:i+1]...) dir = path.Join(*pt.pkg, dir) - isBazelPkg = common.IsBazelPackage(dir) + isBazelPkg = common.HasBUILDFile(config.DefaultValidBuildFileNames, dir) } branch = &BazelPackageTree{ pkg: pt.pkg, diff --git a/gazelle/common/starlark/utils/util.go b/gazelle/common/starlark/utils/util.go index e682b2a64..bfd0e1adc 100644 --- a/gazelle/common/starlark/utils/util.go +++ b/gazelle/common/starlark/utils/util.go @@ -121,8 +121,15 @@ func ReadStringTuple(l starlark.Tuple) []string { } func ForEachMapEntry(v starlark.Value, f func(k string, v starlark.Value)) { - for _, item := range v.(*starlark.Dict).Items() { - f(ReadString(item[0]), item[1]) + d := v.(*starlark.Dict) + + iter := d.Iterate() + defer iter.Done() + + var k starlark.Value + for iter.Next(&k) { + v, _, _ := d.Get(k) + f(ReadString(k), v) } } @@ -155,9 +162,14 @@ func ReadMap[K any](v starlark.Value, f func(k string, v starlark.Value) K) map[ d := v.(*starlark.Dict) m := make(map[string]K) - for _, item := range d.Items() { - k := ReadString(item[0]) - m[k] = f(k, item[1]) + iter := d.Iterate() + defer iter.Done() + + var kv starlark.Value + for iter.Next(&kv) { + k := ReadString(kv) + v, _, _ := d.Get(kv) + m[k] = f(k, v) } return m @@ -167,8 +179,14 @@ func ReadMap2[K any](v starlark.Value, f func(v starlark.Value) K) map[string]K d := v.(*starlark.Dict) m := make(map[string]K) - for _, item := range d.Items() { - m[ReadString(item[0])] = f(item[1]) + iter := d.Iterate() + defer iter.Done() + + var kv starlark.Value + for iter.Next(&kv) { + k := ReadString(kv) + v, _, _ := d.Get(kv) + m[k] = f(v) } return m diff --git a/gazelle/common/walk.go b/gazelle/common/walk.go index 200fcac37..497ffe03c 100644 --- a/gazelle/common/walk.go +++ b/gazelle/common/walk.go @@ -20,7 +20,7 @@ func GazelleWalkDir(args language.GenerateArgs, ignore *git.GitIgnore, excludes // Source files in the primary directory for _, f := range args.RegularFiles { // Skip BUILD files - if isBuildFile(f) { + if args.Config.IsValidBuildFileName(f) { continue } @@ -52,7 +52,7 @@ func GazelleWalkDir(args language.GenerateArgs, ignore *git.GitIgnore, excludes } // Skip BUILD files - if isBuildFile(filePath) { + if args.Config.IsValidBuildFileName(path.Base(filePath)) { return nil } @@ -76,7 +76,7 @@ func GazelleWalkDir(args language.GenerateArgs, ignore *git.GitIgnore, excludes // If visiting a directory recurse if it is not a bazel package. if info.IsDir() { - if IsBazelPackage(filePath) { + if IsBazelPackage(args.Config, filePath) { return filepath.SkipDir } return nil diff --git a/gazelle/js/generate.go b/gazelle/js/generate.go index a0056719b..799a186e1 100644 --- a/gazelle/js/generate.go +++ b/gazelle/js/generate.go @@ -58,7 +58,7 @@ func (ts *typeScriptLang) GenerateRules(args language.GenerateArgs) language.Gen // If this directory has not been declared as a bazel package only continue // if generating new BUILD files is enabled. - if cfg.GenerationMode() == GenerationModeNone && !gazelle.IsBazelPackage(args.Dir) { + if cfg.GenerationMode() == GenerationModeNone && !gazelle.IsBazelPackage(args.Config, args.Dir) { BazelLog.Tracef("GenerateRules '%s' BUILD creation disabled", args.Rel) return language.GenerateResult{} } diff --git a/gazelle/js/tests/ignore_config_files/.test-bazelignore b/gazelle/js/tests/ignore_config_files/.test-bazelignore new file mode 100644 index 000000000..5fe4dbbf9 --- /dev/null +++ b/gazelle/js/tests/ignore_config_files/.test-bazelignore @@ -0,0 +1 @@ +subtarget/s1.ts diff --git a/gazelle/js/tests/ignore_config_files/subtarget/.test-bazelignore b/gazelle/js/tests/ignore_config_files/subtarget/.test-bazelignore deleted file mode 100644 index dc7d1d812..000000000 --- a/gazelle/js/tests/ignore_config_files/subtarget/.test-bazelignore +++ /dev/null @@ -1 +0,0 @@ -s1.ts \ No newline at end of file diff --git a/gazelle/js/tests/parse_errors/BUILD.in b/gazelle/js/tests/parse_errors/BUILD.in index 19a48e4e9..bd0090593 100644 --- a/gazelle/js/tests/parse_errors/BUILD.in +++ b/gazelle/js/tests/parse_errors/BUILD.in @@ -1,2 +1,2 @@ # gazelle:js_ignore_imports mystery-module -# gazelle:js_ignore_imports unknown-library +# aspect:js_ignore_imports unknown-library diff --git a/gazelle/js/tests/parse_errors/BUILD.out b/gazelle/js/tests/parse_errors/BUILD.out index 2c04bbf43..67c8e710f 100644 --- a/gazelle/js/tests/parse_errors/BUILD.out +++ b/gazelle/js/tests/parse_errors/BUILD.out @@ -1,7 +1,7 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project") # gazelle:js_ignore_imports mystery-module -# gazelle:js_ignore_imports unknown-library +# aspect:js_ignore_imports unknown-library ts_project( name = "parse_errors", diff --git a/gazelle/js/tests/pnpm_workspace/lib/no-direct/package.json b/gazelle/js/tests/pnpm_workspace/lib/no-direct/package.json index 7dae88ccc..38dc9d363 100644 --- a/gazelle/js/tests/pnpm_workspace/lib/no-direct/package.json +++ b/gazelle/js/tests/pnpm_workspace/lib/no-direct/package.json @@ -3,6 +3,6 @@ "private": true, "dependencies": { "@lib/b": "workspace:*", - "typescript": "4.9.5" + "typescript": "5.4.5" } } diff --git a/gazelle/js/tests/pnpm_workspace/package.json b/gazelle/js/tests/pnpm_workspace/package.json index 7aaa64e45..1518bf4be 100644 --- a/gazelle/js/tests/pnpm_workspace/package.json +++ b/gazelle/js/tests/pnpm_workspace/package.json @@ -1,7 +1,7 @@ { "private": true, "dependencies": { - "typescript": "4.9.5", + "typescript": "5.4.5", "@aspect-test/a": "5.0.2" }, "devDependencies": { diff --git a/gazelle/js/tests/pnpm_workspace_rerooted/lib/no-direct/package.json b/gazelle/js/tests/pnpm_workspace_rerooted/lib/no-direct/package.json index 7dae88ccc..38dc9d363 100644 --- a/gazelle/js/tests/pnpm_workspace_rerooted/lib/no-direct/package.json +++ b/gazelle/js/tests/pnpm_workspace_rerooted/lib/no-direct/package.json @@ -3,6 +3,6 @@ "private": true, "dependencies": { "@lib/b": "workspace:*", - "typescript": "4.9.5" + "typescript": "5.4.5" } } diff --git a/gazelle/js/tests/pnpm_workspace_rerooted/package.json b/gazelle/js/tests/pnpm_workspace_rerooted/package.json index 7aaa64e45..1518bf4be 100644 --- a/gazelle/js/tests/pnpm_workspace_rerooted/package.json +++ b/gazelle/js/tests/pnpm_workspace_rerooted/package.json @@ -1,7 +1,7 @@ { "private": true, "dependencies": { - "typescript": "4.9.5", + "typescript": "5.4.5", "@aspect-test/a": "5.0.2" }, "devDependencies": { diff --git a/gazelle/js/tests/resolve_directive/BUILD.in b/gazelle/js/tests/resolve_directive/BUILD.in index 5a6bd3e05..e8d7b5a40 100644 --- a/gazelle/js/tests/resolve_directive/BUILD.in +++ b/gazelle/js/tests/resolve_directive/BUILD.in @@ -1,8 +1,8 @@ # gazelle:js_resolve sassy.* :sass_lib -# gazelle:js_resolve **/*.scss //deep:deep_scss_lib +# aspect:js_resolve **/*.scss //deep:deep_scss_lib # gazelle:js_resolve my_prefix/** //resolved:target # gazelle:resolve js resolved1 //direct:resolve1 -# gazelle:resolve js resolved/sub/dir2 //direct:resolve2 +# aspect:resolve js resolved/sub/dir2 //direct:resolve2 # gazelle:resolve js js resolved3 //direct:resolve3 filegroup( @@ -10,4 +10,4 @@ filegroup( ) filegroup( name = "deep_scss_lib" -) \ No newline at end of file +) diff --git a/gazelle/js/tests/resolve_directive/BUILD.out b/gazelle/js/tests/resolve_directive/BUILD.out index 145ec4237..fe31ea5d3 100644 --- a/gazelle/js/tests/resolve_directive/BUILD.out +++ b/gazelle/js/tests/resolve_directive/BUILD.out @@ -1,10 +1,10 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project") # gazelle:js_resolve sassy.* :sass_lib -# gazelle:js_resolve **/*.scss //deep:deep_scss_lib +# aspect:js_resolve **/*.scss //deep:deep_scss_lib # gazelle:js_resolve my_prefix/** //resolved:target # gazelle:resolve js resolved1 //direct:resolve1 -# gazelle:resolve js resolved/sub/dir2 //direct:resolve2 +# aspect:resolve js resolved/sub/dir2 //direct:resolve2 # gazelle:resolve js js resolved3 //direct:resolve3 filegroup( diff --git a/gazelle/js/tests/resolve_order/base/BUILD.in b/gazelle/js/tests/resolve_order/base/BUILD.in index cad3b74bc..01e7b48f6 100644 --- a/gazelle/js/tests/resolve_order/base/BUILD.in +++ b/gazelle/js/tests/resolve_order/base/BUILD.in @@ -13,7 +13,7 @@ # gazelle:resolve js js the-import :directive-resolve # 2: 'js_resolve' directive -# gazelle:js_resolve the-import :directive-js-resolve +# aspect:js_resolve the-import :directive-js-resolve # 3: genrule outputs genrule( @@ -23,4 +23,4 @@ genrule( ) # 4: package name (listed in pnpm-lock.yaml) -npm_link_all_packages(name = "node_modules") \ No newline at end of file +npm_link_all_packages(name = "node_modules") diff --git a/gazelle/js/tests/resolve_order/base/BUILD.out b/gazelle/js/tests/resolve_order/base/BUILD.out index 42ed43c2c..b39cd4211 100644 --- a/gazelle/js/tests/resolve_order/base/BUILD.out +++ b/gazelle/js/tests/resolve_order/base/BUILD.out @@ -13,7 +13,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages") # gazelle:resolve js js the-import :directive-resolve # 2: 'js_resolve' directive -# gazelle:js_resolve the-import :directive-js-resolve +# aspect:js_resolve the-import :directive-js-resolve # 3: genrule outputs genrule( diff --git a/gazelle/js/tests/resolve_order/node-overridden/BUILD.in b/gazelle/js/tests/resolve_order/node-overridden/BUILD.in index 8ce97a933..b9338c826 100644 --- a/gazelle/js/tests/resolve_order/node-overridden/BUILD.in +++ b/gazelle/js/tests/resolve_order/node-overridden/BUILD.in @@ -2,7 +2,7 @@ # ----------------------------------------------------------------------- # 1: 'resolve' directive -# gazelle:resolve js js fs :directive-resolve +# aspect:resolve js js fs :directive-resolve # 4: package name (listed in pnpm-lock.yaml) -npm_link_all_packages(name = "node_modules") \ No newline at end of file +npm_link_all_packages(name = "node_modules") diff --git a/gazelle/js/tests/resolve_order/node-overridden/BUILD.out b/gazelle/js/tests/resolve_order/node-overridden/BUILD.out index d7ccd5d78..f70622f78 100644 --- a/gazelle/js/tests/resolve_order/node-overridden/BUILD.out +++ b/gazelle/js/tests/resolve_order/node-overridden/BUILD.out @@ -5,7 +5,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages") # ----------------------------------------------------------------------- # 1: 'resolve' directive -# gazelle:resolve js js fs :directive-resolve +# aspect:resolve js js fs :directive-resolve # 4: package name (listed in pnpm-lock.yaml) npm_link_all_packages(name = "node_modules") diff --git a/gazelle/js/tests/resolve_order/resolve/BUILD.in b/gazelle/js/tests/resolve_order/resolve/BUILD.in index 3356da988..096368364 100644 --- a/gazelle/js/tests/resolve_order/resolve/BUILD.in +++ b/gazelle/js/tests/resolve_order/resolve/BUILD.in @@ -5,7 +5,7 @@ # gazelle:resolve js js the-import :directive-resolve # 2: 'js_resolve' directive -# gazelle:js_resolve the-import :directive-js-resolve +# aspect:js_resolve the-import :directive-js-resolve # 3: genrule outputs genrule( @@ -15,4 +15,4 @@ genrule( ) # 4: package name (listed in pnpm-lock.yaml) -npm_link_all_packages(name = "node_modules") \ No newline at end of file +npm_link_all_packages(name = "node_modules") diff --git a/gazelle/js/tests/resolve_order/resolve/BUILD.out b/gazelle/js/tests/resolve_order/resolve/BUILD.out index d846c8a8a..77fc83922 100644 --- a/gazelle/js/tests/resolve_order/resolve/BUILD.out +++ b/gazelle/js/tests/resolve_order/resolve/BUILD.out @@ -8,7 +8,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages") # gazelle:resolve js js the-import :directive-resolve # 2: 'js_resolve' directive -# gazelle:js_resolve the-import :directive-js-resolve +# aspect:js_resolve the-import :directive-js-resolve # 3: genrule outputs genrule( diff --git a/gazelle/js/tests/simple_dts_only/BUILD.in b/gazelle/js/tests/simple_dts_only/BUILD.in index bc99953fe..c224c6647 100644 --- a/gazelle/js/tests/simple_dts_only/BUILD.in +++ b/gazelle/js/tests/simple_dts_only/BUILD.in @@ -1 +1 @@ -# gazelle:js_files **/*.{js,ts} \ No newline at end of file +# aspect:js_files **/*.{js,ts} diff --git a/gazelle/js/tests/simple_dts_only/BUILD.out b/gazelle/js/tests/simple_dts_only/BUILD.out index 7d8e5ad1c..c8d7cc529 100644 --- a/gazelle/js/tests/simple_dts_only/BUILD.out +++ b/gazelle/js/tests/simple_dts_only/BUILD.out @@ -1,6 +1,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_library") -# gazelle:js_files **/*.{js,ts} +# aspect:js_files **/*.{js,ts} js_library( name = "simple_dts_only", diff --git a/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.in b/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.in index f671c96cc..4164b2c65 100644 --- a/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.in +++ b/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.in @@ -1 +1 @@ -# gazelle:js_files **/*.{ts,js} \ No newline at end of file +# aspect:js_files **/*.{ts,js} diff --git a/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.out b/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.out index 5ea485fa8..0bc9fcd23 100644 --- a/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.out +++ b/gazelle/js/tests/simple_dts_only_dep/dts-js/BUILD.out @@ -1,6 +1,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_library") -# gazelle:js_files **/*.{ts,js} +# aspect:js_files **/*.{ts,js} js_library( name = "dts-js", diff --git a/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.in b/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.in index f671c96cc..4164b2c65 100644 --- a/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.in +++ b/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.in @@ -1 +1 @@ -# gazelle:js_files **/*.{ts,js} \ No newline at end of file +# aspect:js_files **/*.{ts,js} diff --git a/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.out b/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.out index 4aae628c7..3c013a99f 100644 --- a/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.out +++ b/gazelle/js/tests/simple_dts_only_dep/dts-ts-js/BUILD.out @@ -1,6 +1,6 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project") -# gazelle:js_files **/*.{ts,js} +# aspect:js_files **/*.{ts,js} ts_project( name = "dts-ts-js", diff --git a/gazelle/js/tests/simple_dts_only_dep/js/BUILD.in b/gazelle/js/tests/simple_dts_only_dep/js/BUILD.in index cdf4ea575..afb56d908 100644 --- a/gazelle/js/tests/simple_dts_only_dep/js/BUILD.in +++ b/gazelle/js/tests/simple_dts_only_dep/js/BUILD.in @@ -1 +1 @@ -# gazelle:js_files *.js \ No newline at end of file +# aspect:js_files *.js diff --git a/gazelle/js/tests/simple_dts_only_dep/js/BUILD.out b/gazelle/js/tests/simple_dts_only_dep/js/BUILD.out index a0bbdf0c1..6ead41df6 100644 --- a/gazelle/js/tests/simple_dts_only_dep/js/BUILD.out +++ b/gazelle/js/tests/simple_dts_only_dep/js/BUILD.out @@ -1,6 +1,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_library") -# gazelle:js_files *.js +# aspect:js_files *.js js_library( name = "js", diff --git a/gazelle/js/tests/simple_empty/mapped_kind/BUILD.in b/gazelle/js/tests/simple_empty/mapped_kind/BUILD.in index 1b96baaeb..1a1419d5c 100644 --- a/gazelle/js/tests/simple_empty/mapped_kind/BUILD.in +++ b/gazelle/js/tests/simple_empty/mapped_kind/BUILD.in @@ -1,4 +1,4 @@ -# gazelle:map_kind ts_project ts_my_project //:defs.bzl +# aspect:map_kind ts_project ts_my_project //:defs.bzl load("//:defs.bzl", "ts_my_project") diff --git a/gazelle/js/tests/simple_empty/mapped_kind/BUILD.out b/gazelle/js/tests/simple_empty/mapped_kind/BUILD.out index 361f64900..c2a9f54d0 100644 --- a/gazelle/js/tests/simple_empty/mapped_kind/BUILD.out +++ b/gazelle/js/tests/simple_empty/mapped_kind/BUILD.out @@ -1,3 +1,3 @@ -# gazelle:map_kind ts_project ts_my_project //:defs.bzl +# aspect:map_kind ts_project ts_my_project //:defs.bzl load("//:defs.bzl", "ts_my_project") diff --git a/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.in b/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.in index b0b48aa92..18d803610 100644 --- a/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.in +++ b/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.in @@ -1,14 +1,14 @@ # Simple -# gazelle:exclude **/*.ig.kt +# aspect:exclude **/*.ig.kt # Should support sub-directories -# gazelle:exclude subdir/ignored.kt +# aspect:exclude subdir/ignored.kt # gazelle:exclude **/sub-ignored.kt # Sub-directories must be relative to BUILD # gazelle:exclude sub-not-ignored.kt # Should not be able to exclude for a different BUILD -# gazelle:exclude sub-ignored.kt +# aspect:exclude sub-ignored.kt # gazelle:exclude subproject/* -# gazelle:exclude subproject-included/* \ No newline at end of file +# gazelle:exclude subproject-included/* diff --git a/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.out b/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.out index 2ade1a6f9..a661c1679 100644 --- a/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.out +++ b/gazelle/kotlin/tests/gazelle_exclude_directive/BUILD.out @@ -1,17 +1,17 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") # Simple -# gazelle:exclude **/*.ig.kt +# aspect:exclude **/*.ig.kt # Should support sub-directories -# gazelle:exclude subdir/ignored.kt +# aspect:exclude subdir/ignored.kt # gazelle:exclude **/sub-ignored.kt # Sub-directories must be relative to BUILD # gazelle:exclude sub-not-ignored.kt # Should not be able to exclude for a different BUILD -# gazelle:exclude sub-ignored.kt +# aspect:exclude sub-ignored.kt # gazelle:exclude subproject/* # gazelle:exclude subproject-included/* diff --git a/gazelle/kotlin/tests/ignore_config_files/.test-bazelignore b/gazelle/kotlin/tests/ignore_config_files/.test-bazelignore new file mode 100644 index 000000000..f4801afc5 --- /dev/null +++ b/gazelle/kotlin/tests/ignore_config_files/.test-bazelignore @@ -0,0 +1 @@ +sub1/s1.kt diff --git a/gazelle/kotlin/tests/ignore_config_files/sub1/.test-bazelignore b/gazelle/kotlin/tests/ignore_config_files/sub1/.test-bazelignore deleted file mode 100644 index f7cef6ed3..000000000 --- a/gazelle/kotlin/tests/ignore_config_files/sub1/.test-bazelignore +++ /dev/null @@ -1 +0,0 @@ -s1.kt \ No newline at end of file diff --git a/go.bzl b/go.bzl index e60b3cc87..0a9e44655 100644 --- a/go.bzl +++ b/go.bzl @@ -25,13 +25,6 @@ def deps(): sum = "h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=", version = "v0.0.0-20180116102854-5a71ef0e047d", ) - go_repository( - name = "com_github_alcortesm_tgz", - build_file_proto_mode = "disable_global", - importpath = "github.com/alcortesm/tgz", - sum = "h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=", - version = "v0.0.0-20161220082320-9c5fe88206d7", - ) go_repository( name = "com_github_alecthomas_assert_v2", build_file_proto_mode = "disable_global", @@ -152,6 +145,15 @@ def deps(): sum = "h1:CTefzjN/D3Cdn3rkrM6qMWuQj59OBcuOjyIp3m4hZ7s=", version = "v0.46.0", ) + go_repository( + name = "com_github_bazelbuild_rules_python_gazelle", + # Overwrite BUILD files in rules_python which reference Bazel symbols + build_file_generation = "on", + build_file_proto_mode = "disable_global", + importpath = "github.com/bazelbuild/rules_python/gazelle", + sum = "h1:a473CcQ65A1Dl3RMD2ULOqm5ShBnz853g8OAWl2MuCA=", + version = "v0.0.0-20240610103109-49cdf7d3fe00", + ) go_repository( name = "com_github_bgentry_go_netrc", build_file_proto_mode = "disable_global", @@ -355,13 +357,6 @@ def deps(): sum = "h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=", version = "v2.0.4", ) - go_repository( - name = "com_github_creack_pty", - build_file_proto_mode = "disable_global", - importpath = "github.com/creack/pty", - sum = "h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=", - version = "v1.1.7", - ) go_repository( name = "com_github_cyphar_filepath_securejoin", build_file_proto_mode = "disable_global", @@ -425,13 +420,6 @@ def deps(): sum = "h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=", version = "v1.16.0", ) - go_repository( - name = "com_github_flynn_go_shlex", - build_file_proto_mode = "disable_global", - importpath = "github.com/flynn/go-shlex", - sum = "h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=", - version = "v0.0.0-20150515145356-3f9db97f8568", - ) go_repository( name = "com_github_frankban_quicktest", build_file_proto_mode = "disable_global", @@ -446,6 +434,13 @@ def deps(): sum = "h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=", version = "v1.7.0", ) + go_repository( + name = "com_github_ghodss_yaml", + build_file_proto_mode = "disable_global", + importpath = "github.com/ghodss/yaml", + sum = "h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=", + version = "v1.0.0", + ) go_repository( name = "com_github_gliderlabs_ssh", build_file_proto_mode = "disable_global", @@ -467,13 +462,6 @@ def deps(): sum = "h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=", version = "v5.5.0", ) - go_repository( - name = "com_github_go_git_go_git", - build_file_proto_mode = "disable_global", - importpath = "github.com/go-git/go-git", - sum = "h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA=", - version = "v4.7.0+incompatible", - ) go_repository( name = "com_github_go_git_go_git_fixtures_v4", build_file_proto_mode = "disable_global", @@ -768,13 +756,6 @@ def deps(): sum = "h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=", version = "v0.0.0-20150711004518-d14ea06fba99", ) - go_repository( - name = "com_github_jessevdk_go_flags", - build_file_proto_mode = "disable_global", - importpath = "github.com/jessevdk/go-flags", - sum = "h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=", - version = "v1.4.0", - ) go_repository( name = "com_github_jhump_protoreflect", build_file_proto_mode = "disable_global", @@ -828,8 +809,8 @@ def deps(): name = "com_github_kr_pty", build_file_proto_mode = "disable_global", importpath = "github.com/kr/pty", - sum = "h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=", - version = "v1.1.8", + sum = "h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=", + version = "v1.1.1", ) go_repository( name = "com_github_kr_text", @@ -1034,13 +1015,6 @@ def deps(): sum = "h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=", version = "v1.31.1", ) - go_repository( - name = "com_github_pelletier_go_buffruneio", - build_file_proto_mode = "disable_global", - importpath = "github.com/pelletier/go-buffruneio", - sum = "h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA=", - version = "v0.2.0", - ) go_repository( name = "com_github_pelletier_go_toml_v2", build_file_proto_mode = "disable_global", @@ -1206,6 +1180,7 @@ def deps(): name = "com_github_smacker_go_tree_sitter", build_file_proto_mode = "disable_global", importpath = "github.com/smacker/go-tree-sitter", + patches = ["//patches:com_github_smacker_go_tree_sitter.patch"], # keep sum = "h1:nOtrYzQNgRipVsrOkYpVU/ZMDS3/+78It68cPBPKy8A=", version = "v0.0.0-20240514083259-c5d1f3f5f99e", ) @@ -1258,13 +1233,6 @@ def deps(): sum = "h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc=", version = "v1.16.0", ) - go_repository( - name = "com_github_src_d_gcfg", - build_file_proto_mode = "disable_global", - importpath = "github.com/src-d/gcfg", - sum = "h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=", - version = "v1.4.0", - ) go_repository( name = "com_github_stretchr_objx", build_file_proto_mode = "disable_global", @@ -2196,27 +2164,6 @@ def deps(): sum = "h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=", version = "v1.67.0", ) - go_repository( - name = "in_gopkg_src_d_go_billy_v4", - build_file_proto_mode = "disable_global", - importpath = "gopkg.in/src-d/go-billy.v4", - sum = "h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=", - version = "v4.3.2", - ) - go_repository( - name = "in_gopkg_src_d_go_git_fixtures_v3", - build_file_proto_mode = "disable_global", - importpath = "gopkg.in/src-d/go-git-fixtures.v3", - sum = "h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg=", - version = "v3.5.0", - ) - go_repository( - name = "in_gopkg_src_d_go_git_v4", - build_file_proto_mode = "disable_global", - importpath = "gopkg.in/src-d/go-git.v4", - sum = "h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=", - version = "v4.13.1", - ) go_repository( name = "in_gopkg_warnings_v0", build_file_proto_mode = "disable_global", diff --git a/go.mod b/go.mod index 86d07d7c7..6bf57b47d 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/bmatcuk/doublestar/v4 v4.6.1 github.com/emirpasic/gods v1.18.1 github.com/fatih/color v1.16.0 - github.com/go-git/go-git v4.7.0+incompatible github.com/golang/mock v1.7.0-rc.1 github.com/golang/protobuf v1.5.3 github.com/hashicorp/go-hclog v1.6.2 @@ -47,7 +46,9 @@ require ( ) require ( + github.com/bazelbuild/rules_python/gazelle v0.0.0-20240610103109-49cdf7d3fe00 github.com/charmbracelet/huh v0.3.0 + github.com/go-git/go-git/v5 v5.12.0 github.com/hay-kot/scaffold v0.0.99 github.com/sourcegraph/go-diff v0.7.0 ) @@ -75,7 +76,6 @@ require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect - github.com/go-git/go-git/v5 v5.12.0 // indirect github.com/go-sprout/sprout v0.3.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/btree v1.1.2 // indirect @@ -116,7 +116,6 @@ require ( github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/src-d/gcfg v1.4.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/urfave/cli/v2 v2.27.2 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect @@ -134,7 +133,6 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect - gopkg.in/src-d/go-git.v4 v4.13.1 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 0d962ab78..1d999ded6 100644 --- a/go.sum +++ b/go.sum @@ -47,7 +47,6 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= -github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/assert/v2 v2.2.1 h1:XivOgYcduV98QCahG8T5XTezV5bylXe+lBxLG2K2ink= github.com/alecthomas/assert/v2 v2.2.1/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= github.com/alecthomas/chroma/v2 v2.8.0 h1:w9WJUjFFmHHB2e8mRpL9jjy3alYDlU0QLDezj1xE264= @@ -56,7 +55,6 @@ github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alphadose/haxmap v1.3.1 h1:KmZh75duO1tC8pt3LmUwoTYiZ9sh4K52FX8p7/yrlqU= github.com/alphadose/haxmap v1.3.1/go.mod h1:rjHw1IAqbxm0S3U5tD16GoKsiAd8FWx5BJ2IYqXwgmM= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= @@ -77,6 +75,8 @@ github.com/bazelbuild/buildtools v0.0.0-20240313121412-66c605173954 h1:VNqmvOfFz github.com/bazelbuild/buildtools v0.0.0-20240313121412-66c605173954/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo= github.com/bazelbuild/rules_go v0.46.0 h1:CTefzjN/D3Cdn3rkrM6qMWuQj59OBcuOjyIp3m4hZ7s= github.com/bazelbuild/rules_go v0.46.0/go.mod h1:Dhcz716Kqg1RHNWos+N6MlXNkjNP2EwZQ0LukRKJfMs= +github.com/bazelbuild/rules_python/gazelle v0.0.0-20240610103109-49cdf7d3fe00 h1:a473CcQ65A1Dl3RMD2ULOqm5ShBnz853g8OAWl2MuCA= +github.com/bazelbuild/rules_python/gazelle v0.0.0-20240610103109-49cdf7d3fe00/go.mod h1:KoDh6+H75gM946IxVKnOjm8C74p3M5L6iJXiwyodpeM= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/bluekeyes/go-gitdiff v0.7.1 h1:graP4ElLRshr8ecu0UtqfNTCHrtSyZd3DABQm/DWesQ= @@ -123,7 +123,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -133,7 +132,6 @@ github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -145,20 +143,18 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= -github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= -github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= @@ -270,12 +266,10 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -284,7 +278,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= @@ -342,14 +335,12 @@ github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= -github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= @@ -372,7 +363,6 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= @@ -396,14 +386,10 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= -github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= -github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -422,7 +408,6 @@ github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg= github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= -github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= @@ -449,11 +434,9 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0= go.starlark.net v0.0.0-20240520160348-046347dcd104 h1:3qhteRISupnJvaWshOmeqEUs2y9oc/+/ePPvDh3Eygg= go.starlark.net v0.0.0-20240520160348-046347dcd104/go.mod h1:YKMCv9b1WrfWmeqdV5MAuEHWsu5iC+fe6kYl2sQjdI8= -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= @@ -570,7 +553,6 @@ golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -660,7 +642,6 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -815,14 +796,10 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= -gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= -gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= -gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= -gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/integration_tests/aspect/flags_test.bats b/integration_tests/aspect/flags_test.bats index 1b26fadfc..56051fcb2 100644 --- a/integration_tests/aspect/flags_test.bats +++ b/integration_tests/aspect/flags_test.bats @@ -46,7 +46,7 @@ BAZELISK_BASE_URL=https://static.aspect.build/aspect USE_BAZEL_VERSION=aspect/1.2.3 EOF - run aspect + run aspect --aspect:lock_version=false assert_failure assert_output --partial "could not download Bazel" @@ -60,7 +60,7 @@ EOF version: 1.2.3 EOF - run aspect --aspect:config="version-config.yaml" + run aspect --aspect:config="version-config.yaml" --aspect:lock_version=false assert_failure assert_output --partial "could not download Bazel" diff --git a/integration_tests/aspect/reenter_test.bats b/integration_tests/aspect/reenter_test.bats index 338ca5120..fa492f7d8 100644 --- a/integration_tests/aspect/reenter_test.bats +++ b/integration_tests/aspect/reenter_test.bats @@ -16,7 +16,7 @@ BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download USE_BAZEL_VERSION=aspect/5.8.19 EOF - run aspect version + run aspect --aspect:lock_version=false version assert_success assert_output --partial "Aspect CLI version: 5.8.19" assert_output --partial "Build label: 6.4.0" @@ -26,7 +26,7 @@ EOF export BAZELISK_BASE_URL="https://github.com/aspect-build/aspect-cli/releases/download" export USE_BAZEL_VERSION="aspect/5.8.20" - run aspect version + run aspect --aspect:lock_version=false version assert_success assert_output --partial "Aspect CLI version: 5.8.20" assert_output --partial "Build label: 6.4.0" @@ -38,9 +38,9 @@ BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download USE_BAZEL_VERSION=aspect/5.8.19 EOF - run aspect --versio + run aspect --aspect:lock_version=false --not_a_flag assert_failure - assert_output --partial "unknown startup flag: --versio" + assert_output --partial "unknown startup flag: --not_a_flag" } @test 'non-one exit code from reentrant aspect cli should be progated to parent' { @@ -49,7 +49,7 @@ BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download USE_BAZEL_VERSION=aspect/5.8.19 EOF - run aspect configure --mode=diff + run aspect --aspect:lock_version=false configure --mode=diff assert_failure 112 assert_output --partial "No languages enabled for BUILD file generation." } diff --git a/patches/bazelbuild_bazel-gazelle_aspect-cli.patch b/patches/bazelbuild_bazel-gazelle_aspect-cli.patch new file mode 100644 index 000000000..c7d352fb0 --- /dev/null +++ b/patches/bazelbuild_bazel-gazelle_aspect-cli.patch @@ -0,0 +1,10 @@ +diff --git a/rule/directives.go b/rule/directives.go +index f5ba580..067838f 100644 +--- a/rule/directives.go ++++ b/rule/directives.go +@@ -72,4 +72,4 @@ func parseDirectives(stmt []bzl.Expr) []Directive { + return directives + } + +-var directiveRe = regexp.MustCompile(`^#\s*gazelle:(\w+)\s*(.*?)\s*$`) ++var directiveRe = regexp.MustCompile(`^#\s*(?:gazelle|aspect):(\w+)\s*(.*?)\s*$`) diff --git a/patches/com_github_smacker_go_tree_sitter.patch b/patches/com_github_smacker_go_tree_sitter.patch new file mode 100644 index 000000000..b569f94db --- /dev/null +++ b/patches/com_github_smacker_go_tree_sitter.patch @@ -0,0 +1,25 @@ +--- BUILD.bazel ++++ BUILD.bazel +@@ -1,5 +1,11 @@ + load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + ++cc_library( ++ name = "headers", ++ hdrs = ["alloc.h", "array.h"], ++ visibility = ["//:__subpackages__"], ++) ++ + go_library( + name = "go-tree-sitter", + srcs = [ + +--- python/BUILD.bazel ++++ python/BUILD.bazel +@@ -9,6 +9,7 @@ + "scanner.c", + ], + cgo = True, ++ cdeps = ["//:headers"], + importpath = "github.com/smacker/go-tree-sitter/python", + visibility = ["//visibility:public"], + deps = ["//:go-tree-sitter"], diff --git a/pkg/aspect/configure/BUILD.bazel b/pkg/aspect/configure/BUILD.bazel index 0764df3cd..5f48d1894 100644 --- a/pkg/aspect/configure/BUILD.bazel +++ b/pkg/aspect/configure/BUILD.bazel @@ -10,6 +10,7 @@ go_library( "gazelle.go", "metaresolver.go", "print.go", + "profiler.go", ], importpath = "aspect.build/cli/pkg/aspect/configure", visibility = ["//visibility:public"], @@ -17,7 +18,6 @@ go_library( "//gazelle/bzl", "//gazelle/js", "//gazelle/kotlin", - "//pkg/aspect/configure/internal/module", "//pkg/aspect/configure/internal/wspace", "//pkg/aspecterrors", "//pkg/ioutils", @@ -32,6 +32,8 @@ go_library( "@bazel_gazelle//resolve:go_default_library", "@bazel_gazelle//rule:go_default_library", "@bazel_gazelle//walk:go_default_library", + "@com_github_bazelbuild_buildtools//build:go_default_library", + "@com_github_bazelbuild_rules_python_gazelle//python", "@com_github_pmezard_go_difflib//difflib", "@com_github_spf13_cobra//:cobra", "@com_github_spf13_viper//:viper", diff --git a/pkg/aspect/configure/configure.go b/pkg/aspect/configure/configure.go index 9264c0cfb..62605ac62 100644 --- a/pkg/aspect/configure/configure.go +++ b/pkg/aspect/configure/configure.go @@ -31,18 +31,26 @@ import ( "github.com/bazelbuild/bazel-gazelle/language" golang "github.com/bazelbuild/bazel-gazelle/language/go" "github.com/bazelbuild/bazel-gazelle/language/proto" + python "github.com/bazelbuild/rules_python/gazelle/python" "github.com/spf13/cobra" "github.com/spf13/viper" ) type Configure struct { ioutils.Streams + + languageKeys []string + languages []language.Language } func New(streams ioutils.Streams) *Configure { - return &Configure{ + c := &Configure{ Streams: streams, } + + c.addDefaultLanguages() + + return c } func pluralize(s string, num int) string { @@ -53,42 +61,46 @@ func pluralize(s string, num int) string { } } -func (runner *Configure) Run(_ context.Context, cmd *cobra.Command, args []string) error { - languages := make([]language.Language, 0, 32) - languageKeys := make([]string, 0, 32) +func (c *Configure) AddLanguage(lang string, l language.Language) { + c.languageKeys = append(c.languageKeys, lang) + c.languages = append(c.languages, l) +} +func (c *Configure) addDefaultLanguages() { // Order matters for gazelle languages. Proto should be run before golang. viper.SetDefault("configure.languages.protobuf", false) if viper.GetBool("configure.languages.protobuf") { - languages = append(languages, proto.NewLanguage()) - languageKeys = append(languageKeys, "protobuf") + c.AddLanguage("protobuf", proto.NewLanguage()) } viper.SetDefault("configure.languages.go", false) if viper.GetBool("configure.languages.go") { - languages = append(languages, golang.NewLanguage()) - languageKeys = append(languageKeys, "go") + c.AddLanguage("go", golang.NewLanguage()) } viper.SetDefault("configure.languages.javascript", false) if viper.GetBool("configure.languages.javascript") { - languages = append(languages, js.NewLanguage()) - languageKeys = append(languageKeys, "javascript") + c.AddLanguage("javascript", js.NewLanguage()) } viper.SetDefault("configure.languages.kotlin", false) if viper.GetBool("configure.languages.kotlin") { - languages = append(languages, kotlin.NewLanguage()) - languageKeys = append(languageKeys, "kotlin") + c.AddLanguage("kotlin", kotlin.NewLanguage()) } viper.SetDefault("configure.languages.bzl", false) if viper.GetBool("configure.languages.bzl") { - languages = append(languages, bzl.NewLanguage()) - languageKeys = append(languageKeys, "bzl") + c.AddLanguage("bzl", bzl.NewLanguage()) + } + + viper.SetDefault("configure.languages.python", false) + if viper.GetBool("configure.languages.python") { + c.AddLanguage("python", python.NewLanguage()) } +} - if len(languageKeys) == 0 { +func (runner *Configure) Run(_ context.Context, cmd *cobra.Command, args []string) error { + if len(runner.languageKeys) == 0 { fmt.Fprintln(runner.Streams.Stderr, `No languages enabled for BUILD file generation. To enable one or more languages, add the following to the .aspect/cli/config.yaml @@ -114,11 +126,25 @@ configure: // Append the aspect-cli mode flag to the args parsed by gazelle. mode, _ := cmd.Flags().GetString("mode") + fixArgs := []string{"--mode=" + mode} + + // gazelle --cpuprofile enabled via environment variable. + cpuprofile := os.Getenv("GAZELLE_CPUPROFILE") + if cpuprofile != "" { + fixArgs = append(fixArgs, "--cpuprofile="+cpuprofile) + } + + // gazelle --memprofile enabled via environment variable. + memprofile := os.Getenv("GAZELLE_MEMPROFILE") + if memprofile != "" { + fixArgs = append(fixArgs, "--memprofile="+memprofile) + } + if mode == "fix" { - fmt.Fprintf(runner.Streams.Stdout, "Updating BUILD files for %s\n", strings.Join(languageKeys, ", ")) + fmt.Fprintf(runner.Streams.Stdout, "Updating BUILD files for %s\n", strings.Join(runner.languageKeys, ", ")) } - stats, err := runFixUpdate(wd, languages, updateCmd, []string{"--mode=" + mode}) + stats, err := runFixUpdate(wd, runner.languages, updateCmd, fixArgs) exitCode := aspecterrors.OK @@ -133,7 +159,7 @@ configure: exitCode = aspecterrors.UnhandledOrInternalError } - if mode == "fix" { + if mode == "fix" && stats != nil { fmt.Fprintf(runner.Streams.Stdout, "%v BUILD %s visited\n", stats.NumBuildFilesVisited, pluralize("file", stats.NumBuildFilesVisited)) fmt.Fprintf(runner.Streams.Stdout, "%v BUILD %s updated\n", stats.NumBuildFilesUpdated, pluralize("file", stats.NumBuildFilesUpdated)) } diff --git a/pkg/aspect/configure/diff.go b/pkg/aspect/configure/diff.go index 876074933..f89e1935d 100644 --- a/pkg/aspect/configure/diff.go +++ b/pkg/aspect/configure/diff.go @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE: synced from bazel-gazelle/cmd/gazelle/diff.go + package configure import ( diff --git a/pkg/aspect/configure/fix-update.go b/pkg/aspect/configure/fix-update.go index 7c3e3b173..70e9b6664 100644 --- a/pkg/aspect/configure/fix-update.go +++ b/pkg/aspect/configure/fix-update.go @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE: synced from bazel-gazelle/cmd/gazelle/fix-update.go + package configure import ( @@ -21,7 +23,6 @@ import ( "errors" "flag" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -29,7 +30,8 @@ import ( "strings" "syscall" - module "aspect.build/cli/pkg/aspect/configure/internal/module" + "github.com/bazelbuild/buildtools/build" + wspace "aspect.build/cli/pkg/aspect/configure/internal/wspace" "github.com/bazelbuild/bazel-gazelle/config" gzflag "github.com/bazelbuild/bazel-gazelle/flag" @@ -54,6 +56,7 @@ type updateConfig struct { patchPath string patchBuffer bytes.Buffer print0 bool + profile profiler } // NOTE: addition aspect-cli "changed" result @@ -78,6 +81,8 @@ type updateConfigurer struct { recursive bool knownImports []string repoConfigPath string + cpuProfile string + memProfile string } func (ucr *updateConfigurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) { @@ -90,6 +95,8 @@ func (ucr *updateConfigurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *conf fs.BoolVar(&ucr.recursive, "r", true, "when true, gazelle will update subdirectories recursively") fs.StringVar(&uc.patchPath, "patch", "", "when set with -mode=diff, gazelle will write to a file instead of stdout") fs.BoolVar(&uc.print0, "print0", false, "when set with -mode=fix, gazelle will print the names of rewritten files separated with \\0 (NULL)") + fs.StringVar(&ucr.cpuProfile, "cpuprofile", "", "write cpu profile to `file`") + fs.StringVar(&ucr.memProfile, "memprofile", "", "write memory profile to `file`") fs.Var(&gzflag.MultiFlag{Values: &ucr.knownImports}, "known_import", "import path for which external resolution is skipped (can specify multiple times)") fs.StringVar(&ucr.repoConfigPath, "repo_config", "", "file where Gazelle should load repository configuration. Defaults to WORKSPACE.") } @@ -108,6 +115,11 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro if uc.patchPath != "" && !filepath.IsAbs(uc.patchPath) { uc.patchPath = filepath.Join(c.WorkDir, uc.patchPath) } + p, err := newProfiler(ucr.cpuProfile, ucr.memProfile) + if err != nil { + return err + } + uc.profile = p dirs := fs.Args() if len(dirs) == 0 { @@ -119,7 +131,7 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro if !filepath.IsAbs(dir) { dir = filepath.Join(c.WorkDir, dir) } - dir, err := filepath.EvalSymlinks(dir) + dir, err = filepath.EvalSymlinks(dir) if err != nil { return fmt.Errorf("%s: failed to resolve symlinks: %v", arg, err) } @@ -162,15 +174,10 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro }) } - moduleToApparentName, err := module.ExtractModuleToApparentNameMapping(c.RepoRoot) - if err != nil { - return err - } - for _, r := range c.Repos { if r.Kind() == "go_repository" { var name string - if apparentName := moduleToApparentName(r.AttrString("module_name")); apparentName != "" { + if apparentName := c.ModuleToApparentName(r.AttrString("module_name")); apparentName != "" { name = apparentName } else { name = r.Name() @@ -219,7 +226,7 @@ func (ucr *updateConfigurer) KnownDirectives() []string { return nil } func (ucr *updateConfigurer) Configure(c *config.Config, rel string, f *rule.File) {} -// visitRecord stores information about about a directory visited with +// visitRecord stores information about a directory visited with // packages.Walk. type visitRecord struct { // pkgRel is the slash-separated path to the visited directory, relative to @@ -278,11 +285,6 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] return nil, err } - moduleToApparentName, err := module.ExtractModuleToApparentNameMapping(c.RepoRoot) - if err != nil { - return nil, err - } - mrslv := newMetaResolver() kinds := make(map[string]rule.KindInfo) loads := genericLoads @@ -293,7 +295,7 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] kinds[kind] = info } if moduleAwareLang, ok := lang.(language.ModuleAwareLanguage); ok { - loads = append(loads, moduleAwareLang.ApparentLoads(moduleToApparentName)...) + loads = append(loads, moduleAwareLang.ApparentLoads(c.ModuleToApparentName)...) } else { loads = append(loads, lang.Loads()...) } @@ -316,12 +318,21 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] // Visit all directories in the repository. var visits []visitRecord uc := getUpdateConfig(c) + defer func() { + if err := uc.profile.stop(); err != nil { + log.Printf("stopping profiler: %v", err) + } + }() + var errorsFromWalk []error walk.Walk(c, cexts, uc.dirs, uc.walkMode, func(dir, rel string, c *config.Config, update bool, f *rule.File, subdirs, regularFiles, genFiles []string) { // If this file is ignored or if Gazelle was not asked to update this // directory, just index the build file and move on. if !update { if c.IndexLibraries && f != nil { + for _, repl := range c.KindMap { + mrslv.MappedKind(rel, repl) + } for _, r := range f.Rules { ruleIndex.AddRule(c, r, f) } @@ -373,17 +384,48 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] if f != nil { allRules = append(allRules, f.Rules...) } - for _, r := range allRules { - repl, err := lookupMapKindReplacement(c.KindMap, r.Kind()) + + maybeRecordReplacement := func(ruleKind string) (*string, error) { + var repl *config.MappedKind + repl, err = lookupMapKindReplacement(c.KindMap, ruleKind) if err != nil { - errorsFromWalk = append(errorsFromWalk, fmt.Errorf("looking up mapped kind: %w", err)) - continue + return nil, err } if repl != nil { - mappedKindInfo[repl.KindName] = kinds[r.Kind()] + mappedKindInfo[repl.KindName] = kinds[ruleKind] mappedKinds = append(mappedKinds, *repl) mrslv.MappedKind(rel, *repl) - r.SetKind(repl.KindName) + return &repl.KindName, nil + } + return nil, nil + } + + for _, r := range allRules { + if replacementName, err := maybeRecordReplacement(r.Kind()); err != nil { + errorsFromWalk = append(errorsFromWalk, fmt.Errorf("looking up mapped kind: %w", err)) + } else if replacementName != nil { + r.SetKind(*replacementName) + } + + for i, arg := range r.Args() { + // Only check the first arg - this supports the maybe(java_library, ...) pattern, + // but avoids potential false positives from other uses of symbols. + if i != 0 { + break + } + if ident, ok := arg.(*build.Ident); ok { + // Don't allow re-mapping symbols that aren't known loads of a plugin. + if _, knownKind := kinds[ident.Name]; !knownKind { + continue + } + if replacementName, err := maybeRecordReplacement(ident.Name); err != nil { + errorsFromWalk = append(errorsFromWalk, fmt.Errorf("looking up mapped kind: %w", err)) + } else if replacementName != nil { + if err := r.UpdateArg(i, &build.Ident{Name: *replacementName}); err != nil { + log.Panicf("%s: %v", rel, err) + } + } + } } } for _, r := range empty { @@ -436,8 +478,8 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] if len(errorsFromWalk) > 1 { var additionalErrors []string - for _, error := range errorsFromWalk[1:] { - additionalErrors = append(additionalErrors, error.Error()) + for _, err = range errorsFromWalk[1:] { + additionalErrors = append(additionalErrors, err.Error()) } return nil, fmt.Errorf("encountered multiple errors: %w, %v", errorsFromWalk[0], strings.Join(additionalErrors, ", ")) @@ -453,6 +495,9 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] err = cerr } }() + if err = maybePopulateRemoteCacheFromGoMod(c, rc); err != nil { + log.Print(err) + } for _, v := range visits { for i, r := range v.rules { from := label.New(c.RepoName, v.pkgRel, r.Name()) @@ -488,7 +533,7 @@ func runFixUpdate(wd string, languages []language.Language, cmd command, args [] } } if uc.patchPath != "" { - if err := ioutil.WriteFile(uc.patchPath, uc.patchBuffer.Bytes(), 0o666); err != nil { + if err := os.WriteFile(uc.patchPath, uc.patchBuffer.Bytes(), 0o666); err != nil { return nil, err } } @@ -531,7 +576,11 @@ func newFixUpdateConfiguration(wd string, cmd command, args []string, cexts []co c := config.New() c.WorkDir = wd + // NOTE: aspect-cli renamed "gazelle" to "default_values" (TODO: why?) fs := flag.NewFlagSet("default_values", flag.ContinueOnError) + // Flag will call this on any parse error. Don't print usage unless + // -h or -help were passed explicitly. + fs.Usage = func() {} for _, cext := range cexts { cext.RegisterFlags(fs, cmd.String(), c) @@ -643,18 +692,53 @@ func findOutputPath(c *config.Config, f *rule.File) string { } outputDir := filepath.Join(baseDir, filepath.FromSlash(f.Pkg)) defaultOutputPath := filepath.Join(outputDir, c.DefaultBuildFileName()) - files, err := ioutil.ReadDir(outputDir) + ents, err := os.ReadDir(outputDir) if err != nil { // Ignore error. Directory probably doesn't exist. return defaultOutputPath } - outputPath := rule.MatchBuildFileName(outputDir, c.ValidBuildFileNames, files) + outputPath := rule.MatchBuildFile(outputDir, c.ValidBuildFileNames, ents) if outputPath == "" { return defaultOutputPath } return outputPath } +// maybePopulateRemoteCacheFromGoMod reads go.mod and adds a root to rc for each +// module requirement. This lets the Go extension avoid a network lookup for +// unknown imports with -external=external, and it lets dependency resolution +// succeed with -external=static when it might not otherwise. +// +// This function does not override roots added from WORKSPACE (or some other +// configuration file), but it's useful when there is no such file. In most +// cases, a user of Gazelle with indirect Go dependencies does not need to add +// '# gazelle:repository' or '# gazelle:repository_macro' directives to their +// WORKSPACE file. This need was frustrating for developers in non-Go +// repositories with go_repository dependencies declared in macros. It wasn't +// obvious that Gazelle was missing these. +// +// This function is regrettably Go specific and does not belong here, but it +// can't be moved to //language/go until //repo is broken up and moved there. +func maybePopulateRemoteCacheFromGoMod(c *config.Config, rc *repo.RemoteCache) error { + haveGo := false + for name := range c.Exts { + if name == "go" { + haveGo = true + break + } + } + if !haveGo { + return nil + } + + goModPath := filepath.Join(c.RepoRoot, "go.mod") + if _, err := os.Stat(goModPath); err != nil { + return nil + } + + return rc.PopulateFromGoMod(goModPath) +} + func unionKindInfoMaps(a, b map[string]rule.KindInfo) map[string]rule.KindInfo { if len(a) == 0 { return b diff --git a/pkg/aspect/configure/fix.go b/pkg/aspect/configure/fix.go index ae599efb3..ee582c358 100644 --- a/pkg/aspect/configure/fix.go +++ b/pkg/aspect/configure/fix.go @@ -13,12 +13,13 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE: synced from bazel-gazelle/cmd/gazelle/fix.go + package configure import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" @@ -35,7 +36,7 @@ func fixFile(c *config.Config, f *rule.File) error { if err := os.MkdirAll(filepath.Dir(outPath), 0o777); err != nil { return err } - if err := ioutil.WriteFile(outPath, newContent, 0o666); err != nil { + if err := os.WriteFile(outPath, newContent, 0o666); err != nil { return err } f.Content = newContent diff --git a/pkg/aspect/configure/gazelle.go b/pkg/aspect/configure/gazelle.go index 5d3c34d40..be7f832fb 100644 --- a/pkg/aspect/configure/gazelle.go +++ b/pkg/aspect/configure/gazelle.go @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE: synced from bazel-gazelle/cmd/gazelle/gazelle.go + // Command gazelle is a BUILD file generator for Go projects. // See "gazelle --help" for more details. package configure @@ -32,18 +34,22 @@ const ( var commandFromName = map[string]command{ "fix": fixCmd, "update": updateCmd, + // NOTE: aspect-cli removed --help, --update-repos } var nameFromCommand = []string{ // keep in sync with definition above "update", "fix", + // NOTE: aspect-cli removed --help, --update-repos } func (cmd command) String() string { return nameFromCommand[cmd] } +// NOTE: aspect-cli removed main() + // filterLanguages returns the subset of input languages that pass the config's // filter, if any. Gazelle should not generate rules for languages not returned. func filterLanguages(c *config.Config, langs []language.Language) []language.Language { diff --git a/pkg/aspect/configure/internal/module/BUILD.bazel b/pkg/aspect/configure/internal/module/BUILD.bazel deleted file mode 100644 index e3213ce36..000000000 --- a/pkg/aspect/configure/internal/module/BUILD.bazel +++ /dev/null @@ -1,9 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "module", - srcs = ["module.go"], - importpath = "aspect.build/cli/pkg/aspect/configure/internal/module", - visibility = ["//pkg/aspect/configure:__subpackages__"], - deps = ["@com_github_bazelbuild_buildtools//build:go_default_library"], -) diff --git a/pkg/aspect/configure/internal/module/module.go b/pkg/aspect/configure/internal/module/module.go deleted file mode 100644 index d1ee7388a..000000000 --- a/pkg/aspect/configure/internal/module/module.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copy of gazelle internal https://github.com/bazelbuild/bazel-gazelle/blob/b62589672b5c32264ddf40585247d684c29bdd15/internal/module/module.go - -// Package module provides functions to read information out of MODULE.bazel files. - -package module - -import ( - "os" - "path/filepath" - - "github.com/bazelbuild/buildtools/build" -) - -// ExtractModuleToApparentNameMapping collects the mapping of module names (e.g. "rules_go") to -// user-configured apparent names (e.g. "my_rules_go") from the repos MODULE.bazel, if it exists. -// See https://bazel.build/external/module#repository_names_and_strict_deps for more information on -// apparent names. -func ExtractModuleToApparentNameMapping(repoRoot string) (func(string) string, error) { - moduleFile, err := parseModuleFile(repoRoot) - if err != nil { - return nil, err - } - var moduleToApparentName map[string]string - if moduleFile != nil { - moduleToApparentName = collectApparentNames(moduleFile) - } else { - // If there is no MODULE.bazel file, return a function that always returns the empty string. - // Languages will know to fall back to the WORKSPACE names of repos. - moduleToApparentName = make(map[string]string) - } - - return func(moduleName string) string { - return moduleToApparentName[moduleName] - }, nil -} - -func parseModuleFile(repoRoot string) (*build.File, error) { - path := filepath.Join(repoRoot, "MODULE.bazel") - bytes, err := os.ReadFile(path) - if os.IsNotExist(err) { - return nil, nil - } else if err != nil { - return nil, err - } - return build.ParseModule(path, bytes) -} - -// Collects the mapping of module names (e.g. "rules_go") to user-configured apparent names (e.g. -// "my_rules_go"). See https://bazel.build/external/module#repository_names_and_strict_deps for more -// information on apparent names. -func collectApparentNames(m *build.File) map[string]string { - apparentNames := make(map[string]string) - - for _, dep := range m.Rules("") { - if dep.Name() == "" { - continue - } - if dep.Kind() != "module" && dep.Kind() != "bazel_dep" { - continue - } - // We support module in addition to bazel_dep to handle language repos that use Gazelle to - // manage their own BUILD files. - if name := dep.AttrString("name"); name != "" { - if repoName := dep.AttrString("repo_name"); repoName != "" { - apparentNames[name] = repoName - } else { - apparentNames[name] = name - } - } - } - - return apparentNames -} diff --git a/pkg/aspect/configure/internal/wspace/finder.go b/pkg/aspect/configure/internal/wspace/finder.go index 7759c928a..1f29f6439 100644 --- a/pkg/aspect/configure/internal/wspace/finder.go +++ b/pkg/aspect/configure/internal/wspace/finder.go @@ -1,4 +1,16 @@ -// Copy of gazelle internal https://github.com/bazelbuild/bazel-gazelle/blob/b62589672b5c32264ddf40585247d684c29bdd15/internal/wspace/finder.go +/* Copyright 2016 The Bazel Authors. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// NOTE: synced from bazel-gazelle/internal/wspace/finder.go // Package wspace provides functions to locate and modify a bazel WORKSPACE file. package wspace diff --git a/pkg/aspect/configure/metaresolver.go b/pkg/aspect/configure/metaresolver.go index b33d56acc..f95e9d784 100644 --- a/pkg/aspect/configure/metaresolver.go +++ b/pkg/aspect/configure/metaresolver.go @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE: synced from bazel-gazelle/cmd/gazelle/metaresolver.go + package configure import ( diff --git a/pkg/aspect/configure/print.go b/pkg/aspect/configure/print.go index cbd8ffc36..12da60cdc 100644 --- a/pkg/aspect/configure/print.go +++ b/pkg/aspect/configure/print.go @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE: synced from bazel-gazelle/cmd/gazelle/print.go + package configure import ( diff --git a/pkg/aspect/configure/profiler.go b/pkg/aspect/configure/profiler.go new file mode 100644 index 000000000..be0d881c9 --- /dev/null +++ b/pkg/aspect/configure/profiler.go @@ -0,0 +1,55 @@ +// NOTE: synced from bazel-gazelle/cmd/gazelle/print.go + +package configure + +import ( + "os" + "runtime" + "runtime/pprof" +) + +type profiler struct { + cpuProfile *os.File + memProfile string +} + +// newProfiler creates a profiler that writes to the given files. +// it returns an empty profiler if both files are empty. +// so that stop() will never fail. +func newProfiler(cpuProfile, memProfile string) (profiler, error) { + if cpuProfile == "" { + return profiler{ + memProfile: memProfile, + }, nil + } + + f, err := os.Create(cpuProfile) + if err != nil { + return profiler{}, err + } + pprof.StartCPUProfile(f) + + return profiler{ + cpuProfile: f, + memProfile: memProfile, + }, nil +} + +func (p *profiler) stop() error { + if p.cpuProfile != nil { + pprof.StopCPUProfile() + p.cpuProfile.Close() + } + + if p.memProfile == "" { + return nil + } + + f, err := os.Create(p.memProfile) + if err != nil { + return err + } + defer f.Close() + runtime.GC() + return pprof.WriteHeapProfile(f) +} diff --git a/pkg/aspect/lint/bep.go b/pkg/aspect/lint/bep.go index a407467c1..58caa28ac 100644 --- a/pkg/aspect/lint/bep.go +++ b/pkg/aspect/lint/bep.go @@ -23,7 +23,6 @@ import ( "os" "path" "path/filepath" - "strconv" "strings" "time" @@ -34,10 +33,10 @@ import ( // ResultForLabel aggregates the relevant files we find in the BEP for type ResultForLabel struct { label string + mnemonic string exitCodeFile *buildeventstream.File reportFile *buildeventstream.File patchFile *buildeventstream.File - linter string } type LintBEPHandler struct { @@ -46,17 +45,15 @@ type LintBEPHandler struct { workspaceRoot string handleResultsErrgroup *errgroup.Group resultsByLabel map[string]*ResultForLabel - lintHandlers []LintHandler } -func newLintBEPHandler(ctx context.Context, workspaceRoot string, handleResultsErrgroup *errgroup.Group, lintHandlers []LintHandler) *LintBEPHandler { +func newLintBEPHandler(ctx context.Context, workspaceRoot string, handleResultsErrgroup *errgroup.Group) *LintBEPHandler { return &LintBEPHandler{ ctx: ctx, namedSets: make(map[string]*buildeventstream.NamedSetOfFiles), resultsByLabel: make(map[string]*ResultForLabel), workspaceRoot: workspaceRoot, handleResultsErrgroup: handleResultsErrgroup, - lintHandlers: lintHandlers, } } @@ -116,6 +113,21 @@ func (runner *LintBEPHandler) readBEPFile(file *buildeventstream.File) ([]byte, } } +func parseLinterMnemonicFromFilename(filename string) string { + // Parse the filename convention that rules_lint has for output files. + // path/to/.. -> linter + // See https://github.com/aspect-build/rules_lint/blob/6df14f0e5dae0c9a9c0e8e6f69e25bbdb3aa7394/lint/private/lint_aspect.bzl#L28. + s := strings.Split(filepath.Base(filename), ".") + if len(s) < 3 { + return "" + } + // Filter out mnemonics that don't start with AspectRulesLint, which is the rules_lint convention + if !strings.HasPrefix(s[len(s)-2], "AspectRulesLint") { + return "" + } + return s[len(s)-2] +} + func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEvent) error { switch event.Payload.(type) { @@ -137,28 +149,21 @@ func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEven for _, file := range fileSet.GetFiles() { if outputGroup.Name == LINT_PATCH_GROUP { + if mnemonic := parseLinterMnemonicFromFilename(file.Name); mnemonic != "" { + result.mnemonic = mnemonic + } result.patchFile = file } else if outputGroup.Name == LINT_REPORT_GROUP { + if mnemonic := parseLinterMnemonicFromFilename(file.Name); mnemonic != "" { + result.mnemonic = mnemonic + } if strings.HasSuffix(file.Name, ".report") { result.reportFile = file - - // Parse the filename convention that rules_lint has for report files. - // path/to/linter.target_name.aspect_rules_lint.report -> linter - s := strings.Split(filepath.Base(file.Name), ".") - if len(s) > 2 { - result.linter = s[len(s)-2] - } } else if strings.HasSuffix(file.Name, ".exit_code") { result.exitCodeFile = file } } } - - if outputGroup.Name == LINT_PATCH_GROUP { - runner.lintHandlersPatch(result) - } else if outputGroup.Name == LINT_REPORT_GROUP { - runner.lintHandlersReport(result) - } } } } @@ -166,69 +171,3 @@ func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEven return nil } - -func (runner *LintBEPHandler) lintHandlersPatch(result *ResultForLabel) { - if len(runner.lintHandlers) == 0 { - return - } - - if result.patchFile == nil { - return - } - - // async handling of this lint patch - func(label string, linter string, patchFile *buildeventstream.File) { - runner.handleResultsErrgroup.Go(func() error { - patch, err := runner.readBEPFile(patchFile) - if err != nil { - return fmt.Errorf("failed to read patch file for target %s from linter %s: %v", label, linter, err) - } - for _, h := range runner.lintHandlers { - if err = h.Patch(label, linter, patch); err != nil { - return fmt.Errorf("failed to handle patch for target %s from linter %s: %v", label, linter, err) - } - } - return nil - }) - }(result.label, result.linter, result.patchFile) -} - -func (runner *LintBEPHandler) lintHandlersReport(result *ResultForLabel) { - if len(runner.lintHandlers) == 0 { - return - } - - if result.reportFile == nil { - return - } - - // async handling of this lint result - func(label string, linter string, reportFile *buildeventstream.File, exitCodeFile *buildeventstream.File) { - runner.handleResultsErrgroup.Go(func() error { - report, err := runner.readBEPFile(reportFile) - if err != nil { - return fmt.Errorf("failed to read report file for target %s from linter %s: %v", label, linter, err) - } - exitCode := 0 - if exitCodeFile != nil { - exitCodeBytes, err := runner.readBEPFile(exitCodeFile) - if err != nil { - return fmt.Errorf("failed to read exit code file for target %s from linter %s: %v", label, linter, err) - } - targetExitCode, err := strconv.Atoi(strings.TrimSpace(string(exitCodeBytes))) - if err != nil { - return fmt.Errorf("failed to parse exit code as integer for target %s from linter %s: %v", label, linter, err) - } - if targetExitCode > 0 { - exitCode = 1 - } - } - for _, h := range runner.lintHandlers { - if err = h.Report(label, linter, report, exitCode); err != nil { - return fmt.Errorf("failed to handle report for target %s from linter %s: %v", label, linter, err) - } - } - return nil - }) - }(result.label, result.linter, result.reportFile, result.exitCodeFile) -} diff --git a/pkg/aspect/lint/lint.go b/pkg/aspect/lint/lint.go index c75f4fdc3..6473b7840 100644 --- a/pkg/aspect/lint/lint.go +++ b/pkg/aspect/lint/lint.go @@ -41,22 +41,29 @@ import ( "golang.org/x/sync/errgroup" ) -type LintHandler interface { - Report(label string, linter string, report []byte, exitCode int) error - Patch(label string, linter string, patch []byte) error +type LintResult struct { + Label string + Mnemonic string + ExitCode int + Report string + Patch []byte +} + +type LintResultsHandler interface { + Results(results []*LintResult) error } type Linter struct { ioutils.Streams - bzl bazel.Bazel - lintHandlers []LintHandler + bzl bazel.Bazel + resultsHandlers []LintResultsHandler } // Align with rules_lint const ( LINT_REPORT_GROUP = "rules_lint_report" LINT_PATCH_GROUP = "rules_lint_patch" - LINT_RESULT_REGEX = ".*aspect_rules_lint.*" + LINT_RESULT_REGEX = ".*AspectRulesLint.*" HISTOGRAM_CHARS = 20 MAX_FILENAME_WIDTH = 80 ) @@ -64,12 +71,12 @@ const ( func New( streams ioutils.Streams, bzl bazel.Bazel, - lintHandlers []LintHandler, + resultsHandlers []LintResultsHandler, ) *Linter { return &Linter{ - Streams: streams, - bzl: bzl, - lintHandlers: lintHandlers, + Streams: streams, + bzl: bzl, + resultsHandlers: resultsHandlers, } } @@ -221,7 +228,7 @@ lint: return fmt.Errorf("failed to find workspace root: %w", err) } - lintBEPHandler = newLintBEPHandler(handleResultsCtx, workspaceRoot, handleResultsErrgroup, runner.lintHandlers) + lintBEPHandler = newLintBEPHandler(handleResultsCtx, workspaceRoot, handleResultsErrgroup) besBackend.RegisterSubscriber(lintBEPHandler.bepEventCallback) } @@ -245,97 +252,129 @@ lint: return fmt.Errorf("%v BES subscriber error(s)", len(subscriberErrors)) } - // Bazel is done running, so stdout is now safe for us to print the results - applyNone := false - exitCode := 0 - for label, result := range lintBEPHandler.resultsByLabel { - if result.exitCodeFile != nil { - exitCodeBytes, err := lintBEPHandler.readBEPFile(result.exitCodeFile) + // Convert raw results to list of LintResult structs + results := make([]*LintResult, 0, len(lintBEPHandler.resultsByLabel)) + for _, r := range lintBEPHandler.resultsByLabel { + result := &LintResult{ + Mnemonic: r.mnemonic, + Label: r.label, + } + results = append(results, result) + + // parse exit code file + if r.exitCodeFile != nil { + exitCodeBytes, err := lintBEPHandler.readBEPFile(r.exitCodeFile) if err != nil { return err } - targetExitCode, err := strconv.Atoi(strings.TrimSpace(string(exitCodeBytes))) + exitCode, err := strconv.Atoi(strings.TrimSpace(string(exitCodeBytes))) if err != nil { return fmt.Errorf("failed parse read exit code as integer: %v", err) } - if targetExitCode > 0 { - exitCode = 1 + result.ExitCode = exitCode + } + + // read the report file + if r.reportFile != nil { + reportBytes, err := lintBEPHandler.readBEPFile(r.reportFile) + if err != nil { + return err } + result.Report = strings.TrimSpace(string(reportBytes)) } - reportBytes, err := lintBEPHandler.readBEPFile(result.reportFile) - if err != nil { - return err + + // read the patch file + if r.patchFile != nil { + patch, err := lintBEPHandler.readBEPFile(r.patchFile) + if err != nil { + return err + } + if patch != nil && len(patch) > 0 { + result.Patch = patch + } + } + } + + // Send the result to any lint handlers. Call the handlers even if results list + // is empty since no results is a success. + for _, h := range runner.resultsHandlers { + if err := h.Results(results); err != nil { + return fmt.Errorf("lint results handler failed: %w", err) } + } + + // Bazel is done running, so stdout is now safe for us to print the results + applyNone := false + exitCode := 0 + for _, r := range results { + if r.ExitCode > 0 { + exitCode = 1 + } + printHeader := true - report := strings.TrimSpace(string(reportBytes)) - if printReport && len(report) > 0 { + if len(r.Report) > 0 { if printHeader { - runner.printLintResultsHeader(label) + runner.printLintResultsHeader(r.Label) printHeader = false } - runner.printLintReport(report) + runner.printLintReport(r.Report) } - if result.patchFile != nil { - patch, err := lintBEPHandler.readBEPFile(result.patchFile) - if err != nil { - return err + + if r.Patch != nil { + if printHeader { + runner.printLintResultsHeader(r.Label) + printHeader = false } - if patch != nil && len(patch) > 0 { - if printHeader { - runner.printLintResultsHeader(label) - printHeader = false + color.New(color.FgYellow).Fprintf(runner.Streams.Stdout, "Some problems have automated fixes available:\n\n") + if showDiff { + runner.printLintPatchDiff(r.Patch) + } else { + err = runner.printLintPatchDiffStat(r.Patch) + if err != nil { + return fmt.Errorf("failed to parse patch file for %s: %v", r.Label, err) } - color.New(color.FgYellow).Fprintf(runner.Streams.Stdout, "Some problems have automated fixes available:\n\n") - if showDiff { - runner.printLintPatchDiff(patch) - } else { - err = runner.printLintPatchDiffStat(patch) - if err != nil { - return fmt.Errorf("failed to parse patch file %s: %v", result.patchFile, err) + } + apply := applyAll + if isInteractiveMode && !applyNone && !apply { + for { + var choice string + options := []huh.Option[string]{ + huh.NewOption("Yes", "yes"), + huh.NewOption("No", "no"), + huh.NewOption("All", "all"), + huh.NewOption("None", "none"), } - } - apply := applyAll - if isInteractiveMode && !applyNone && !apply { - for { - var choice string - options := []huh.Option[string]{ - huh.NewOption("Yes", "yes"), - huh.NewOption("No", "no"), - huh.NewOption("All", "all"), - huh.NewOption("None", "none"), - } - if !showDiff { - options = append(options, huh.NewOption("Show Diff", "diff")) - } - applyFixPrompt := huh.NewSelect[string](). - Title("Apply fixes?"). - Options(options...). - Value(&choice) - form := huh.NewForm(huh.NewGroup(applyFixPrompt)) - err := form.Run() - if err != nil { - return fmt.Errorf("prompt failed: %v", err) - } - switch choice { - case "yes": - apply = true - case "all": - apply = true - applyAll = true - case "none": - applyNone = true - case "diff": - runner.printLintPatchDiff(patch) - continue - } - break + if !showDiff { + options = append(options, huh.NewOption("Show Diff", "diff")) } - } - if apply { - err = runner.applyLintPatch(patch) + applyFixPrompt := huh.NewSelect[string](). + Title("Apply fixes?"). + Options(options...). + Value(&choice) + form := huh.NewForm(huh.NewGroup(applyFixPrompt)) + err := form.Run() if err != nil { - return fmt.Errorf("failed to apply patch file %s: %v", result.patchFile, err) + return fmt.Errorf("prompt failed: %v", err) + } + switch choice { + case "yes": + apply = true + case "all": + apply = true + applyAll = true + case "none": + applyNone = true + case "diff": + runner.printLintPatchDiff(r.Patch) + continue } + break + } + } + if apply { + err = runner.applyLintPatch(r.Patch) + if err != nil { + return fmt.Errorf("failed to apply patch file for %s: %v", r.Label, err) } } } diff --git a/pkg/aspect/root/flags/BUILD.bazel b/pkg/aspect/root/flags/BUILD.bazel index af1d69694..7723ba493 100644 --- a/pkg/aspect/root/flags/BUILD.bazel +++ b/pkg/aspect/root/flags/BUILD.bazel @@ -13,6 +13,7 @@ go_library( importpath = "aspect.build/cli/pkg/aspect/root/flags", visibility = ["//visibility:public"], deps = [ + "//buildinfo", "//pkg/interceptors", "//pkg/ioutils", "@com_github_spf13_cobra//:cobra", diff --git a/pkg/aspect/root/flags/global.go b/pkg/aspect/root/flags/global.go index 1683f5b60..203d07928 100644 --- a/pkg/aspect/root/flags/global.go +++ b/pkg/aspect/root/flags/global.go @@ -19,16 +19,30 @@ package flags import ( "fmt" + "aspect.build/cli/buildinfo" + "github.com/spf13/cobra" ) +func AspectLockVersionDefault() bool { + // We set the default `--aspect:lock_version`` depending on whether or not the CLI is a stamped + // release or unstamped development build. When unstamped we want to ignore the version of the + // CLI specified in `.bazeliskrc` or `.aspect/cli/config.yaml` and not re-enter that version + // when booting since during development that is more ergonomic. For stamped release builds, on + // the other hand, we want to CLI to honor the version specified in the repos `.bazeliskrc` or + // `.aspect/cli/config.yaml` since that is the version that developers are expecting to be run. + // In either case, the default behavior can be overridden by explicitly specifying the flag as + // either `--aspect:lock_version` or `--aspect:lock_version=false`. + return !buildinfo.Current().HasRelease() +} + func AddGlobalFlags(cmd *cobra.Command, defaultInteractive bool) { // Documented global flags. These flags show up as "global flags" on the `help` command output. cmd.PersistentFlags().String(AspectConfigFlagName, "", fmt.Sprintf("User-specified Aspect CLI config file. /dev/null indicates that all further --%s flags will be ignored.", AspectConfigFlagName)) cmd.PersistentFlags().Bool(AspectInteractiveFlagName, defaultInteractive, "Interactive mode (e.g. prompts for user input)") // Hidden global flags - cmd.PersistentFlags().Bool(AspectLockVersion, false, "Lock the version of the Aspect CLI. This prevents the Aspect CLI from downloading and running an different version of the Aspect CLI if one is specified in .bazeliskrc or the Aspect CLI config.") + cmd.PersistentFlags().Bool(AspectLockVersion, AspectLockVersionDefault(), "Lock the version of the Aspect CLI. This prevents the Aspect CLI from downloading and running an different version of the Aspect CLI if one is specified in .bazeliskrc or the Aspect CLI config.") cmd.PersistentFlags().MarkHidden(AspectLockVersion) cmd.PersistentFlags().Bool(AspectForceBesBackendFlagName, false, "Force the creation of a BES backend even if there are no plugins loaded") diff --git a/pkg/bazel/bazelisk.go b/pkg/bazel/bazelisk.go index def9d014b..b6db6ac00 100644 --- a/pkg/bazel/bazelisk.go +++ b/pkg/bazel/bazelisk.go @@ -202,7 +202,7 @@ func (bazelisk *Bazelisk) GetConfig(name string) string { // GetEnvOrConfig reads a configuration value from the environment, but fall back to reading it from .bazeliskrc. func (bazelisk *Bazelisk) GetEnvOrConfig(name string) string { - if val := os.Getenv(name); val != "" { + if val, found := os.LookupEnv(name); found { return val }