#!/bin/bash -e # Copyright (C) 2022 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Common script utilities source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../lib.sh require_top # Look for the --run-soong-tests flag and skip passing --skip-soong-tests to Soong if present bazel_args="" 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). # RBE is disabled because it's not used with b builds and adds overhead: b/251441524 # TODO(b/262904551) - this is Darwin incompatible and should eventually be updated. BUILD_STARTED_TIME=`date +%s%3N` B_ARGS=$* set +e "$TOP/build/soong/soong_ui.bash" --build-mode --all-modules --dir="$(pwd)" $skip_tests bp2build USE_BAZEL_ANALYSIS= --build-command="b ${B_ARGS}" --skip-metrics-upload --build-started-time-unix-millis=$BUILD_STARTED_TIME exit_code=$? if [[ $exit_code -ne 0 ]]; then exit $exit_code fi set -e # Then, run Bazel using the synthetic workspace as the --package_path. if [[ -z "$bazel_args" ]]; then # If there are no args, show help and exit. "$TOP/build/bazel/bin/bazel" help else PROFILE_OUT=$(get_profile_out_dir) mkdir -p $PROFILE_OUT bazel_args_with_config=$(formulate_b_args $bazel_args) # Call Bazel. set +e "$TOP/build/bazel/bin/bazel" ${bazel_args_with_config[@]} bazel_exit_code=$? set -e bazel_exit_code_string="--bazel-exit-code=$bazel_exit_code" "$TOP/build/bazel/bin/bazel" analyze-profile $PROFILE_OUT/bazel_metrics-profile 1> $PROFILE_OUT/analyzed_bazel_profile.txt 2>/dev/null rm $PROFILE_OUT/bazel_metrics-profile exit $bazel_exit_code fi