From e31d7de7b072db42caa0bc3bfd88ef1f373a6f55 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Mon, 29 Aug 2022 17:39:44 -0400 Subject: [PATCH] insert --config=bp2build before -- in b args Bazel also supports `--foo bar` as another way to mean `--foo=bar`, The current implementation would accidentally catch that and make it `--foo --config=bp2build bar`. This CL instead requires that additional arguments to the target come after a `--`. E.g. ``` b run --args-for-bazel //foo -- --args-for-foo ``` Test: b build //build/bazel/scripts/difftool:difftool Test: b run //build/bazel/scripts/difftool/difftool.py --level=FINE /tmp/legacyBuildFiles /tmp/bazelBuildFiles --file_type=object Change-Id: I534caab04e4c919d4e7b6dc83b8a88e020626b18 --- envsetup.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/envsetup.sh b/envsetup.sh index 3a04451e48..2d670c4001 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -1849,17 +1849,21 @@ function b() # Add the --config=bp2build after the first argument that doesn't start with a dash. That should be the bazel # command. (build, test, run, ect) If the --config was added at the end, it wouldn't work with commands like: # b run //foo -- --args-for-foo - local previous_args="" - for arg in $@; - do - previous_args+="$arg " - shift - if [[ $arg != -* ]]; # if $arg doesn't start with a dash + local config_set=0 + local bazel_args_with_config="" + for arg in $@; do + if [[ $arg == "--" && $config_set -ne 1 ]]; # if we find --, insert config argument here then - break + bazel_args_with_config+="--config=bp2build -- " + config_set=1 + else + bazel_args_with_config+="$arg " fi done - bazel $previous_args --config=bp2build $@ + if [[ $config_set -ne 1 ]]; then + bazel_args_with_config+="--config=bp2build " + fi + eval "bazel $bazel_args_with_config" fi )