-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
create_cipd_packages.sh
executable file
·139 lines (122 loc) · 4.62 KB
/
create_cipd_packages.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# This script requires depot_tools to be on path.
print_usage () {
echo "Usage:"
echo " ./create_cipd_packages.sh <VERSION_TAG> [PATH_TO_SDK_DIR]"
echo " Downloads, packages, and uploads Android SDK packages where:"
echo " - VERSION_TAG is the tag of the cipd packages, e.g. 28r6 or 31v1"
echo " - PATH_TO_SDK_DIR is the path to the sdk folder. If omitted, this defaults to"
echo " your ANDROID_SDK_ROOT environment variable."
echo " ./create_cipd_packages.sh list"
echo " Lists the available packages for use in 'packages.txt'"
echo ""
echo "This script downloads the packages specified in packages.txt and uploads"
echo "them to CIPD for linux, mac, and windows."
echo ""
echo "Manage the packages to download in 'packages.txt'. You can use"
echo "'sdkmanager --list --include_obsolete' in cmdline-tools to list all available packages."
echo "Packages should be listed in the format of <package-name>:<directory-to-upload>."
echo "For example, build-tools;31.0.0:build-tools"
echo "Multiple directories to upload can be specified by delimiting by additional ':'"
echo ""
echo "This script expects the cmdline-tools to be installed in your specified PATH_TO_SDK_DIR"
echo "and should only be run on linux or macos hosts."
}
# Validate version is provided
if [[ $1 == "" ]]; then
print_usage
exit 1
fi
# Validate path contains depot_tools
if [[ `which cipd` == "" ]]; then
echo "'cipd' command not found. depot_tools should be on the path."
exit 1
fi
sdk_path=${2:-$ANDROID_SDK_ROOT}
version_tag=$1
# Validate directory contains all SDK packages
if [[ ! -d "$sdk_path" ]]; then
echo "Android SDK at '$sdk_path' not found."
print_usage
exit 1
fi
if [[ ! -d "$sdk_path/cmdline-tools" ]]; then
echo "SDK directory does not contain $sdk_path/cmdline-tools."
print_usage
exit 1
fi
platforms=("linux" "macosx" "windows")
package_file_name="packages.txt"
# Find the sdkmanager in cmdline-tools. We default to using latest if available.
sdkmanager_path="$sdk_path/cmdline-tools/latest/bin/sdkmanager"
find_results=()
while IFS= read -r line; do
find_results+=("$line")
done < <(find "$sdk_path/cmdline-tools" -name sdkmanager)
i=0
while [ ! -f "$sdkmanager_path" ]; do
if [ $i -ge ${#find_results[@]} ]; then
echo "Unable to find sdkmanager in the SDK directory. Please ensure cmdline-tools is installed."
exit 1
fi
sdkmanager_path="${find_results[$i]}"
echo $sdkmanager_path
((i++))
done
# list available packages
if [ $version_tag == "list" ]; then
$sdkmanager_path --list --include_obsolete
exit 0
fi
# We create a new temporary SDK directory because the default working directory
# tends to not update/re-download packages if they are being used. This guarantees
# a clean install of Android SDK.
temp_dir=`mktemp -d -t android_sdkXXXX`
for platform in "${platforms[@]}"; do
sdk_root="$temp_dir/sdk_$platform"
upload_dir="$temp_dir/upload_$platform"
echo "Creating temporary working directory for $platform: $sdk_root"
mkdir $sdk_root
mkdir $upload_dir
mkdir $upload_dir/sdk
export REPO_OS_OVERRIDE=$platform
# Download all the packages with sdkmanager.
for package in $(cat $package_file_name); do
echo $package
split=(${package//:/ })
echo "Installing ${split[0]}"
yes "y" | $sdkmanager_path --sdk_root=$sdk_root ${split[0]}
# We copy only the relevant directories to a temporary dir
# for upload. sdkmanager creates extra files that we don't need.
array_length=${#split[@]}
for (( i=1; i<${array_length}; i++ )); do
cp -r "$sdk_root/${split[$i]}" "$upload_dir/sdk"
done
done
# Special treatment for NDK to move to expected directory.
mv $upload_dir/sdk/ndk $upload_dir/ndk-bundle
ndk_sub_paths=`find $upload_dir/ndk-bundle -maxdepth 1 -type d`
ndk_sub_paths_arr=($ndk_sub_paths)
mv ${ndk_sub_paths_arr[1]} $upload_dir/ndk
rm -rf $upload_dir/ndk-bundle
# Accept all licenses to ensure they are generated and uploaded.
yes "y" | $sdkmanager_path --licenses --sdk_root=$sdk_root
cp -r "$sdk_root/licenses" "$upload_dir/sdk"
archs=("amd64")
if [[ $platform == "macosx" ]]; then
# Upload an arm64 version for M1 macs
archs=("amd64" "arm64")
fi
for arch in "${archs[@]}"; do
# Mac uses a different sdkmanager name than the platform name used in gn.
cipd_name="$platform-$arch"
if [[ $platform == "macosx" ]]; then
cipd_name="mac-$arch"
fi
echo "Uploading $cipd_name to CIPD"
cipd create -in $upload_dir -name "flutter/android/sdk/all/$cipd_name" -install-mode copy -tag version:$version_tag
done
rm -rf $sdk_root
rm -rf $upload_dir
done
rm -rf $temp_dir