bp2build: support genrule $(location) and $(locations)
Soong genrules support $(location) and $(locations) cmd variable
shortcuts without labels. The shortcut is for the location of the first
tool module from the concatenation of the tools and tool_files
properties.
Bazel doesn't support this shortcut, so the bp2build mapping needs to
support it.
Documentation:
https://cs.android.com/android/platform/superproject/+/master:build/soong/genrule/genrule.go;l=95-96;drc=316e07c593ab66599c74725cf482dedbb32b2875
Code: https://cs.android.com/android/platform/superproject/+/master:build/soong/genrule/genrule.go;l=236-246;drc=316e07c593ab66599c74725cf482dedbb32b2875
Test: build_conversion_test.go
Test: TH
Change-Id: I8aa98ae460af3a3fbb0a7835572518680dc7ade1
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 1f47dec..66e5652 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -797,12 +797,19 @@
func bp2buildMutator(ctx android.TopDownMutatorContext) {
if m, ok := ctx.Module().(*Module); ok {
name := "__bp2build__" + m.Name()
+ // Bazel only has the "tools" attribute.
+ tools := append(m.properties.Tools, m.properties.Tool_files...)
+
// Replace in and out variables with $< and $@
var cmd string
if m.properties.Cmd != nil {
cmd = strings.Replace(*m.properties.Cmd, "$(in)", "$(SRCS)", -1)
cmd = strings.Replace(cmd, "$(out)", "$(OUTS)", -1)
cmd = strings.Replace(cmd, "$(genDir)", "$(GENDIR)", -1)
+ if len(tools) > 0 {
+ cmd = strings.Replace(cmd, "$(location)", fmt.Sprintf("$(location %s)", tools[0]), -1)
+ cmd = strings.Replace(cmd, "$(locations)", fmt.Sprintf("$(locations %s)", tools[0]), -1)
+ }
}
// The Out prop is not in an immediately accessible field
@@ -816,9 +823,6 @@
}
}
- // Bazel only has the "tools" attribute.
- tools := append(m.properties.Tools, m.properties.Tool_files...)
-
// Create the BazelTargetModule.
ctx.CreateModule(BazelGenruleFactory, &bazelGenruleAttributes{
Name: proptools.StringPtr(name),