diff --git a/merger/fix.go b/merger/fix.go index 128050c73..e73f50e04 100644 --- a/merger/fix.go +++ b/merger/fix.go @@ -65,20 +65,30 @@ func FixLoads(f *rule.File, knownLoads []rule.LoadInfo) { return } - id, ok := ce.X.(*bzl.Ident) + functionIdent, ok := ce.X.(*bzl.Ident) if !ok { return } - file, ok := knownSymbols[id.Name] - if !ok || otherLoadedKinds[id.Name] { - return + idents := []*bzl.Ident{functionIdent} + + for _, arg := range ce.List { + if argIdent, ok := arg.(*bzl.Ident); ok { + idents = append(idents, argIdent) + } } - if usedSymbols[file] == nil { - usedSymbols[file] = make(map[string]bool) + for _, id := range idents { + file, ok := knownSymbols[id.Name] + if !ok || otherLoadedKinds[id.Name] { + continue + } + + if usedSymbols[file] == nil { + usedSymbols[file] = make(map[string]bool) + } + usedSymbols[file][id.Name] = true } - usedSymbols[file][id.Name] = true }) // Fix the load statements. The order is important, so we iterate over diff --git a/merger/fix_test.go b/merger/fix_test.go index def5ca210..61d938ea7 100644 --- a/merger/fix_test.go +++ b/merger/fix_test.go @@ -41,6 +41,12 @@ func TestFixLoads(t *testing.T) { "foo_test", }, }, + { + Name: "@bazel_tools//tools/build_defs/repo:utils.bzl", + Symbols: []string{ + "maybe", + }, + }, } type testCase struct { @@ -153,6 +159,21 @@ foo_library(name = "a_lib") foo_binary(name = "a") foo_library(name = "a_lib") +`, + }, + "missing wrapper and wrapped kind load symbol": { + input: `maybe( + foo_binary, + name = "a", +) +`, + want: `load("@foo", "foo_binary") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +maybe( + foo_binary, + name = "a", +) `, }, "unused kind load symbol": {