Keep legacy location tests explicit (#646) Buildifier rejects the tests’ uses of `$(location)` and `$(locations)` [1]. Use `$(execpath)` where a command needs the path to an input or output. The `native_binary` and `run_binary` tests also cover legacy substitution, quoting, and escaping. Leave those expressions in place and exempt just those lines from the lint. Codex for Tamir. [1]: https://buildkite.com/bazel/bazel-skylib/builds/4636#01a17582-8e68-4941-8c9b-a39d81cdf72f
diff --git a/tests/copy_file/BUILD b/tests/copy_file/BUILD index 53b67ef..ace8071 100644 --- a/tests/copy_file/BUILD +++ b/tests/copy_file/BUILD
@@ -77,10 +77,10 @@ "xgen-out.txt", ], cmd = " && ".join([ - "$(location :bin_src_symlink) > $(location xsrc-out-symlink.txt)", - "$(location :bin_gen_symlink) > $(location xgen-out-symlink.txt)", - "$(location :bin_src) > $(location xsrc-out.txt)", - "$(location :bin_gen) > $(location xgen-out.txt)", + "$(execpath :bin_src_symlink) > $(execpath xsrc-out-symlink.txt)", + "$(execpath :bin_gen_symlink) > $(execpath xgen-out-symlink.txt)", + "$(execpath :bin_src) > $(execpath xsrc-out.txt)", + "$(execpath :bin_gen) > $(execpath xgen-out.txt)", ]), output_to_bindir = 1, tools = [
diff --git a/tests/diff_test/BUILD b/tests/diff_test/BUILD index 00b9a46..8ea20bc 100644 --- a/tests/diff_test/BUILD +++ b/tests/diff_test/BUILD
@@ -46,5 +46,5 @@ "a-gen.txt", "aa-gen.txt", ], - cmd = "echo -n 'potato' > $(location a-gen.txt) && echo -n 'potato' > $(location aa-gen.txt)", + cmd = "echo -n 'potato' > $(execpath a-gen.txt) && echo -n 'potato' > $(execpath aa-gen.txt)", )
diff --git a/tests/native_binary/BUILD b/tests/native_binary/BUILD index f0162d8..2389169 100644 --- a/tests/native_binary/BUILD +++ b/tests/native_binary/BUILD
@@ -72,11 +72,12 @@ is_executable = True, ) +# Preserve legacy location expansion and quoting alongside escaped literals. _ARGS = [ "'a b'", "c\\ d", - "$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)", - "'$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)'", + "$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)", # buildifier: disable=make-location + "'$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)'", # buildifier: disable=make-location "$$TEST_SRCDIR", "$${TEST_SRCDIR}", ]
diff --git a/tests/run_binary/BUILD b/tests/run_binary/BUILD index 6c1858d..2c1679c 100644 --- a/tests/run_binary/BUILD +++ b/tests/run_binary/BUILD
@@ -61,11 +61,11 @@ # Testing $(location) expansion only on source files so the result is # predictable. The path of generated files depends on the target # platform. - "ENV_LOCATION": "a $(location BUILD)", - "ENV_LOCATIONS": "b\\ $(locations :dummy_srcs)", + "ENV_LOCATION": "a $(location BUILD)", # buildifier: disable=make-location + "ENV_LOCATIONS": "b\\ $(locations :dummy_srcs)", # buildifier: disable=make-location "ENV_PATH_BASH": "$PATH", "ENV_PATH_CMD": "%PATH%", - "OUT": "$(location run_script.out)", + "OUT": "$(execpath run_script.out)", }, tool = ":script", ) @@ -157,9 +157,9 @@ "$(execpaths :dummy_srcs)", "'$(execpath BUILD) $$(execpath BUILD)'", # Test the legacy 'location' expansions - "$(location BUILD)", - "$(locations :dummy_srcs)", - "'$(location BUILD) $$(location BUILD)'", + "$(location BUILD)", # buildifier: disable=make-location + "$(locations :dummy_srcs)", # buildifier: disable=make-location + "'$(location BUILD) $$(location BUILD)'", # buildifier: disable=make-location "$PATH", "$$PATH", "${PATH}", @@ -167,7 +167,7 @@ ], # Not testing any complex envvars here, because we already did in # "run_script". - env = {"OUT": "$(location run_bin.out)"}, + env = {"OUT": "$(execpath run_bin.out)"}, tool = ":printargs", )
diff --git a/tests/write_file/BUILD b/tests/write_file/BUILD index 794a100..c4bde0b 100644 --- a/tests/write_file/BUILD +++ b/tests/write_file/BUILD
@@ -72,8 +72,8 @@ "empty-bin-out.txt", "nonempty-bin-out.txt", ], - cmd = ("$(location :bin_empty) > $(location empty-bin-out.txt) && " + - "$(location :bin_nonempty) > $(location nonempty-bin-out.txt)"), + cmd = ("$(execpath :bin_empty) > $(execpath empty-bin-out.txt) && " + + "$(execpath :bin_nonempty) > $(execpath nonempty-bin-out.txt)"), output_to_bindir = 1, tools = [ ":bin_empty",