1#!/bin/bash
2
3set -e
4
5PROGNAME="$0"
6
7function usage {
8  cat <<EOF
9Usage:
10    ${PROGNAME} [OPTION] ... "[Args for compare_images]"
11
12Options:
13    -h, --help
14        Show this message and exit.
15    -c, --check
16        Exit with a non-zero status if there is any unexpected diffs.
17EOF
18}
19
20while [[ "$1" =~ ^- ]] && [[ "$1" != "--" ]]; do
21  case "$1" in
22    -h | --help)
23      usage
24      exit 0
25      ;;
26    -c | --check)
27      CHECK_DIFF_RESULT=1
28      ;;
29    *)
30      break
31      ;;
32  esac
33  shift
34done
35if [ "$1" == "--" ]; then
36  shift
37fi
38
39readonly CHECK_DIFF_RESULT
40
41. build/envsetup.sh
42lunch aosp_arm64
43build/soong/soong_ui.bash --make-mode compare_images
44COMMON_ALLOWLIST=development/vndk/tools/image-diff-tool/allowlist.txt
45out/host/linux-x86/bin/compare_images $1 -u -w "${COMMON_ALLOWLIST}"
46
47if [ -v DIST_DIR ]; then
48  cp common.csv diff.csv allowlisted_diff.csv "${DIST_DIR}"
49fi
50
51echo >&2
52echo >&2 " - Different parts (that are allowlisted)"
53cat >&2 allowlisted_diff.csv
54echo >&2
55echo >&2 " - Different parts (that are not allowlisted)"
56cat >&2 diff.csv
57
58if [ "$(wc -l diff.csv | cut -d' ' -f1)" -gt "1" ]; then
59  cat >&2 <<EOF
60
61[ERROR] Unexpected diffing files.
62There are diffing files that are not ignored by allowlist.
63The allowlist may need to be updated.
64EOF
65  if [ -n "${CHECK_DIFF_RESULT}" ]; then
66    exit 1
67  fi
68fi
69