Make the bash completion generation easier to customize per product, take 2.
Refactor the code to generate the bash completions file by moving the
logic to a separate script and keeping the genrule as a dumb invocation
of this script. This allows us to more easily customize the rules
for Blaze.
--
PiperOrigin-RevId: 146362379
MOS_MIGRATED_REVID=146362379
diff --git a/scripts/BUILD b/scripts/BUILD
index decf702..7c782cc 100644
--- a/scripts/BUILD
+++ b/scripts/BUILD
@@ -8,15 +8,16 @@
name = "bash_completion",
srcs = ["bazel-complete-template.bash"],
outs = ["bazel-complete.bash"],
- cmd = "cat $(SRCS) > $@\n" +
- "touch err.log\n" +
- "TMP=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX`\n" +
- "trap \"rm -fr err.log $${TMP}\" EXIT\n" +
- "$(location //src:bazel) " +
- " --batch --output_user_root=$${TMP} --host_javabase=$(JAVABASE) " +
- " help completion 2>err.log >>$@ || { cat err.log; exit 1; }",
+ cmd = " ".join([
+ "$(location :generate_bash_completion.sh)",
+ "--bazel=$(location //src:bazel)",
+ "--javabase=$(JAVABASE)",
+ "--output=$@",
+ "--prepend=$(location bazel-complete-template.bash)",
+ ]),
output_to_bindir = 1,
tools = [
+ ":generate_bash_completion.sh",
"//src:bazel",
"//tools/defaults:jdk",
],