diff --git a/gazelle/buf/buf.go b/gazelle/buf/buf.go index 53e444a..34a7fec 100644 --- a/gazelle/buf/buf.go +++ b/gazelle/buf/buf.go @@ -33,12 +33,10 @@ const ( const lang = "buf" -var ( - stringToBreakingMode = map[string]BreakingMode{ - "module": BreakingModeModule, - "package": BreakingModePackage, - } -) +var stringToBreakingMode = map[string]BreakingMode{ + "module": BreakingModeModule, + "package": BreakingModePackage, +} // BreakingMode is the generation strategy for buf_breaking_test // @@ -80,18 +78,21 @@ type Config struct { ModuleRoot bool // BufConfigFile is for the nearest buf.yaml BufConfigFile label.Label - // GeneratePushRule controls if buf_push should be generated. + // Path to the nearest module root. // - // Always false for now. - GeneratePushRule bool + // Only applies to v2. + ModuleConfig *ModuleConfig } // BufModule is the parsed buf.yaml. It currently only supports version, name, and build // top-level attributes. type BufModule struct { - Version string `json:"version,omitempty" yaml:"version,omitempty"` - Name string `json:"name,omitempty" yaml:"name,omitempty"` - Build BuildConfig `json:"build,omitempty" yaml:"build,omitempty"` + Version string `json:"version,omitempty" yaml:"version,omitempty"` + // V1 + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Build BuildConfig `json:"build,omitempty" yaml:"build,omitempty"` + // V2 + Modules []ModuleConfig `json:"modules,omitempty" yaml:"modules,omitempty"` } // BuildConfig is the build section of the buf.yaml @@ -99,6 +100,11 @@ type BuildConfig struct { Excludes []string `json:"excludes,omitempty" yaml:"excludes,omitempty"` } +type ModuleConfig struct { + Path string `json:"path,omitempty" yaml:"path,omitempty"` + Excludes []string `json:"excludes,omitempty" yaml:"excludes,omitempty"` +} + // GetConfigForGazelleConfig extracts a Config from gazelle config. // It will return `nil` if one is not found. // diff --git a/gazelle/buf/buf_lock.go b/gazelle/buf/buf_lock.go index 8e1426b..30e205e 100644 --- a/gazelle/buf/buf_lock.go +++ b/gazelle/buf/buf_lock.go @@ -24,5 +24,6 @@ type bufLock struct { Owner string `yaml:"owner,omitempty" json:"owner,omitempty"` Repository string `yaml:"repository,omitempty" json:"repository,omitempty"` Commit string `yaml:"commit,omitempty" json:"commit,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` } `yaml:"deps,omitempty" json:"deps,omitempty"` } diff --git a/gazelle/buf/buf_test.go b/gazelle/buf/buf_test.go index 8c556f9..ba43aac 100644 --- a/gazelle/buf/buf_test.go +++ b/gazelle/buf/buf_test.go @@ -32,6 +32,7 @@ import ( func TestLint(t *testing.T) { t.Parallel() testRunGazelle(t, "lint") + testRunGazelle(t, "v2/lint") } func TestBreaking(t *testing.T) { @@ -39,40 +40,43 @@ func TestBreaking(t *testing.T) { testRunGazelle(t, "breaking_module") testRunGazelle(t, "breaking_package") testRunGazelle(t, "breaking_package_to_module") + testRunGazelle(t, "v2/breaking_module") + testRunGazelle(t, "v2/breaking_package") + testRunGazelle(t, "v2/breaking_package_to_module") } func TestExcludes(t *testing.T) { t.Parallel() testRunGazelle(t, "excludes_module") testRunGazelle(t, "excludes_package") + testRunGazelle(t, "v2/excludes_module") + testRunGazelle(t, "v2/excludes_package") } func TestWorkspaces(t *testing.T) { t.Parallel() testRunGazelle(t, "workspace") + testRunGazelle(t, "v2/workspace") } func TestCrossResolve(t *testing.T) { t.Parallel() testRunGazelle(t, "cross_resolve") -} - -func TestPush(t *testing.T) { - // Skipping this test until we release the `buf_push` rule - t.SkipNow() - t.Parallel() - testRunGazelle(t, "push") + testRunGazelle(t, "v2/cross_resolve") } func TestMerge(t *testing.T) { t.Parallel() testRunGazelle(t, "merge") + testRunGazelle(t, "v2/merge") } func TestImportResolve(t *testing.T) { t.Parallel() testRunGazelle(t, "imports", "update-repos", "--from_file=buf.work.yaml", "-to_macro=buf_deps.bzl%buf_deps", "-prune") testRunGazelle(t, "imports_toolchain_name", "update-repos", "--from_file=buf.work.yaml", "-to_macro=buf_deps.bzl%buf_deps", "-prune") + testRunGazelle(t, "v2/imports", "update-repos", "--from_file=buf.yaml", "-to_macro=buf_deps.bzl%buf_deps", "-prune") + testRunGazelle(t, "v2/imports_toolchain_name", "update-repos", "--from_file=buf.yaml", "-to_macro=buf_deps.bzl%buf_deps", "-prune") } func testRunGazelle(t *testing.T, name string, gazelleArgs ...string) { diff --git a/gazelle/buf/config.go b/gazelle/buf/config.go index f4b7bf6..43a2dba 100644 --- a/gazelle/buf/config.go +++ b/gazelle/buf/config.go @@ -85,11 +85,39 @@ func loadConfig(gazelleConfig *config.Config, packageRelativePath string, file * if err != nil { log.Print("error trying to load default config", err) } - if bufModule != nil { + if config.Module != nil && config.Module.Version == "v2" { + for _, module := range config.Module.Modules { + if module.Path == packageRelativePath { + config.ModuleRoot = true + config.BufConfigFile = label.New("", "", "buf.yaml") // v2 will always have a buf.yaml at the roor. + config.ModuleConfig = &module + break + } + } + } else if bufModule != nil { config.Module = bufModule config.ModuleRoot = true config.BufConfigFile = label.New("", packageRelativePath, bufConfigFile) } + // When using workspaces, for gazelle to generate accurate proto_library rules + // we need add `# gazelle:proto_strip_import_prefix /path` to BUILD file at each module root + // + // Here we set the config if the directive is not present + if config.ModuleRoot && packageRelativePath != "" { + protoConfig := proto.GetProtoConfig(gazelleConfig) + stripImportPrefix := "/" + packageRelativePath + if protoConfig.StripImportPrefix == "" { + protoConfig.StripImportPrefix = stripImportPrefix + } + if protoConfig.StripImportPrefix != stripImportPrefix { + log.Printf( + "strip_import_prefix at %s should be %s but is %s", + packageRelativePath, + stripImportPrefix, + protoConfig.StripImportPrefix, + ) + } + } if file == nil { return config } @@ -111,25 +139,6 @@ func loadConfig(gazelleConfig *config.Config, packageRelativePath string, file * config.BreakingMode = breakingMode } } - // When using workspaces, for gazelle to generate accurate proto_library rules - // we need add `# gazelle:proto_strip_import_prefix /path` to BUILD file at each module root - // - // Here we set the config if the directive is not present - if config.ModuleRoot && packageRelativePath != "" { - protoConfig := proto.GetProtoConfig(gazelleConfig) - stripImportPrefix := "/" + packageRelativePath - if protoConfig.StripImportPrefix == "" { - protoConfig.StripImportPrefix = stripImportPrefix - } - if protoConfig.StripImportPrefix != stripImportPrefix { - log.Printf( - "strip_import_prefix at %s should be %s but is %s", - packageRelativePath, - stripImportPrefix, - protoConfig.StripImportPrefix, - ) - } - } return config } @@ -172,11 +181,20 @@ func isWithinExcludes(config *Config, path string) bool { if config.Module == nil { return false } + // v1 for _, exclude := range config.Module.Build.Excludes { if strings.Contains(path, exclude) { return true } } + // v2, all paths are relative to the root to `buf.yaml`, so no need to filter out the module. + for _, module := range config.Module.Modules { + for _, exclude := range module.Excludes { + if strings.HasPrefix(path, exclude) { + return true + } + } + } return false } diff --git a/gazelle/buf/generate.go b/gazelle/buf/generate.go index 5f8ba38..f22f5cd 100644 --- a/gazelle/buf/generate.go +++ b/gazelle/buf/generate.go @@ -51,12 +51,6 @@ func (*bufLang) GenerateRules(args language.GenerateArgs) language.GenerateResul result.Imports = append(result.Imports, struct{}{}) } if config.ModuleRoot { - protoImportPaths := getProtoImportPaths(config, args.Dir) - if config.GeneratePushRule && config.Module.Name != "" { - pushRule := generatePushRule() - result.Gen = append(result.Gen, pushRule) - result.Imports = append(result.Imports, protoImportPaths) - } if config.BreakingImageTarget != "" && config.BreakingMode == BreakingModeModule { breakingRule := generateBreakingRule(config, "buf") result.Gen = append(result.Gen, breakingRule) @@ -73,10 +67,6 @@ func (*bufLang) GenerateRules(args language.GenerateArgs) language.GenerateResul result.Empty = append(result.Empty, generateEmptyRule(rule)) continue } - if rule.Kind() == pushRuleKind { - result.Empty = append(result.Empty, generateEmptyRule(rule)) - continue - } // proto_library targets are mapped one to one for lint and breaking rules in package mode if rule.Kind() == lintRuleKind || rule.Kind() == breakingRuleKind { if shouldRemoveSingleTargetBufRule( @@ -96,6 +86,9 @@ func generateLintRule(config *Config, target string) *rule.Rule { if config.Module != nil { r.SetAttr("config", config.BufConfigFile.String()) } + if config.ModuleConfig != nil { + r.SetAttr("module", config.ModuleConfig.Path) + } return r } @@ -113,13 +106,9 @@ func generateBreakingRule(config *Config, target string) *rule.Rule { if config.Module != nil { r.SetAttr("config", config.BufConfigFile.String()) } - return r -} - -func generatePushRule() *rule.Rule { - r := rule.NewRule(pushRuleKind, "buf_push") - r.SetAttr("config", "buf.yaml") - r.SetAttr("lock", "buf.lock") + if config.ModuleConfig != nil { + r.SetAttr("module", config.ModuleConfig.Path) + } return r } diff --git a/gazelle/buf/kinds.go b/gazelle/buf/kinds.go index 3f40c81..221a5ed 100644 --- a/gazelle/buf/kinds.go +++ b/gazelle/buf/kinds.go @@ -20,7 +20,6 @@ const ( lintRuleKind = "buf_lint_test" breakingRuleKind = "buf_breaking_test" dependenciesRepoRuleKind = "buf_dependencies" - pushRuleKind = "buf_push" ) var bufKinds = map[string]rule.KindInfo{ @@ -56,20 +55,6 @@ var bufKinds = map[string]rule.KindInfo{ "modules": true, }, }, - pushRuleKind: { - MatchAttrs: []string{"targets"}, - NonEmptyAttrs: map[string]bool{ - "targets": true, - }, - MergeableAttrs: map[string]bool{ - "targets": true, - "config": true, - "lock": true, - }, - ResolveAttrs: map[string]bool{ - "targets": true, - }, - }, } var bufLoads = []rule.LoadInfo{ @@ -79,7 +64,6 @@ var bufLoads = []rule.LoadInfo{ lintRuleKind, breakingRuleKind, dependenciesRepoRuleKind, - pushRuleKind, }, }, } diff --git a/gazelle/buf/resolve.go b/gazelle/buf/resolve.go index 3e05dc9..98f6901 100644 --- a/gazelle/buf/resolve.go +++ b/gazelle/buf/resolve.go @@ -42,8 +42,6 @@ func (l *bufLang) Resolve( if config.BreakingMode != BreakingModeModule { return } - fallthrough - case pushRuleKind: resolveProtoTargetsForRule( gazelleConfig, ruleIndex, @@ -55,7 +53,7 @@ func (l *bufLang) Resolve( } } -// resolveProtoTargetsForRule resolves targets of buf_breaking_test in Module mode and buf_push +// resolveProtoTargetsForRule resolves targets of buf_breaking_test in Module mode func resolveProtoTargetsForRule( gazelleConfig *config.Config, ruleIndex *resolve.RuleIndex, @@ -64,7 +62,7 @@ func resolveProtoTargetsForRule( importsRaw interface{}, fromLabel label.Label, ) { - // importsRaw will be `[]string` for module mode and buf_push + // importsRaw will be `[]string` for module mode imports, ok := importsRaw.([]string) if !ok { return diff --git a/gazelle/buf/testdata/push/BUILD.out b/gazelle/buf/testdata/push/BUILD.out deleted file mode 100644 index 66926dd..0000000 --- a/gazelle/buf/testdata/push/BUILD.out +++ /dev/null @@ -1,8 +0,0 @@ -load("@rules_buf//buf:defs.bzl", "buf_push") - -buf_push( - name = "buf_push", - config = "buf.yaml", - lock = "buf.lock", - targets = ["//foo/v1:foo_proto"], -) diff --git a/gazelle/buf/testdata/push/buf.yaml b/gazelle/buf/testdata/push/buf.yaml deleted file mode 100644 index d87ab92..0000000 --- a/gazelle/buf/testdata/push/buf.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: v1 -name: buf.build/bazel/test -breaking: - use: - - FILE -lint: - use: - - DEFAULT diff --git a/gazelle/buf/testdata/v2/breaking_module/BUILD.in b/gazelle/buf/testdata/v2/breaking_module/BUILD.in new file mode 100644 index 0000000..5de5235 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_module/BUILD.in @@ -0,0 +1 @@ +# gazelle:buf_breaking_against //:against_file \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/breaking_module/BUILD.out b/gazelle/buf/testdata/v2/breaking_module/BUILD.out new file mode 100644 index 0000000..12a4725 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_module/BUILD.out @@ -0,0 +1,10 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test") + +# gazelle:buf_breaking_against //:against_file + +buf_breaking_test( + name = "buf_breaking", + against = "//:against_file", + config = "//:buf.yaml", + targets = ["//foo/v1:foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/breaking_module/buf.yaml b/gazelle/buf/testdata/v2/breaking_module/buf.yaml new file mode 100644 index 0000000..6fe9ec4 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_module/buf.yaml @@ -0,0 +1,14 @@ +version: v2 +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/breaking_module/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/breaking_module/foo/v1/BUILD.in new file mode 100644 index 0000000..dce0c73 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_module/foo/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/breaking_module/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/breaking_module/foo/v1/BUILD.out new file mode 100644 index 0000000..556d787 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_module/foo/v1/BUILD.out @@ -0,0 +1,14 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/push/foo/v1/foo.proto b/gazelle/buf/testdata/v2/breaking_module/foo/v1/foo.proto similarity index 100% rename from gazelle/buf/testdata/push/foo/v1/foo.proto rename to gazelle/buf/testdata/v2/breaking_module/foo/v1/foo.proto diff --git a/gazelle/buf/testdata/v2/breaking_package/BUILD.in b/gazelle/buf/testdata/v2/breaking_package/BUILD.in new file mode 100644 index 0000000..f64d8ce --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package/BUILD.in @@ -0,0 +1,2 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/breaking_package/BUILD.out b/gazelle/buf/testdata/v2/breaking_package/BUILD.out new file mode 100644 index 0000000..f64d8ce --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package/BUILD.out @@ -0,0 +1,2 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/breaking_package/buf.yaml b/gazelle/buf/testdata/v2/breaking_package/buf.yaml new file mode 100644 index 0000000..6fe9ec4 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package/buf.yaml @@ -0,0 +1,14 @@ +version: v2 +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/breaking_package/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/breaking_package/foo/v1/BUILD.in new file mode 100644 index 0000000..dce0c73 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package/foo/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/breaking_package/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/breaking_package/foo/v1/BUILD.out new file mode 100644 index 0000000..de57864 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package/foo/v1/BUILD.out @@ -0,0 +1,22 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) + +buf_breaking_test( + name = "foo_proto_breaking", + against = "//:against_file", + config = "//:buf.yaml", + limit_to_input_files = True, + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/push/BUILD.in b/gazelle/buf/testdata/v2/breaking_package/foo/v1/foo.proto similarity index 100% rename from gazelle/buf/testdata/push/BUILD.in rename to gazelle/buf/testdata/v2/breaking_package/foo/v1/foo.proto diff --git a/gazelle/buf/testdata/v2/breaking_package_to_module/BUILD.in b/gazelle/buf/testdata/v2/breaking_package_to_module/BUILD.in new file mode 100644 index 0000000..c1d725b --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package_to_module/BUILD.in @@ -0,0 +1 @@ +# gazelle:buf_breaking_against //:against_file diff --git a/gazelle/buf/testdata/v2/breaking_package_to_module/BUILD.out b/gazelle/buf/testdata/v2/breaking_package_to_module/BUILD.out new file mode 100644 index 0000000..12a4725 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package_to_module/BUILD.out @@ -0,0 +1,10 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test") + +# gazelle:buf_breaking_against //:against_file + +buf_breaking_test( + name = "buf_breaking", + against = "//:against_file", + config = "//:buf.yaml", + targets = ["//foo/v1:foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/breaking_package_to_module/buf.yaml b/gazelle/buf/testdata/v2/breaking_package_to_module/buf.yaml new file mode 100644 index 0000000..6fe9ec4 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package_to_module/buf.yaml @@ -0,0 +1,14 @@ +version: v2 +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/BUILD.in new file mode 100644 index 0000000..bce062e --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/BUILD.in @@ -0,0 +1,21 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) + +buf_breaking_test( + name = "foo_proto_breaking", + against = "//:against_file", + config = "//:buf.yaml", + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/BUILD.out new file mode 100644 index 0000000..556d787 --- /dev/null +++ b/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/BUILD.out @@ -0,0 +1,14 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/foo.proto b/gazelle/buf/testdata/v2/breaking_package_to_module/foo/v1/foo.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/cross_resolve/barapis/BUILD.in b/gazelle/buf/testdata/v2/cross_resolve/barapis/BUILD.in new file mode 100644 index 0000000..da23603 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/barapis/BUILD.in @@ -0,0 +1,3 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package +# gazelle:proto_strip_import_prefix /barapis diff --git a/gazelle/buf/testdata/v2/cross_resolve/barapis/BUILD.out b/gazelle/buf/testdata/v2/cross_resolve/barapis/BUILD.out new file mode 100644 index 0000000..da23603 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/barapis/BUILD.out @@ -0,0 +1,3 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package +# gazelle:proto_strip_import_prefix /barapis diff --git a/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/BUILD.in b/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/BUILD.in new file mode 100644 index 0000000..d95a30d --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + strip_import_prefix = "/barapis", + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/BUILD.out b/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/BUILD.out new file mode 100644 index 0000000..aed1b98 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/BUILD.out @@ -0,0 +1,25 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + strip_import_prefix = "/barapis", + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "bar_proto_lint", + config = "//:buf.yaml", + module = "barapis", + targets = [":bar_proto"], +) + +buf_breaking_test( + name = "bar_proto_breaking", + against = "//:against_file", + config = "//:buf.yaml", + limit_to_input_files = True, + module = "barapis", + targets = [":bar_proto"], +) diff --git a/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/bar.proto b/gazelle/buf/testdata/v2/cross_resolve/barapis/bar/v1/bar.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/cross_resolve/buf.yaml b/gazelle/buf/testdata/v2/cross_resolve/buf.yaml new file mode 100644 index 0000000..b8e8d51 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/buf.yaml @@ -0,0 +1,18 @@ +version: v2 +modules: + - path: barapis + - path: fooapis + - path: petapis +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/cross_resolve/fooapis/BUILD.in b/gazelle/buf/testdata/v2/cross_resolve/fooapis/BUILD.in new file mode 100644 index 0000000..c1d725b --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/fooapis/BUILD.in @@ -0,0 +1 @@ +# gazelle:buf_breaking_against //:against_file diff --git a/gazelle/buf/testdata/v2/cross_resolve/fooapis/BUILD.out b/gazelle/buf/testdata/v2/cross_resolve/fooapis/BUILD.out new file mode 100644 index 0000000..5b16619 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/fooapis/BUILD.out @@ -0,0 +1,11 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test") + +# gazelle:buf_breaking_against //:against_file + +buf_breaking_test( + name = "buf_breaking", + against = "//:against_file", + config = "//:buf.yaml", + module = "fooapis", + targets = ["//fooapis/foo/v1:foo_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/BUILD.out new file mode 100644 index 0000000..91fb131 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/BUILD.out @@ -0,0 +1,16 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_v1_proto", + srcs = ["foo.proto"], + strip_import_prefix = "/fooapis", + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_v1_proto_lint", + config = "//:buf.yaml", + module = "fooapis", + targets = [":foo_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/foo.proto b/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/foo.proto new file mode 100644 index 0000000..403aebb --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/fooapis/foo/v1/foo.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package foo.v1; + +message Foo {} diff --git a/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/BUILD.in b/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/BUILD.out b/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/BUILD.out new file mode 100644 index 0000000..8b6365a --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/BUILD.out @@ -0,0 +1,20 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "pets_v1_proto", + srcs = ["pets.proto"], + strip_import_prefix = "/petapis", + visibility = ["//visibility:public"], + deps = [ + "//fooapis/foo/v1:foo_v1_proto", + "@buf_deps//validate:validate_proto", + ], +) + +buf_lint_test( + name = "pets_v1_proto_lint", + config = "//:buf.yaml", + module = "petapis", + targets = [":pets_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/pets.proto b/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/pets.proto new file mode 100644 index 0000000..3329c54 --- /dev/null +++ b/gazelle/buf/testdata/v2/cross_resolve/petapis/pets/v1/pets.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package pets.v1; + +import "foo/v1/foo.proto"; +import "validate/validate.proto"; + +message Pet { + foo.v1.Foo foo = 1; +} diff --git a/gazelle/buf/testdata/v2/excludes_module/BUILD.in b/gazelle/buf/testdata/v2/excludes_module/BUILD.in new file mode 100644 index 0000000..c1d725b --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/BUILD.in @@ -0,0 +1 @@ +# gazelle:buf_breaking_against //:against_file diff --git a/gazelle/buf/testdata/v2/excludes_module/BUILD.out b/gazelle/buf/testdata/v2/excludes_module/BUILD.out new file mode 100644 index 0000000..12a4725 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/BUILD.out @@ -0,0 +1,10 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test") + +# gazelle:buf_breaking_against //:against_file + +buf_breaking_test( + name = "buf_breaking", + against = "//:against_file", + config = "//:buf.yaml", + targets = ["//foo/v1:foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/excludes_module/bar/v1/BUILD.in b/gazelle/buf/testdata/v2/excludes_module/bar/v1/BUILD.in new file mode 100644 index 0000000..0c945eb --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/bar/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/excludes_module/bar/v1/BUILD.out b/gazelle/buf/testdata/v2/excludes_module/bar/v1/BUILD.out new file mode 100644 index 0000000..3e7bbcd --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/bar/v1/BUILD.out @@ -0,0 +1,8 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/excludes_module/bar/v1/bar.proto b/gazelle/buf/testdata/v2/excludes_module/bar/v1/bar.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/excludes_module/buf.yaml b/gazelle/buf/testdata/v2/excludes_module/buf.yaml new file mode 100644 index 0000000..1ec6877 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/buf.yaml @@ -0,0 +1,18 @@ +version: v2 +modules: + - path: . + excludes: + - bar +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/excludes_module/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/excludes_module/foo/v1/BUILD.in new file mode 100644 index 0000000..dce0c73 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/foo/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/excludes_module/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/excludes_module/foo/v1/BUILD.out new file mode 100644 index 0000000..556d787 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_module/foo/v1/BUILD.out @@ -0,0 +1,14 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/excludes_module/foo/v1/foo.proto b/gazelle/buf/testdata/v2/excludes_module/foo/v1/foo.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/excludes_package/BUILD.in b/gazelle/buf/testdata/v2/excludes_package/BUILD.in new file mode 100644 index 0000000..f64d8ce --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/BUILD.in @@ -0,0 +1,2 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/excludes_package/BUILD.out b/gazelle/buf/testdata/v2/excludes_package/BUILD.out new file mode 100644 index 0000000..f64d8ce --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/BUILD.out @@ -0,0 +1,2 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/excludes_package/bar/v1/BUILD.in b/gazelle/buf/testdata/v2/excludes_package/bar/v1/BUILD.in new file mode 100644 index 0000000..0c945eb --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/bar/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/excludes_package/bar/v1/BUILD.out b/gazelle/buf/testdata/v2/excludes_package/bar/v1/BUILD.out new file mode 100644 index 0000000..3e7bbcd --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/bar/v1/BUILD.out @@ -0,0 +1,8 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/excludes_package/bar/v1/bar.proto b/gazelle/buf/testdata/v2/excludes_package/bar/v1/bar.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/excludes_package/buf.yaml b/gazelle/buf/testdata/v2/excludes_package/buf.yaml new file mode 100644 index 0000000..1ec6877 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/buf.yaml @@ -0,0 +1,18 @@ +version: v2 +modules: + - path: . + excludes: + - bar +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/excludes_package/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/excludes_package/foo/v1/BUILD.in new file mode 100644 index 0000000..dce0c73 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/foo/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/excludes_package/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/excludes_package/foo/v1/BUILD.out new file mode 100644 index 0000000..de57864 --- /dev/null +++ b/gazelle/buf/testdata/v2/excludes_package/foo/v1/BUILD.out @@ -0,0 +1,22 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) + +buf_breaking_test( + name = "foo_proto_breaking", + against = "//:against_file", + config = "//:buf.yaml", + limit_to_input_files = True, + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/excludes_package/foo/v1/foo.proto b/gazelle/buf/testdata/v2/excludes_package/foo/v1/foo.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/imports/WORKSPACE.in b/gazelle/buf/testdata/v2/imports/WORKSPACE.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/imports/WORKSPACE.out b/gazelle/buf/testdata/v2/imports/WORKSPACE.out new file mode 100644 index 0000000..327a802 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports/WORKSPACE.out @@ -0,0 +1,4 @@ +load("//:buf_deps.bzl", "buf_deps") + +# gazelle:repository_macro buf_deps.bzl%buf_deps +buf_deps() \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/imports/barapis/bar/v1/bar.proto b/gazelle/buf/testdata/v2/imports/barapis/bar/v1/bar.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/imports/buf.lock b/gazelle/buf/testdata/v2/imports/buf.lock new file mode 100644 index 0000000..84923a9 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports/buf.lock @@ -0,0 +1,6 @@ +# Generated by buf. DO NOT EDIT. +version: v2 +deps: + - name: buf.build/envoyproxy/protoc-gen-validate + commit: dc09a417d27241f7b069feae2cd74a0e + digest: b5:63939effe0c64a94cd3151770b73007e43c9aeff31dcb24737fb11750dcaaca99338df3c1e5513828a685c743712e59ce283e046c27725e96928d200492bb6ec diff --git a/gazelle/buf/testdata/v2/imports/buf.yaml b/gazelle/buf/testdata/v2/imports/buf.yaml new file mode 100644 index 0000000..63b09c6 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports/buf.yaml @@ -0,0 +1,20 @@ +version: v2 +modules: + - path: barapis + - path: fooapis + - path: petapis +deps: + - buf.build/envoyproxy/protoc-gen-validate +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/imports/buf_deps.bzl.out b/gazelle/buf/testdata/v2/imports/buf_deps.bzl.out new file mode 100644 index 0000000..d9ffc45 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports/buf_deps.bzl.out @@ -0,0 +1,9 @@ +load("@rules_buf//buf:defs.bzl", "buf_dependencies") + +def buf_deps(): + buf_dependencies( + name = "buf_deps", + modules = [ + "buf.build/envoyproxy/protoc-gen-validate:dc09a417d27241f7b069feae2cd74a0e", + ], + ) diff --git a/gazelle/buf/testdata/v2/imports/fooapis/foo/v1/foo.proto b/gazelle/buf/testdata/v2/imports/fooapis/foo/v1/foo.proto new file mode 100644 index 0000000..403aebb --- /dev/null +++ b/gazelle/buf/testdata/v2/imports/fooapis/foo/v1/foo.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package foo.v1; + +message Foo {} diff --git a/gazelle/buf/testdata/v2/imports/petapis/pets/v1/pets.proto b/gazelle/buf/testdata/v2/imports/petapis/pets/v1/pets.proto new file mode 100644 index 0000000..3329c54 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports/petapis/pets/v1/pets.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package pets.v1; + +import "foo/v1/foo.proto"; +import "validate/validate.proto"; + +message Pet { + foo.v1.Foo foo = 1; +} diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/WORKSPACE.in b/gazelle/buf/testdata/v2/imports_toolchain_name/WORKSPACE.in new file mode 100644 index 0000000..fa22897 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/WORKSPACE.in @@ -0,0 +1,8 @@ +load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains") + +rules_buf_dependencies() + +rules_buf_toolchains( + "buf_toolchains", + version = "v1.5.0", +) diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/WORKSPACE.out b/gazelle/buf/testdata/v2/imports_toolchain_name/WORKSPACE.out new file mode 100644 index 0000000..a866719 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/WORKSPACE.out @@ -0,0 +1,12 @@ +load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains") +load("//:buf_deps.bzl", "buf_deps") + +# gazelle:repository_macro buf_deps.bzl%buf_deps +buf_deps() + +rules_buf_dependencies() + +rules_buf_toolchains( + "buf_toolchains", + version = "v1.5.0", +) diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/barapis/bar/v1/bar.proto b/gazelle/buf/testdata/v2/imports_toolchain_name/barapis/bar/v1/bar.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/buf.lock b/gazelle/buf/testdata/v2/imports_toolchain_name/buf.lock new file mode 100644 index 0000000..84923a9 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/buf.lock @@ -0,0 +1,6 @@ +# Generated by buf. DO NOT EDIT. +version: v2 +deps: + - name: buf.build/envoyproxy/protoc-gen-validate + commit: dc09a417d27241f7b069feae2cd74a0e + digest: b5:63939effe0c64a94cd3151770b73007e43c9aeff31dcb24737fb11750dcaaca99338df3c1e5513828a685c743712e59ce283e046c27725e96928d200492bb6ec diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/buf.yaml b/gazelle/buf/testdata/v2/imports_toolchain_name/buf.yaml new file mode 100644 index 0000000..63b09c6 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/buf.yaml @@ -0,0 +1,20 @@ +version: v2 +modules: + - path: barapis + - path: fooapis + - path: petapis +deps: + - buf.build/envoyproxy/protoc-gen-validate +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/buf_deps.bzl.out b/gazelle/buf/testdata/v2/imports_toolchain_name/buf_deps.bzl.out new file mode 100644 index 0000000..a433966 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/buf_deps.bzl.out @@ -0,0 +1,10 @@ +load("@rules_buf//buf:defs.bzl", "buf_dependencies") + +def buf_deps(): + buf_dependencies( + name = "buf_deps", + modules = [ + "buf.build/envoyproxy/protoc-gen-validate:dc09a417d27241f7b069feae2cd74a0e", + ], + toolchain_repo = "buf_toolchains", + ) diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/fooapis/foo/v1/foo.proto b/gazelle/buf/testdata/v2/imports_toolchain_name/fooapis/foo/v1/foo.proto new file mode 100644 index 0000000..403aebb --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/fooapis/foo/v1/foo.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package foo.v1; + +message Foo {} diff --git a/gazelle/buf/testdata/v2/imports_toolchain_name/petapis/pets/v1/pets.proto b/gazelle/buf/testdata/v2/imports_toolchain_name/petapis/pets/v1/pets.proto new file mode 100644 index 0000000..3329c54 --- /dev/null +++ b/gazelle/buf/testdata/v2/imports_toolchain_name/petapis/pets/v1/pets.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package pets.v1; + +import "foo/v1/foo.proto"; +import "validate/validate.proto"; + +message Pet { + foo.v1.Foo foo = 1; +} diff --git a/gazelle/buf/testdata/v2/lint/BUILD.in b/gazelle/buf/testdata/v2/lint/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/lint/BUILD.out b/gazelle/buf/testdata/v2/lint/BUILD.out new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/lint/buf.yaml b/gazelle/buf/testdata/v2/lint/buf.yaml new file mode 100644 index 0000000..6fe9ec4 --- /dev/null +++ b/gazelle/buf/testdata/v2/lint/buf.yaml @@ -0,0 +1,14 @@ +version: v2 +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/lint/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/lint/foo/v1/BUILD.in new file mode 100644 index 0000000..dce0c73 --- /dev/null +++ b/gazelle/buf/testdata/v2/lint/foo/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/lint/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/lint/foo/v1/BUILD.out new file mode 100644 index 0000000..556d787 --- /dev/null +++ b/gazelle/buf/testdata/v2/lint/foo/v1/BUILD.out @@ -0,0 +1,14 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + config = "//:buf.yaml", + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/lint/foo/v1/foo.proto b/gazelle/buf/testdata/v2/lint/foo/v1/foo.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/merge/BUILD.in b/gazelle/buf/testdata/v2/merge/BUILD.in new file mode 100644 index 0000000..f64d8ce --- /dev/null +++ b/gazelle/buf/testdata/v2/merge/BUILD.in @@ -0,0 +1,2 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/merge/BUILD.out b/gazelle/buf/testdata/v2/merge/BUILD.out new file mode 100644 index 0000000..f64d8ce --- /dev/null +++ b/gazelle/buf/testdata/v2/merge/BUILD.out @@ -0,0 +1,2 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/merge/buf.yaml b/gazelle/buf/testdata/v2/merge/buf.yaml new file mode 100644 index 0000000..6fe9ec4 --- /dev/null +++ b/gazelle/buf/testdata/v2/merge/buf.yaml @@ -0,0 +1,14 @@ +version: v2 +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/merge/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/merge/foo/v1/BUILD.in new file mode 100644 index 0000000..32fc6cb --- /dev/null +++ b/gazelle/buf/testdata/v2/merge/foo/v1/BUILD.in @@ -0,0 +1,24 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + size = "small", + config = "//:buf.yaml", + targets = [":foo_proto"], +) + +buf_breaking_test( + name = "foo_proto_breaking", + size = "small", + against = "//:against_file", + config = "//:buf.yaml", + limit_to_input_files = True, + targets = [":foo_proto"], +) \ No newline at end of file diff --git a/gazelle/buf/testdata/v2/merge/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/merge/foo/v1/BUILD.out new file mode 100644 index 0000000..a8829e9 --- /dev/null +++ b/gazelle/buf/testdata/v2/merge/foo/v1/BUILD.out @@ -0,0 +1,24 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_proto_lint", + size = "small", + config = "//:buf.yaml", + targets = [":foo_proto"], +) + +buf_breaking_test( + name = "foo_proto_breaking", + size = "small", + against = "//:against_file", + config = "//:buf.yaml", + limit_to_input_files = True, + targets = [":foo_proto"], +) diff --git a/gazelle/buf/testdata/v2/merge/foo/v1/foo.proto b/gazelle/buf/testdata/v2/merge/foo/v1/foo.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/workspace/barapis/BUILD.in b/gazelle/buf/testdata/v2/workspace/barapis/BUILD.in new file mode 100644 index 0000000..da23603 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/barapis/BUILD.in @@ -0,0 +1,3 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package +# gazelle:proto_strip_import_prefix /barapis diff --git a/gazelle/buf/testdata/v2/workspace/barapis/BUILD.out b/gazelle/buf/testdata/v2/workspace/barapis/BUILD.out new file mode 100644 index 0000000..da23603 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/barapis/BUILD.out @@ -0,0 +1,3 @@ +# gazelle:buf_breaking_against //:against_file +# gazelle:buf_breaking_mode package +# gazelle:proto_strip_import_prefix /barapis diff --git a/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/BUILD.in b/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/BUILD.in new file mode 100644 index 0000000..d95a30d --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/BUILD.in @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + strip_import_prefix = "/barapis", + visibility = ["//visibility:public"], +) + diff --git a/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/BUILD.out b/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/BUILD.out new file mode 100644 index 0000000..aed1b98 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/BUILD.out @@ -0,0 +1,25 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test", "buf_lint_test") +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + strip_import_prefix = "/barapis", + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "bar_proto_lint", + config = "//:buf.yaml", + module = "barapis", + targets = [":bar_proto"], +) + +buf_breaking_test( + name = "bar_proto_breaking", + against = "//:against_file", + config = "//:buf.yaml", + limit_to_input_files = True, + module = "barapis", + targets = [":bar_proto"], +) diff --git a/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/bar.proto b/gazelle/buf/testdata/v2/workspace/barapis/bar/v1/bar.proto new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/workspace/buf.yaml b/gazelle/buf/testdata/v2/workspace/buf.yaml new file mode 100644 index 0000000..b8e8d51 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/buf.yaml @@ -0,0 +1,18 @@ +version: v2 +modules: + - path: barapis + - path: fooapis + - path: petapis +lint: + use: + - DEFAULT + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/gazelle/buf/testdata/v2/workspace/fooapis/BUILD.in b/gazelle/buf/testdata/v2/workspace/fooapis/BUILD.in new file mode 100644 index 0000000..c1d725b --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/fooapis/BUILD.in @@ -0,0 +1 @@ +# gazelle:buf_breaking_against //:against_file diff --git a/gazelle/buf/testdata/v2/workspace/fooapis/BUILD.out b/gazelle/buf/testdata/v2/workspace/fooapis/BUILD.out new file mode 100644 index 0000000..5b16619 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/fooapis/BUILD.out @@ -0,0 +1,11 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test") + +# gazelle:buf_breaking_against //:against_file + +buf_breaking_test( + name = "buf_breaking", + against = "//:against_file", + config = "//:buf.yaml", + module = "fooapis", + targets = ["//fooapis/foo/v1:foo_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/BUILD.in b/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/BUILD.out b/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/BUILD.out new file mode 100644 index 0000000..91fb131 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/BUILD.out @@ -0,0 +1,16 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "foo_v1_proto", + srcs = ["foo.proto"], + strip_import_prefix = "/fooapis", + visibility = ["//visibility:public"], +) + +buf_lint_test( + name = "foo_v1_proto_lint", + config = "//:buf.yaml", + module = "fooapis", + targets = [":foo_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/foo.proto b/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/foo.proto new file mode 100644 index 0000000..403aebb --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/fooapis/foo/v1/foo.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package foo.v1; + +message Foo {} diff --git a/gazelle/buf/testdata/v2/workspace/petapis/BUILD.in b/gazelle/buf/testdata/v2/workspace/petapis/BUILD.in new file mode 100644 index 0000000..c1d725b --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/petapis/BUILD.in @@ -0,0 +1 @@ +# gazelle:buf_breaking_against //:against_file diff --git a/gazelle/buf/testdata/v2/workspace/petapis/BUILD.out b/gazelle/buf/testdata/v2/workspace/petapis/BUILD.out new file mode 100644 index 0000000..a38cc63 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/petapis/BUILD.out @@ -0,0 +1,11 @@ +load("@rules_buf//buf:defs.bzl", "buf_breaking_test") + +# gazelle:buf_breaking_against //:against_file + +buf_breaking_test( + name = "buf_breaking", + against = "//:against_file", + config = "//:buf.yaml", + module = "petapis", + targets = ["//petapis/pets/v1:pets_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/BUILD.in b/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/BUILD.out b/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/BUILD.out new file mode 100644 index 0000000..4c6f8c3 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/BUILD.out @@ -0,0 +1,17 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_buf//buf:defs.bzl", "buf_lint_test") + +proto_library( + name = "pets_v1_proto", + srcs = ["pets.proto"], + strip_import_prefix = "/petapis", + visibility = ["//visibility:public"], + deps = ["//fooapis/foo/v1:foo_v1_proto"], +) + +buf_lint_test( + name = "pets_v1_proto_lint", + config = "//:buf.yaml", + module = "petapis", + targets = [":pets_v1_proto"], +) diff --git a/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/pets.proto b/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/pets.proto new file mode 100644 index 0000000..ba7c841 --- /dev/null +++ b/gazelle/buf/testdata/v2/workspace/petapis/pets/v1/pets.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package pets.v1; + +import "foo/v1/foo.proto"; + +message Pet { + foo.v1.Foo foo = 1; +} diff --git a/gazelle/buf/update.go b/gazelle/buf/update.go index 0b299be..f91ab1f 100644 --- a/gazelle/buf/update.go +++ b/gazelle/buf/update.go @@ -89,7 +89,18 @@ func bufLockImport(args language.ImportReposArgs) language.ImportReposResult { List: make([]build.Expr, 0, len(bufLock.Deps)), } for _, dep := range bufLock.Deps { - modules.List = append(modules.List, &build.StringExpr{Value: fmt.Sprintf("%s/%s/%s:%s", dep.Remote, dep.Owner, dep.Repository, dep.Commit)}) + var value string + if dep.Name != "" { // v2 + value = fmt.Sprintf("%s:%s", dep.Name, dep.Commit) + } else { + value = fmt.Sprintf("%s/%s/%s:%s", dep.Remote, dep.Owner, dep.Repository, dep.Commit) + } + modules.List = append( + modules.List, + &build.StringExpr{ + Value: value, + }, + ) } repoRule.SetAttr("modules", modules) addOptionalToolchainAttribute(args, repoRule)