From bfa114d05b0d325ad46b479320dc23d63985c6a1 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Thu, 17 Jun 2021 05:42:43 +0000 Subject: [PATCH] Direct Bazel builds from m. This CL extends the `m` function to short circuit to Bazel iff: 1) USE_BAZEL_ANALYSIS is set to 1 or true 2) There is only 1 Soong module requested to be built 3) The Soong module has a corresponding Bazel alias target in @soong_injection//targets/BUILD to the real target in out/soong/workspace. Test: TH Change-Id: I976ffa53106c0b52c75b71f1e0e1e8b3ef5cb3d1 --- envsetup.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/envsetup.sh b/envsetup.sh index c6151559c4..4f9440e9fb 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -1700,19 +1700,27 @@ function _trigger_build() function b() ( # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace). - m nothing GENERATE_BAZEL_FILES=true || return 1 + _trigger_build "all-modules" nothing GENERATE_BAZEL_FILES=true USE_BAZEL_ANALYSIS= || return 1 # Then, run Bazel using the synthetic workspace as the --package_path. if [[ -z "$@" ]]; then # If there are no args, show help. - "$(gettop)/tools/bazel" help + bazel help else # Else, always run with the bp2build configuration, which sets Bazel's package path to the synthetic workspace. - "$(gettop)/tools/bazel" "$@" --config=bp2build + bazel "$@" --config=bp2build fi ) function m() ( + if [[ "${USE_BAZEL_ANALYSIS}" =~ ^(true|1)$ ]]; then + # This only short-circuits to Bazel for a single module target now. + b cquery "@soong_injection//module_name_to_label:$@" 2>/dev/null + if [[ $? == 0 ]]; then + bazel build "@soong_injection//module_name_to_label:$@" --config=bp2build + return $? + fi + fi _trigger_build "all-modules" "$@" )