genrule: add $(location) for inputs and outputs
There was no way to select a single source file from a genrule that
has multiple source files. Make Soong's genrule closer to Bazel
by supporting $(location) for input and outputs. Change the
label used for tools referenced through filegroups to the name
of the module instead of the name of the file, which means it
matches the string used in the tools property.
Also support :module format in the tools property in preparation
for deprecating the tool_files property and putting both files
and modules in the tools property.
Bug: 117354232
Test: genrule_test.go
Change-Id: Id31a4ac4ff7064076a576c1d8ffeb7c19fc6b9a4
Merged-In: Id31a4ac4ff7064076a576c1d8ffeb7c19fc6b9a4
(cherry picked from commit 098d22b5f6d965872b524ce798ce728580ce405c)
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 0d690d4..7e16ce1 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -133,6 +133,15 @@
expect: "out/tool > __SBOX_OUT_FILES__",
},
{
+ name: "empty location tool2",
+ prop: `
+ tools: [":tool"],
+ out: ["out"],
+ cmd: "$(location) > $(out)",
+ `,
+ expect: "out/tool > __SBOX_OUT_FILES__",
+ },
+ {
name: "empty location tool file",
prop: `
tool_files: ["tool_file1"],
@@ -170,6 +179,15 @@
expect: "out/tool > __SBOX_OUT_FILES__",
},
{
+ name: "tool2",
+ prop: `
+ tools: [":tool"],
+ out: ["out"],
+ cmd: "$(location :tool) > $(out)",
+ `,
+ expect: "out/tool > __SBOX_OUT_FILES__",
+ },
+ {
name: "tool file",
prop: `
tool_files: ["tool_file1"],
@@ -183,7 +201,7 @@
prop: `
tool_files: [":1tool_file"],
out: ["out"],
- cmd: "$(location tool_file1) > $(out)",
+ cmd: "$(location :1tool_file) > $(out)",
`,
expect: "tool_file1 > __SBOX_OUT_FILES__",
},
@@ -192,7 +210,7 @@
prop: `
tool_files: [":tool_files"],
out: ["out"],
- cmd: "$(location tool_file1) $(location tool_file2) > $(out)",
+ cmd: "$(locations :tool_files) > $(out)",
`,
expect: "tool_file1 tool_file2 > __SBOX_OUT_FILES__",
},
@@ -233,6 +251,42 @@
expect: "cat ${in} > __SBOX_OUT_FILES__",
},
{
+ name: "location in1",
+ prop: `
+ srcs: ["in1"],
+ out: ["out"],
+ cmd: "cat $(location in1) > $(out)",
+ `,
+ expect: "cat in1 > __SBOX_OUT_FILES__",
+ },
+ {
+ name: "location in1 fg",
+ prop: `
+ srcs: [":1in"],
+ out: ["out"],
+ cmd: "cat $(location :1in) > $(out)",
+ `,
+ expect: "cat in1 > __SBOX_OUT_FILES__",
+ },
+ {
+ name: "location ins",
+ prop: `
+ srcs: ["in1", "in2"],
+ out: ["out"],
+ cmd: "cat $(location in1) > $(out)",
+ `,
+ expect: "cat in1 > __SBOX_OUT_FILES__",
+ },
+ {
+ name: "location ins fg",
+ prop: `
+ srcs: [":ins"],
+ out: ["out"],
+ cmd: "cat $(locations :ins) > $(out)",
+ `,
+ expect: "cat in1 in2 > __SBOX_OUT_FILES__",
+ },
+ {
name: "outs",
prop: `
out: ["out", "out2"],
@@ -241,6 +295,14 @@
expect: "echo foo > __SBOX_OUT_FILES__",
},
{
+ name: "location out",
+ prop: `
+ out: ["out", "out2"],
+ cmd: "echo foo > $(location out2)",
+ `,
+ expect: "echo foo > __SBOX_OUT_DIR__/out2",
+ },
+ {
name: "depfile",
prop: `
out: ["out"],
@@ -267,6 +329,24 @@
err: "at least one `tools` or `tool_files` is required if $(location) is used",
},
{
+ name: "error empty location no files",
+ prop: `
+ tool_files: [":empty"],
+ out: ["out"],
+ cmd: "$(location) > $(out)",
+ `,
+ err: `default label ":empty" has no files`,
+ },
+ {
+ name: "error empty location multiple files",
+ prop: `
+ tool_files: [":tool_files"],
+ out: ["out"],
+ cmd: "$(location) > $(out)",
+ `,
+ err: `default label ":tool_files" has multiple files`,
+ },
+ {
name: "error location",
prop: `
out: ["out"],
@@ -275,6 +355,41 @@
err: `unknown location label "missing"`,
},
{
+ name: "error locations",
+ prop: `
+ out: ["out"],
+ cmd: "echo foo > $(locations missing)",
+ `,
+ err: `unknown locations label "missing"`,
+ },
+ {
+ name: "error location no files",
+ prop: `
+ out: ["out"],
+ srcs: [":empty"],
+ cmd: "echo $(location :empty) > $(out)",
+ `,
+ err: `label ":empty" has no files`,
+ },
+ {
+ name: "error locations no files",
+ prop: `
+ out: ["out"],
+ srcs: [":empty"],
+ cmd: "echo $(locations :empty) > $(out)",
+ `,
+ err: `label ":empty" has no files`,
+ },
+ {
+ name: "error location multiple files",
+ prop: `
+ out: ["out"],
+ srcs: [":ins"],
+ cmd: "echo $(location :ins) > $(out)",
+ `,
+ err: `label ":ins" has multiple files`,
+ },
+ {
name: "error variable",
prop: `
out: ["out"],