Skip to content

Commit

Permalink
fix: change providers target to list and update testing please version (
Browse files Browse the repository at this point in the history
#128)

Co-authored-by: roulle_a <[email protected]>
  • Loading branch information
SkeneZr and roulle_a authored Nov 12, 2024
1 parent ea0c04d commit 988cf57
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
17 changes: 15 additions & 2 deletions e2e/tests/codegen/test_repo/codegen/BUILD_FILE.plz
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ filegroup(
name = "provider",
srcs = ["foo.proto"],
provides = {
"go": ":srcs",
"go": [":srcs"],
},
)

filegroup(
name = "recursive_provider",
srcs = ["foo.proto"],
provides = {
"go": ":provider",
"go": [":provider"],
},
)

filegroup(
name = "list_provider",
srcs = ["foo.proto"],
provides = {
"go": [":srcs", ":provider"],
},
)

Expand All @@ -40,4 +48,9 @@ go_binary(
go_binary(
name = "recursive_codegen_provider",
srcs = [":recursive_provider"],
)

go_binary(
name = "list_codegen_provider",
srcs = [":list_provider"],
)
4 changes: 2 additions & 2 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ func (e *Eval) BuildSources(plzPath, dir string, rule *build.Rule, srcsArg strin
ret = append(ret, src)
continue
}
target, err := please.RecursivelyProvide(plzPath, labels.ParseRelative(src, dir).Format(), "go")
targets, err := please.RecursivelyProvide(plzPath, labels.ParseRelative(src, dir).Format(), "go")
if err != nil {
return nil, err
}

outs, err := please.Build(plzPath, target)
outs, err := please.Build(plzPath, targets...)
if err != nil {
return nil, err
}
Expand Down
39 changes: 27 additions & 12 deletions please/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

// Build builds a target and returns the outputted files
func Build(plz, target string) ([]string, error) {
out, err := execPlease(plz, "build", "-p", target)
func Build(plz string, targets ...string) ([]string, error) {
out, err := execPlease(plz, append([]string{"build", "-p"}, targets...)...)
if err != nil {
return nil, err
}
Expand All @@ -17,31 +17,46 @@ func Build(plz, target string) ([]string, error) {

// RecursivelyProvide queries the target, checking if it provides a different target for the given requirement, and
// returns that, repeating the operation if that target also provides a different target.
func RecursivelyProvide(plz, target, requires string) (string, error) {
func RecursivelyProvide(plz string, target string, requires string) ([]string, error) {
out, err := execPlease(plz, "query", "print", "--json", "--field=provides", target)
if err != nil {
return "", err
return nil, err
}
// Returns a map of labels to fields. One of the fields in provides, which is a map of requests to targets, so we
// index res[target]["provides"][requires] to get the provided target
res := map[string]map[string]map[string]string{}
res := map[string]map[string]map[string][]string{}
if err := json.Unmarshal(out, &res); err != nil {
return "", err
return nil, err
}

t, ok := res[target]
if !ok {
return target, nil
return []string{target}, nil
}

provides, ok := t["provides"]
if !ok {
return target, nil
return []string{target}, nil
}

providedTargets := provides[requires]

if len(providedTargets) == 0 || (len(providedTargets) == 1 && providedTargets[0] == target) {
return []string{target}, nil
}

ret := provides[requires]
if ret == "" || ret == target {
return target, nil
ret := make([]string, 0, len(providedTargets))
for _, providedTarget := range providedTargets {
if providedTarget == target {
ret = append(ret, providedTarget) // Providing itself, don't recurse
} else {
r, err := RecursivelyProvide(plz, providedTarget, requires)
if err != nil {
return []string{}, err
}
ret = append(ret, r...)
}
}
return RecursivelyProvide(plz, ret, requires)

return ret, nil
}
2 changes: 1 addition & 1 deletion third_party/binary/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ remote_file(
name = "plz",
binary = True,
test_only = True,
url = f"https://github.com/thought-machine/please/releases/download/v17.3.1/please_17.3.1_{CONFIG.OS}_{CONFIG.ARCH}",
url = f"https://github.com/thought-machine/please/releases/download/v17.11.0/please_17.11.0_{CONFIG.OS}_{CONFIG.ARCH}",
visibility = ["PUBLIC"],
)

0 comments on commit 988cf57

Please sign in to comment.