Skip to content

Commit 337ab58

Browse files
authored
Protect sdk upload script from missing ndk, add documentation for checking write access, improve comments to add context (flutter#47989)
Script used to upload 34v7 with ndk 26.1.10909125 Added documentation for how to check for write access before running script. Added documentation for why the ndk is in a non standard location. Protected against silent ndk failure caused by a failure to download ndk on m1 macs flutter#47609 (comment) Clean up os override so that script does not dirty the environment variables in a shell where it is run. See flutter/flutter#117973 for more detail on why a newer ndk is required.
1 parent ac942ca commit 337ab58

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

tools/android_sdk/create_cipd_packages.sh

+23-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ print_usage () {
1515
echo ""
1616
echo "This script downloads the packages specified in packages.txt and uploads"
1717
echo "them to CIPD for linux, mac, and windows."
18+
echo "To confirm you have write permissions run 'cipd acl-check flutter/android/sdk/all/ -writer'."
1819
echo ""
1920
echo "Manage the packages to download in 'packages.txt'. You can use"
2021
echo "'sdkmanager --list --include_obsolete' in cmdline-tools to list all available packages."
@@ -26,34 +27,36 @@ print_usage () {
2627
echo "and should only be run on linux or macos hosts."
2728
}
2829

29-
# Validate version is provided
30-
if [[ $1 == "" ]]; then
30+
first_argument=$1
31+
# Validate version or argument is provided.
32+
if [[ $first_argument == "" ]]; then
3133
print_usage
3234
exit 1
3335
fi
3436

35-
#Validate version contains only lower case letters and numbers
36-
if ! [[ $1 =~ ^[[:lower:][:digit:]]+$ ]]; then
37+
# Validate version contains only lower case letters and numbers.
38+
if ! [[ $first_argument =~ ^[[:lower:][:digit:]]+$ ]]; then
3739
echo "Version tag can only consist of lower case letters and digits.";
3840
print_usage
3941
exit 1
4042
fi
4143

42-
# Validate path contains depot_tools
44+
# Validate environment has cipd installed.
4345
if [[ `which cipd` == "" ]]; then
4446
echo "'cipd' command not found. depot_tools should be on the path."
4547
exit 1
4648
fi
4749

4850
sdk_path=${2:-$ANDROID_SDK_ROOT}
49-
version_tag=$1
5051

5152
# Validate directory contains all SDK packages
5253
if [[ ! -d "$sdk_path" ]]; then
5354
echo "Android SDK at '$sdk_path' not found."
5455
print_usage
5556
exit 1
5657
fi
58+
59+
# Validate caller has cipd.
5760
if [[ ! -d "$sdk_path/cmdline-tools" ]]; then
5861
echo "SDK directory does not contain $sdk_path/cmdline-tools."
5962
print_usage
@@ -81,7 +84,7 @@ while [ ! -f "$sdkmanager_path" ]; do
8184
done
8285

8386
# list available packages
84-
if [ $version_tag == "list" ]; then
87+
if [ $first_argument == "list" ]; then
8588
$sdkmanager_path --list --include_obsolete
8689
exit 0
8790
fi
@@ -120,12 +123,18 @@ for platform in "${platforms[@]}"; do
120123
# in `ndk/`.
121124
# This simplifies the build scripts, and enables version difference between
122125
# the Dart and Flutter build while reusing the same build rules.
126+
# See https://github.com/flutter/flutter/issues/136666#issuecomment-1805467578
123127
mv $upload_dir/sdk/ndk $upload_dir/ndk-bundle
124128
ndk_sub_paths=`find $upload_dir/ndk-bundle -maxdepth 1 -type d`
125129
ndk_sub_paths_arr=($ndk_sub_paths)
126130
mv ${ndk_sub_paths_arr[1]} $upload_dir/ndk
127131
rm -rf $upload_dir/ndk-bundle
128132

133+
if [[ ! -d "$upload_dir/ndk" ]]; then
134+
echo "Failure to bundle ndk for platform"
135+
exit 1
136+
fi
137+
129138
# Accept all licenses to ensure they are generated and uploaded.
130139
yes "y" | $sdkmanager_path --licenses --sdk_root=$sdk_root
131140
cp -r "$sdk_root/licenses" "$upload_dir/sdk"
@@ -141,11 +150,16 @@ for platform in "${platforms[@]}"; do
141150
if [[ $platform == "macosx" ]]; then
142151
cipd_name="mac-$arch"
143152
fi
144-
echo "Uploading $cipd_name to CIPD"
145-
cipd create -in $upload_dir -name "flutter/android/sdk/all/$cipd_name" -install-mode copy -tag version:$version_tag
153+
154+
echo "Uploading $upload_dir as $cipd_name to CIPD"
155+
cipd create -in $upload_dir -name "flutter/android/sdk/all/$cipd_name" -install-mode copy -tag version:$first_argument
146156
done
147157

148158
rm -rf $sdk_root
149159
rm -rf $upload_dir
160+
161+
# This variable changes the behvaior of sdkmanager.
162+
# Unset to clean up after script.
163+
unset REPO_OS_OVERRIDE
150164
done
151165
rm -rf $temp_dir

0 commit comments

Comments
 (0)