Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look in call args for loadable symbols #1317

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions merger/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions merger/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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": {
Expand Down