1#!/bin/bash -eu
2#
3# Compares Android-TARGET.mk files generated by the mixed build
4# against the same file generated by the reference build.
5# This is the wrapper around build/bazel/mkcompare tool
6# Usage:
7#  mkmodules_diff [--bazel-mode-staging] <mkcompare_option> ...
8# Android-TARGET.mk files that are compared are for the product
9# defined by the TARGET_PRODUCT and TARGET_BUILD_VARIANT environment
10# variables.
11# Without --bazel-mode-staging option, the mixed build is run with
12# --bazel-mode-dev option.
13# The output can be safely redirected to a file, it does not include
14# the noise from the build.
15
16trap 'printf "FAILED: $BASH_COMMAND (rc=%s)\n" $? >&2' ERR
17declare -r builder=build/soong/soong_ui.bash
18[[ -x ${builder} ]] || \
19  { echo "current directory should be the root of the Android source tree"; exit 1; }
20export ANDROID_QUIET_BUILD=yes
21declare -a mkargs
22declare bazel_mode=--bazel-mode-dev
23for a in $@; do
24  if [[ "$a" =~ ^--bazel-mode ]]; then
25    bazel_mode="$a"
26  else
27    mkargs+=("$a")
28  fi
29done
30declare -r mkmod_file="out/soong/Android-${TARGET_PRODUCT?TARGET_PRODUCT not set}.mk"
31${builder} --make-mode nothing >/dev/null
32mv ${mkmod_file} ${mkmod_file}.ref
33${builder} --make-mode "${bazel_mode}"  nothing >/dev/null
34GOWORK=$PWD/build/bazel/mkcompare/go.work \
35  go run android/bazel/mkcompare/cmd ${mkargs[@]} ${mkmod_file}.ref ${mkmod_file}
36