From e31d7de7b072db42caa0bc3bfd88ef1f373a6f55 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Mon, 29 Aug 2022 17:39:44 -0400 Subject: [PATCH 1/2] 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 ) From e4c74c5eefe0b14d03812bf64a49d38ff59a4413 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Tue, 30 Aug 2022 10:17:38 -0400 Subject: [PATCH 2/2] skip soong tests by default for b command It doesn't really make sense to incur the cost of running Soong tests to Bazel users. We can shave off 20 seconds from the local critical path during clean builds (or if Soong itself has changed) by enabling --skip-soong-tests in the b command. Test: b build '...' Test: b build '...' --run-soong-tests Bug: 240231596 Change-Id: I2325e1992099534b41ae996cee99e126a12f3c62 --- envsetup.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/envsetup.sh b/envsetup.sh index 2d670c4001..550dca86bb 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -1838,10 +1838,20 @@ function _trigger_build() # Convenience entry point (like m) to use Bazel in AOSP. function b() ( + # Look for the --run-soong-tests flag and skip passing --skip-soong-tests to Soong if present + local bazel_args="" + local skip_tests="--skip-soong-tests" + for i in $@; do + if [[ $i != "--run-soong-tests" ]]; then + bazel_args+="$i " + else + skip_tests="" + fi + done # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace). _trigger_build "all-modules" bp2build USE_BAZEL_ANALYSIS= || return 1 # Then, run Bazel using the synthetic workspace as the --package_path. - if [[ -z "$@" ]]; then + if [[ -z "$bazel_args" ]]; then # If there are no args, show help. bazel help else @@ -1851,7 +1861,7 @@ function b() # b run //foo -- --args-for-foo local config_set=0 local bazel_args_with_config="" - for arg in $@; do + 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 -- "