Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ed082f6 authored by Jingwen Chen's avatar Jingwen Chen
Browse files

Fix b with zsh.

zsh doesn't do string splitting like bash, so it passes the
post-processed bazel args to bazel as a single arg. So this CL adds a
conditional to do the splitting correctly for zsh with `setopt
shwordsplit`.

Reference: https://zsh.sourceforge.io/FAQ/zshfaq03.html

For bash, this uses array[@] to split the list into separate
shell words.

Test: zsh; source build/envsetup.sh && b test
//system/logging/logd:logd-unit-tests --config=linux_x86_64
Test: bash; source build/envsetup.sh && b test
//system/logging/logd:logd-unit-tests --config=linux_x86_64

Change-Id: I4e19a062b7f7e119b1612a8ce5c801878378cc69
parent 46ee66c0
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -1866,20 +1866,29 @@ function b()
        # 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 config_set=0
        local bazel_args_with_config=""

        # Represent the args as an array, not a string.
        local bazel_args_with_config=()
        for arg in $bazel_args; do
            if [[ $arg == "--" && $config_set -ne 1 ]]; # if we find --, insert config argument here
            then
                bazel_args_with_config+="--config=bp2build -- "
                bazel_args_with_config+=("--config=bp2build -- ")
                config_set=1
            else
                bazel_args_with_config+="$arg "
                bazel_args_with_config+=("$arg ")
            fi
        done
        if [[ $config_set -ne 1 ]]; then
            bazel_args_with_config+="--config=bp2build "
            bazel_args_with_config+=("--config=bp2build ")
        fi

        if [ -n "$ZSH_VERSION" ]; then
          # zsh breaks posix by not doing string-splitting on unquoted args
          # by default. Enable the compatibility option.
          setopt shwordsplit
        fi
        bazel $bazel_args_with_config
        # Call Bazel.
        bazel ${bazel_args_with_config[@]}
    fi
)