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