Skip to content

Commit

Permalink
Only embed go_proto_library targets with matching importpath
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromep-stripe committed Mar 14, 2024
1 parent c37d146 commit 7452881
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions language/go/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ func (gl *goLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
protoTargets := importPathToProtoTargets[importPath]
protoEmbed, rs = g.generateProto(pcMode, protoTargets, importPath)
if protoEmbed != "" {
protoEmbeds = append(protoEmbeds, protoEmbed)
// check if rs is non-empty and that the first rule is a go_proto_library with the same importPath
if len(rs) > 0 && rs[0].Kind() == "go_proto_library" && rs[0].AttrString("importpath") == pkg.importPath {
protoEmbeds = append(protoEmbeds, protoEmbed)
}
}
rules = append(rules, rs...)
}
Expand All @@ -239,7 +242,10 @@ func (gl *goLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
}
protoEmbed, rs = g.generateProto(pcMode, []protoTarget{pkg.proto}, pkg.importPath)
if protoEmbed != "" {
protoEmbeds = append(protoEmbeds, protoEmbed)
// check if rs is non-empty and that the first rule is a go_proto_library with the same importPath
if len(rs) > 0 && rs[0].Kind() == "go_proto_library" && rs[0].AttrString("importpath") == pkg.importPath {
protoEmbeds = append(protoEmbeds, protoEmbed)
}
}
} else {
target := protoTargetFromProtoPackage(name, ppkg)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
Expand Down Expand Up @@ -55,3 +56,12 @@ go_proto_library(
proto = ":foo_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "multiple_go_packages",
srcs = ["gofile.go"],
_gazelle_imports = [],
embed = [":baz_go_proto"],
importpath = "example.com/repo/proto_file_mode/multiple_go_packages",
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package multiple_go_packages

0 comments on commit 7452881

Please sign in to comment.