• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# checks the diff between legacy Soong built artifacts and their counterparts
3# built with bazel/mixed build
4export TARGET_PRODUCT=aosp_arm64
5export TARGET_BUILD_VARIANT=userdebug
6
7build/soong/soong_ui.bash \
8  --build-mode \
9  --all-modules \
10  --dir="$(pwd)" \
11  bp2build
12tools/bazel build --config=bp2build //build/bazel/scripts/difftool:collect_zip
13tools/bazel build --config=bp2build //build/bazel/scripts/difftool:difftool_zip
14
15# the following 2 arrays must be of the same size
16MODULES=(
17  libnativehelper
18)
19OUTPUTS=(
20  JNIHelp.o
21)
22PATH_FILTERS=(
23  "linux_glibc_x86_shared/\|linux_x86-fastbuild"
24  "linux_glibc_x86_64_shared/\|linux_x86_64-fastbuild"
25  "android_arm64[-_]"
26#  "android_arm[-_]" TODO(usta) investigate why there is a diff for this
27)
28readonly AOSP_ROOT="$(readlink -f "$(dirname "$0")"/../../..)"
29#TODO(usta): absolute path isn't compatible with collect.py and ninja
30readonly LEGACY_OUTPUT_SEARCH_TREE="out/soong/.intermediates/libnativehelper"
31readonly MIXED_OUTPUT_SEARCH_TREE="out/bazel/output/execroot/__main__/bazel-out"
32readonly NINJA_FILE="$AOSP_ROOT/out/combined-$TARGET_PRODUCT.ninja"
33# python is expected in PATH but used only to start a zipped python archive,
34# which bundles its own interpreter. We could also simply use `tools/bazel run`
35# instead however that sets the working directly differently and collect.py
36# won't work because it expects paths relative to $OUT_DIR
37# TODO(usta) make collect.py work with absolute paths and maybe consider
38# using `tools/bazel run` on the `py_binary` target directly instead of using
39# the python_zip_file filegroup's output
40readonly stub_python=python3
41readonly LEGACY_COLLECTION="$AOSP_ROOT/out/diff_metadata/legacy"
42readonly MIXED_COLLECTION="$AOSP_ROOT/out/diff_metadata/mixed"
43mkdir -p "$LEGACY_COLLECTION"
44mkdir -p "$MIXED_COLLECTION"
45
46function findIn() {
47  result=$(find "$1" -name "$3" | grep "$2")
48  count=$(echo "$result" | wc -l)
49  if [ "$count" != 1 ]; then
50    printf "multiple files found instead of exactly ONE:\n%s\n" "$result" 1>&2
51    exit 1
52  fi
53  echo "$result"
54}
55
56for ((i = 0; i < ${#MODULES[@]}; i++)); do
57  MODULE=${MODULES[$i]}
58  echo "Building $MODULE for comparison"
59  build/soong/soong_ui.bash --make-mode "$MODULE"
60  $stub_python "bazel-bin/build/bazel/scripts/difftool/collect.zip" \
61    "$NINJA_FILE" "$LEGACY_COLLECTION"
62  build/soong/soong_ui.bash \
63    --make-mode \
64    USE_BAZEL_ANALYSIS=1 \
65    BAZEL_STARTUP_ARGS="--max_idle_secs=5" \
66    BAZEL_BUILD_ARGS="--color=no --curses=no --noshow_progress" \
67    "$MODULE"
68  $stub_python "bazel-bin/build/bazel/scripts/difftool/collect.zip" \
69      "$NINJA_FILE" "$MIXED_COLLECTION"
70  OUTPUT=${OUTPUTS[$i]}
71  for ((j = 0; j < ${#PATH_FILTERS[@]}; j++)); do
72    PATH_FILTER=${PATH_FILTERS[$j]}
73    LEGACY_OUTPUT=$(findIn "$LEGACY_OUTPUT_SEARCH_TREE" "$PATH_FILTER" "$OUTPUT")
74    MIXED_OUTPUT=$(findIn "$MIXED_OUTPUT_SEARCH_TREE" "$PATH_FILTER" "$OUTPUT")
75
76    LEGACY_COLLECTION_DIR=$(dirname "$LEGACY_COLLECTION/$LEGACY_OUTPUT")
77    mkdir -p "$LEGACY_COLLECTION_DIR"
78    cp "$LEGACY_OUTPUT" "$LEGACY_COLLECTION_DIR"
79    MIXED_COLLECTION_DIR=$(dirname "$MIXED_COLLECTION/$MIXED_OUTPUT")
80    mkdir -p "$MIXED_COLLECTION_DIR"
81    cp "$MIXED_OUTPUT" "$MIXED_COLLECTION_DIR"
82
83    $stub_python "bazel-bin/build/bazel/scripts/difftool/difftool.zip" \
84      --level=SEVERE -v "$LEGACY_COLLECTION" "$MIXED_COLLECTION" \
85      -l="$LEGACY_OUTPUT" -r="$MIXED_OUTPUT"
86  done
87done
88
89