diff --git a/cmd/gazelle/integration_test.go b/cmd/gazelle/integration_test.go index ff8ec12d0..ea0be886b 100644 --- a/cmd/gazelle/integration_test.go +++ b/cmd/gazelle/integration_test.go @@ -2975,72 +2975,3 @@ go_repository( }, }) } - -func TestMatchProtoLibrary(t *testing.T) { - files := []testtools.FileSpec{ - { - Path: "WORKSPACE", - }, - { - Path: "proto/BUILD.bazel", - Content: ` -load("@rules_proto//proto:defs.bzl", "proto_library") -# gazelle:prefix example.com/foo - -some_rule( - name = "gen_proto", - out = "foo.proto", -) - -proto_library( - name = "existing_proto", - srcs = ["foo.proto"], -) -`, - }, - } - dir, cleanup := testtools.CreateFiles(t, files) - defer cleanup() - - args := []string{"update"} - if err := runGazelle(dir, args); err != nil { - t.Fatal(err) - } - - testtools.CheckFiles(t, dir, []testtools.FileSpec{ - { - Path: "proto/BUILD.bazel", - Content: ` -load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") -# gazelle:prefix example.com/foo - -some_rule( - name = "gen_proto", - out = "foo.proto", -) - -proto_library( - name = "existing_proto", - srcs = ["foo.proto"], - visibility = ["//visibility:public"], -) - -go_proto_library( - name = "proto_go_proto", - importpath = "example.com/foo", - proto = ":existing_proto", - visibility = ["//visibility:public"], -) - -go_library( - name = "go_default_library", - embed = [":proto_go_proto"], - importpath = "example.com/foo", - visibility = ["//visibility:public"], -) -`, - }, - }) -} diff --git a/language/proto/kinds.go b/language/proto/kinds.go index aef1518e2..d4d9c0179 100644 --- a/language/proto/kinds.go +++ b/language/proto/kinds.go @@ -19,7 +19,6 @@ import "github.com/bazelbuild/bazel-gazelle/rule" var protoKinds = map[string]rule.KindInfo{ "proto_library": { - MatchAttrs: []string{"srcs"}, NonEmptyAttrs: map[string]bool{"srcs": true}, MergeableAttrs: map[string]bool{ "srcs": true, diff --git a/merger/merger.go b/merger/merger.go index dbd2fb23b..7993eba07 100644 --- a/merger/merger.go +++ b/merger/merger.go @@ -38,7 +38,6 @@ package merger import ( "fmt" - "sort" "strings" "github.com/bazelbuild/bazel-gazelle/rule" @@ -223,15 +222,19 @@ func Match(rules []*rule.Rule, x *rule.Rule, info rule.KindInfo) (*rule.Rule, er for _, key := range info.MatchAttrs { var attrMatches []*rule.Rule + xvalue := x.AttrString(key) + if xvalue == "" { + continue + } for _, y := range kindMatches { - if attrMatch(x, y, key) { + if xvalue == y.AttrString(key) { attrMatches = append(attrMatches, y) } } if len(attrMatches) == 1 { return attrMatches[0], nil } else if len(attrMatches) > 1 { - return nil, fmt.Errorf("could not merge %s(%s): multiple rules have the same attribute %s", xkind, xname, key) + return nil, fmt.Errorf("could not merge %s(%s): multiple rules have the same attribute %s = %q", xkind, xname, key, xvalue) } } @@ -245,23 +248,3 @@ func Match(rules []*rule.Rule, x *rule.Rule, info rule.KindInfo) (*rule.Rule, er return nil, nil } - -func attrMatch(x, y *rule.Rule, key string) bool { - xValue := x.AttrString(key) - if xValue != "" && xValue == y.AttrString(key) { - return true - } - xValues := x.AttrStrings(key) - yValues := y.AttrStrings(key) - if xValues == nil || yValues == nil || len(xValues) != len(yValues) { - return false - } - sort.Strings(xValues) - sort.Strings(yValues) - for i, v := range xValues { - if v != yValues[i] { - return false - } - } - return true -} diff --git a/merger/merger_test.go b/merger/merger_test.go index 4af976577..658b8d2dc 100644 --- a/merger/merger_test.go +++ b/merger/merger_test.go @@ -969,15 +969,6 @@ go_binary(name = "y") go_binary(name = "z") `, wantError: true, - }, { - desc: "srcs match", - gen: `proto_library(name = "proto1", srcs = ["foo.proto", "bar.proto"])`, - old: `proto_library(name = "proto2", srcs = ["bar.proto", "foo.proto"])`, - wantIndex: 0, - }, { - desc: "importpath match", - gen: `go_proto_library(name = "go_proto1", importpath="example.com/foo")`, - old: `go_proto_library(name = "go_proto2", importpath="example.com/foo")`, }, } { t.Run(tc.desc, func(t *testing.T) {