Skip to content

Commit cd2dafe

Browse files
committed
Add a script to update the forks of AOSP sources
Various AOSP sources are fully copied and forked, and some are also patched. Make updating these files easier.
1 parent c9323fb commit cd2dafe

1 file changed

Lines changed: 226 additions & 0 deletions

File tree

base/cvd/update_aosp_sources.sh

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
usage() {
6+
echo "usage: $0 [/path/to/android/source/tree]"
7+
exit
8+
}
9+
[ -z "$1" ] && usage
10+
11+
# $1 = array name to update with checked path
12+
# $2 = suffix applied to variable name set to checked path
13+
# $3 = check this path is an existing directory
14+
check_dir() {
15+
local -n array="${1}"
16+
if [ ! -d "${3}" ]; then
17+
echo "${3} does not exist!"
18+
exit
19+
fi
20+
eval ${3##*/}${2}="${3}"
21+
array+=("${3}")
22+
}
23+
24+
script_dir="$(dirname $(readlink -f "$0"))"
25+
cd ${script_dir}
26+
27+
source_dirs=()
28+
add_source_dir() {
29+
check_dir source_dirs "_source" "${1}"
30+
}
31+
add_source_dir "$1/packages/modules/adb"
32+
add_source_dir "$1/system/core/diagnose_usb"
33+
add_source_dir "$1/system/core/fastboot"
34+
add_source_dir "$1/system/core/fs_mgr/libstorage_literals"
35+
add_source_dir "$1/system/core/libcrypto_utils"
36+
add_source_dir "$1/system/core/mkbootfs"
37+
add_source_dir "$1/system/extras/ext4_utils"
38+
add_source_dir "$1/system/extras/libfec"
39+
add_source_dir "$1/system/extras/verity"
40+
add_source_dir "$1/system/teeui/libteeui"
41+
# Can now access with e.g. $adb_source or $source_dirs[x]
42+
43+
dest_dirs=()
44+
add_dest_dir() {
45+
check_dir dest_dirs "" "${1}"
46+
}
47+
add_dest_dir "adb"
48+
add_dest_dir "fastboot"
49+
add_dest_dir "fec"
50+
add_dest_dir "libext4_utils"
51+
add_dest_dir "mkbootfs"
52+
add_dest_dir "teeui/libteeui"
53+
# Can now access with e.g. $adb or $dest_dirs[x]
54+
55+
echo "WARNING: This script MUST be run against an AOSP / publicly released Android tree."
56+
echo "WARNING: Do not run it against an internal Android tree under any circumstance!"
57+
echo
58+
while true; do
59+
read -p "Do you understand the above instructions? " yn
60+
case $yn in
61+
[Yy]* ) break;;
62+
[Nn]* ) exit;;
63+
* ) echo "Please answer yes or no.";;
64+
esac
65+
done
66+
echo
67+
68+
adb() {
69+
cp -a "${adb_source}"/* .
70+
cp -a "${diagnose_usb_source}"/* diagnose_usb/
71+
cp -a "${libcrypto_utils_source}"/* libcrypto_utils/
72+
73+
# Remove Android build system and metadata
74+
find \( -name Android.bp -or -name OWNERS \) -exec rm -f '{}' ';'
75+
rm -f adbd_flags.aconfig METADATA MODULE_LICENSE_* NOTICE PREUPLOAD.cfg TEST_MAPPING
76+
rm -rf apex
77+
78+
# Remove coverage instrumentation
79+
rm -rf coverage
80+
81+
# Remove documentation
82+
rm -rf docs/ README.md sockets.dia
83+
84+
# Remove tools
85+
rm -rf adb.bash tools/
86+
87+
# Remove symbol map text files, as the modules using them are not built
88+
find -name '*.map.txt' -exec rm -f '{}' ';'
89+
90+
# Remove osx and windows support
91+
find \( -name '*_osx*' -or -name 'fdevent_poll*' -or -name '*_windows*' -or -name '*win32*' \) -exec rm -rf '{}' ';' 2>/dev/null || true
92+
93+
# Remove all tests, as they are not built and have additional dependencies
94+
find \( -name '*_test.*' -or -name tests -or -name 'test_*' \) -exec rm -rf '{}' ';' 2>/dev/null || true
95+
rm -f adb_integration_test_* run-device-tests.sh
96+
97+
# Remove all benchmarks, as they are not built and have additional dependencies
98+
find \( -name '*_benchmark.*' -or -name 'benchmark_*' -or -name trace.sh \) -exec rm -rf '{}' ';'
99+
100+
# Remove fastdeploy
101+
rm -rf client/fastdeploy.* fastdeploy/ proto/jarjar-rules.txt
102+
103+
# Remove adb device-side daemon sources
104+
rm -rf daemon/ libs/ security_log_tags.h transfer_id.h
105+
find pairing_connection \( -name 'pairing_server*' -or -name internal \) -exec rm -rf '{}' ';' 2>/dev/null || true
106+
}
107+
108+
fastboot() {
109+
cp -a "${fastboot_source}"/* .
110+
cp -a "${diagnose_usb_source}"/* diagnose_usb/
111+
cp -a "${libstorage_literals_source}"/* libstorage_literals/
112+
113+
# Remove fuzzers
114+
rm -rf fuzzer fuzzy_fastboot
115+
116+
# Remove osx and windows support
117+
find \( -name '*_osx*' -or -name '*_windows*' \) -exec rm -rf '{}' ';' 2>/dev/null || true
118+
119+
# Remove Android build system and metadata
120+
find \( -name Android.bp -or -name OWNERS \) -exec rm -f '{}' ';'
121+
rm -f LICENSE README.md TEST_MAPPING
122+
123+
# Remove device-side implementation
124+
rm -rf device
125+
126+
# Remove tools
127+
rm -rf fastboot.bash
128+
129+
# Remove all tests, as they are not built and have additional dependencies
130+
find \( \
131+
-name '*_test.*' -or -name 'test_*' -or -name tests -or \
132+
-name '*_mock.*' -or -name 'mock_*' \
133+
\) -exec rm -rf '{}' ';' 2>/dev/null || true
134+
rm -rf testdata
135+
}
136+
137+
fec() {
138+
cp -a "${libcrypto_utils_source}"/include/* libcrypto_utils/include/
139+
cp -a "${libfec_source}"/* libfec/
140+
cp -a "${verity_source}"/fec/* verity/fec/
141+
142+
# Remove Android build system and metadata
143+
find \( -name Android.bp -or -name OWNERS -or -name NOTICE \) -exec rm -f '{}' ';'
144+
145+
# Remove all tests, as they are not built and have additional dependencies
146+
find \( -name test -or -name tests \) -exec rm -rf '{}' ';' 2>/dev/null || true
147+
}
148+
149+
libext4_utils() {
150+
cp -a "${ext4_utils_source}"/* .
151+
chmod a+x mkuserimg_mke2fs.py
152+
153+
# Remove Android build system and metadata
154+
rm -f Android.bp MODULE_LICENSE_* NOTICE OWNERS
155+
156+
# Remove unused blk_allow_to_base_fs and "wipe" APIs
157+
rm -f blk_alloc_to_base_fs.cpp include/ext4_utils/wipe.h wipe.cpp
158+
159+
# Remove all tests, as they are not built and have additional dependencies
160+
find -name 'test_*' -exec rm -f '{}' ';' 2>/dev/null
161+
}
162+
163+
libteeui() {
164+
cp -a "${libteeui_source}"/* .
165+
166+
# Remove Android build system
167+
find -name Android.bp -exec rm -f '{}' ';'
168+
169+
# Remove generic operation/messages support
170+
rm -f \
171+
include/teeui/cbor.h \
172+
include/teeui/generic_messages.h \
173+
include/teeui/generic_operation.h \
174+
src/cbor.cpp \
175+
src/generic_messages.cpp \
176+
src/msg_formatting.cpp
177+
178+
# Remove input device support
179+
rm -rf include/secure_input/ src/evdev.cpp src/weak_secure_input_device.cpp
180+
181+
# Remove example code
182+
rm -rf example/ include/teeui/example/ include/teeui/incfont.h
183+
}
184+
185+
mkbootfs() {
186+
cp -a "${mkbootfs_source}"/* .
187+
188+
# Remove Android build system
189+
rm -f Android.bp
190+
}
191+
192+
# Remove everything, except..
193+
# - BUILD.bazel and *.patch, which are GitHub-only
194+
# - Compat.h, which is stubbed as it is not used
195+
# - squashfs_utils.h, which is stubbed to avoid a libsquashfs_utils dependency
196+
# - version.h and platform_tools_version.h, which are generated files in AOSP
197+
excluded_files=("Compat.h squashfs_utils.h platform_tools_version.h version.h")
198+
for dir in ${dest_dirs[@]}; do
199+
find ${dir} -type f \( \
200+
-not -name BUILD.bazel \
201+
-and -not -name '*.patch' \
202+
$(for file in ${excluded_files[@]}; do echo -and -not -name "$file"; done) \
203+
\) -exec rm -f '{}' ';'
204+
done
205+
206+
# Copy, prune and optionally patch the upstream sources
207+
for dir in ${dest_dirs[@]}; do
208+
pushd "${dir}" >/dev/null
209+
${dir##*/}
210+
if [ -d patches ]; then
211+
for patch in patches/*; do
212+
echo Applying patch "$dir/$patch"...
213+
level=$((4 + $(echo $dir | tr -cd / | wc -c)))
214+
patch --no-backup-if-mismatch -Np${level} -i $patch
215+
echo
216+
done
217+
fi
218+
popd >/dev/null
219+
done
220+
221+
echo "WARNING: Remember to update:"
222+
for dir in ${dest_dirs[@]}; do
223+
find "${dir}" -name zzyzx \
224+
$(for file in ${excluded_files[@]}; do echo -or -name "$file"; done)
225+
done
226+
echo "Done!"

0 commit comments

Comments
 (0)