aboutsummaryrefslogtreecommitdiff
path: root/test_mappings/test_mappings.sh
blob: 8a8ca5ab5b217f8ab4f1eab8f0d6578bd72410c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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.

# Ensure hermeticity.
PATH="$PWD/prebuilts/build-tools/path/linux-x86/:$PWD/prebuilts/build-tools/linux-x86/bin/"

while [[ $# -gt 0 ]]; do
  case $1 in
    --dist_dir)
      DIST_DIR="$2"
      shift # past argument
      shift # past value
      ;;
    --dist_dir=*)
      DIST_DIR=$1
      DIST_DIR="${DIST_DIR#*=}"
      shift # past argument=value
      ;;
    -*|--*)
      # There may be additional arguments passed to copy_to_dist_dir. Ignore them.
      shift
      ;;
    *)
      # There may be additional arguments passed to copy_to_dist_dir. Ignore them.
      shift
      ;;
  esac
done

# BUILD_WORKSPACE_DIRECTORY is the root of the Bazel workspace containing
# this binary target.
# https://docs.bazel.build/versions/main/user-manual.html#run
ROOT_DIR=$BUILD_WORKSPACE_DIRECTORY
if [[ -z "$ROOT_DIR" ]]; then
  echo "ERROR: Only execute this script with bazel run." >&2
  exit 1
fi

if [[ -z "$DIST_DIR" ]]; then
  echo "ERROR: --dist_dir is not specified." >&2
  exit 1
fi

if [[ ! "$DIST_DIR" == /* ]]; then
  DIST_DIR=${ROOT_DIR}/${DIST_DIR}
fi
mkdir -p ${DIST_DIR}

OUTPUT_FILE=${DIST_DIR}/test_mappings.zip
echo "Generating ${OUTPUT_FILE}"

trap 'rm -f "$TMPFILE"' EXIT
TEST_MAPPING_FILES=$(mktemp)
find ${ROOT_DIR} -path "${ROOT_DIR}/out*" -prune -o \
  -name TEST_MAPPING -type f \
  -not -path "${ROOT_DIR}/\.git*" \
  -not -path "${ROOT_DIR}/\.repo*" \
  -print > ${TEST_MAPPING_FILES}
soong_zip -o ${OUTPUT_FILE} -C ${ROOT_DIR} -l ${TEST_MAPPING_FILES}
rm -f ${TEST_MAPPING_FILES}