• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -e
2
3# Copyright (C) 2022 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Ensure hermeticity.
18PATH="$PWD/prebuilts/build-tools/path/linux-x86/:$PWD/prebuilts/build-tools/linux-x86/bin/"
19
20while [[ $# -gt 0 ]]; do
21  case $1 in
22    --dist_dir)
23      DIST_DIR="$2"
24      shift # past argument
25      shift # past value
26      ;;
27    --dist_dir=*)
28      DIST_DIR=$1
29      DIST_DIR="${DIST_DIR#*=}"
30      shift # past argument=value
31      ;;
32    -*|--*)
33      # There may be additional arguments passed to copy_to_dist_dir. Ignore them.
34      shift
35      ;;
36    *)
37      # There may be additional arguments passed to copy_to_dist_dir. Ignore them.
38      shift
39      ;;
40  esac
41done
42
43# BUILD_WORKSPACE_DIRECTORY is the root of the Bazel workspace containing
44# this binary target.
45# https://docs.bazel.build/versions/main/user-manual.html#run
46ROOT_DIR=$BUILD_WORKSPACE_DIRECTORY
47if [[ -z "$ROOT_DIR" ]]; then
48  echo "ERROR: Only execute this script with bazel run." >&2
49  exit 1
50fi
51
52if [[ -z "$DIST_DIR" ]]; then
53  echo "ERROR: --dist_dir is not specified." >&2
54  exit 1
55fi
56
57if [[ ! "$DIST_DIR" == /* ]]; then
58  DIST_DIR=${ROOT_DIR}/${DIST_DIR}
59fi
60mkdir -p ${DIST_DIR}
61
62OUTPUT_FILE=${DIST_DIR}/test_mappings.zip
63echo "Generating ${OUTPUT_FILE}"
64
65trap 'rm -f "$TMPFILE"' EXIT
66TEST_MAPPING_FILES=$(mktemp)
67find ${ROOT_DIR} -path "${ROOT_DIR}/out*" -prune -o \
68  -name TEST_MAPPING -type f \
69  -not -path "${ROOT_DIR}/\.git*" \
70  -not -path "${ROOT_DIR}/\.repo*" \
71  -print > ${TEST_MAPPING_FILES}
72soong_zip -o ${OUTPUT_FILE} -C ${ROOT_DIR} -l ${TEST_MAPPING_FILES}
73rm -f ${TEST_MAPPING_FILES}
74