xref: /aosp_15_r20/external/ltp/android/tools/gen_android_build.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#!/usr/bin/env bash
2*49cdfc7eSAndroid Build Coastguard Worker#
3*49cdfc7eSAndroid Build Coastguard Worker# Copyright 2016 - The Android Open Source Project
4*49cdfc7eSAndroid Build Coastguard Worker#
5*49cdfc7eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*49cdfc7eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*49cdfc7eSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*49cdfc7eSAndroid Build Coastguard Worker#
9*49cdfc7eSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*49cdfc7eSAndroid Build Coastguard Worker#
11*49cdfc7eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*49cdfc7eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*49cdfc7eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*49cdfc7eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*49cdfc7eSAndroid Build Coastguard Worker# limitations under the License.
16*49cdfc7eSAndroid Build Coastguard Worker#
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Workerset -e
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard WorkerTOOLS_DIR=$(realpath $(dirname $0))
21*49cdfc7eSAndroid Build Coastguard WorkerTOOLS_DUMP_DIR=$TOOLS_DIR/dump
22*49cdfc7eSAndroid Build Coastguard WorkerLTP_ANDROID_DIR=$(realpath $TOOLS_DIR/..)
23*49cdfc7eSAndroid Build Coastguard WorkerLTP_ROOT=$(realpath $LTP_ANDROID_DIR/..)
24*49cdfc7eSAndroid Build Coastguard WorkerCUSTOM_CFLAGS_PATH=$TOOLS_DIR/custom_cflags.json
25*49cdfc7eSAndroid Build Coastguard WorkerOUTPUT_BP=$LTP_ROOT/gen.bp
26*49cdfc7eSAndroid Build Coastguard WorkerOUTPUT_LTP_TESTCASE_BP=$LTP_ANDROID_DIR/../testcases/Android.bp
27*49cdfc7eSAndroid Build Coastguard WorkerOUTPUT_LTP_MAIN_BP=$LTP_ANDROID_DIR/../android/Android.bp
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Workerexport PYTHONDONTWRITEBYTECODE=1
30*49cdfc7eSAndroid Build Coastguard Worker
31*49cdfc7eSAndroid Build Coastguard Workercd $TOOLS_DIR
32*49cdfc7eSAndroid Build Coastguard Worker
33*49cdfc7eSAndroid Build Coastguard Workercase $1 in
34*49cdfc7eSAndroid Build Coastguard Worker  -u|--update)
35*49cdfc7eSAndroid Build Coastguard Worker    echo "Update option enabled. Regenerating..."
36*49cdfc7eSAndroid Build Coastguard Worker    rm -rf *.dump
37*49cdfc7eSAndroid Build Coastguard Worker    ;;
38*49cdfc7eSAndroid Build Coastguard Worker  -h|--help)
39*49cdfc7eSAndroid Build Coastguard Worker    echo "Generate Android.ltp.mk / gen.bp."
40*49cdfc7eSAndroid Build Coastguard Worker    echo "Please use \"--update\" option to update and regenerate Android.ltp.mk / gen.bp."
41*49cdfc7eSAndroid Build Coastguard Worker    exit 0
42*49cdfc7eSAndroid Build Coastguard Worker    ;;
43*49cdfc7eSAndroid Build Coastguard Workeresac
44*49cdfc7eSAndroid Build Coastguard Worker
45*49cdfc7eSAndroid Build Coastguard Workerif ! [ -f $TOOLS_DUMP_DIR/make_dry_run.dump ]; then
46*49cdfc7eSAndroid Build Coastguard Worker  DOCKER_USERNAME=$(id -un)
47*49cdfc7eSAndroid Build Coastguard Worker  DOCKER_UID=$(id -u)
48*49cdfc7eSAndroid Build Coastguard Worker  DOCKER_GID=$(id -g)
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker  echo "LTP make dry_run not dumped. Dumping..."
51*49cdfc7eSAndroid Build Coastguard Worker  echo ""
52*49cdfc7eSAndroid Build Coastguard Worker  echo "This may need your sudo password in order to access docker:"
53*49cdfc7eSAndroid Build Coastguard Worker  set -x
54*49cdfc7eSAndroid Build Coastguard Worker  sudo docker build --build-arg userid=$DOCKER_UID --build-arg groupid=$DOCKER_GID --build-arg username=$DOCKER_USERNAME --build-arg ltproot=$LTP_ROOT -t android-gen-ltp .
55*49cdfc7eSAndroid Build Coastguard Worker  sudo docker run -it --rm -v $LTP_ROOT:/src -w /src/android/tools android-gen-ltp
56*49cdfc7eSAndroid Build Coastguard Worker  set +x
57*49cdfc7eSAndroid Build Coastguard Workerfi
58*49cdfc7eSAndroid Build Coastguard Worker
59*49cdfc7eSAndroid Build Coastguard Workersed "s%#%//%" $LTP_ANDROID_DIR/AOSP_license_text.txt > $OUTPUT_BP
60*49cdfc7eSAndroid Build Coastguard Workerecho "" >> $OUTPUT_BP
61*49cdfc7eSAndroid Build Coastguard Workerecho "// This file is autogenerated by $(basename $0)" >> $OUTPUT_BP
62*49cdfc7eSAndroid Build Coastguard Worker
63*49cdfc7eSAndroid Build Coastguard Workersed "s%#%//%" $LTP_ANDROID_DIR/AOSP_license_text.txt > $OUTPUT_LTP_TESTCASE_BP
64*49cdfc7eSAndroid Build Coastguard Workerecho "" >> $OUTPUT_LTP_TESTCASE_BP
65*49cdfc7eSAndroid Build Coastguard Workerecho "// This file is autogenerated by $(basename $0)" >> $OUTPUT_LTP_TESTCASE_BP
66*49cdfc7eSAndroid Build Coastguard Worker
67*49cdfc7eSAndroid Build Coastguard Workersed "s%#%//%" $LTP_ANDROID_DIR/AOSP_license_text.txt > $OUTPUT_LTP_MAIN_BP
68*49cdfc7eSAndroid Build Coastguard Workerecho "" >> $OUTPUT_LTP_MAIN_BP
69*49cdfc7eSAndroid Build Coastguard Workerecho "// This file is autogenerated by $(basename $0)" >> $OUTPUT_LTP_MAIN_BP
70*49cdfc7eSAndroid Build Coastguard Worker
71*49cdfc7eSAndroid Build Coastguard Workerecho ""
72*49cdfc7eSAndroid Build Coastguard Workerecho "Parsing LTP make dry_run output..."
73*49cdfc7eSAndroid Build Coastguard WorkerCMD="python3 android_build_generator.py --ltp_root $LTP_ROOT \
74*49cdfc7eSAndroid Build Coastguard Worker    --output_prebuilt_ltp_testcase_bp_path $OUTPUT_LTP_TESTCASE_BP \
75*49cdfc7eSAndroid Build Coastguard Worker    --output_ltp_main_bp_path $OUTPUT_LTP_MAIN_BP \
76*49cdfc7eSAndroid Build Coastguard Worker    --output_bp_path $OUTPUT_BP \
77*49cdfc7eSAndroid Build Coastguard Worker    --custom_cflags_file $CUSTOM_CFLAGS_PATH"
78*49cdfc7eSAndroid Build Coastguard Workerecho $CMD
79*49cdfc7eSAndroid Build Coastguard Worker$CMD
80