forked from lemniskett/android-kernel-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·229 lines (203 loc) · 9.27 KB
/
entrypoint.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env bash
msg(){
echo
echo "==> $*"
echo
}
err(){
echo 1>&2
echo "==> $*" 1>&2
echo 1>&2
}
set_output(){
echo "::set-output name=$1::$2"
}
extract_tarball(){
echo "Extracting $1 to $2"
tar xf "$1" -C "$2"
}
workdir="$GITHUB_WORKSPACE"
arch="$1"
compiler="$2"
defconfig="$3"
image="$4"
repo_name="${GITHUB_REPOSITORY/*\/}"
zipper_path="${ZIPPER_PATH:-zipper}"
kernel_path="${KERNEL_PATH:-.}"
name="${NAME:-$repo_name}"
msg "Updating container..."
apt update && apt upgrade -y
msg "Installing essential packages..."
apt install -y --no-install-recommends git make bc bison openssl \
curl zip kmod cpio flex libelf-dev libssl-dev libtfm-dev wget \
device-tree-compiler ca-certificates python3 python2
ln -sf /usr/bin/python3 /usr/bin/python
set_output hash "$(cd "$kernel_path" && git rev-parse HEAD || exit 127)"
msg "Installing toolchain..."
if [[ $arch = "arm64" ]]; then
arch_opts="ARCH=${arch} SUBARCH=${arch}"
export ARCH="$arch"
export SUBARCH="$arch"
if [[ $compiler = gcc/* ]]; then
ver_number="${compiler/gcc\/}"
make_opts=""
host_make_opts=""
if ! apt install -y --no-install-recommends gcc-"$ver_number" g++-"$ver_number" \
gcc-"$ver_number"-aarch64-linux-gnu gcc-"$ver_number"-arm-linux-gnueabi; then
err "Compiler package not found, refer to the README for details"
exit 1
fi
ln -sf /usr/bin/gcc-"$ver_number" /usr/bin/gcc
ln -sf /usr/bin/g++-"$ver_number" /usr/bin/g++
ln -sf /usr/bin/aarch64-linux-gnu-gcc-"$ver_number" /usr/bin/aarch64-linux-gnu-gcc
ln -sf /usr/bin/arm-linux-gnueabi-gcc-"$ver_number" /usr/bin/arm-linux-gnueabi-gcc
export CROSS_COMPILE="aarch64-linux-gnu-"
export CROSS_COMPILE_ARM32="arm-linux-gnueabi-"
elif [[ $compiler = clang/* ]]; then
ver="${compiler/clang\/}"
ver_number="${ver/\/binutils}"
binutils="$([[ $ver = */binutils ]] && echo true || echo false)"
if $binutils; then
additional_packages="binutils binutils-aarch64-linux-gnu binutils-arm-linux-gnueabi"
make_opts="CC=clang"
host_make_opts="HOSTCC=clang HOSTCXX=clang++"
else
# Most android kernels still need binutils as the assembler, but it will
# not be used when the Makefile is patched to make use of LLVM_IAS option
additional_packages="binutils-aarch64-linux-gnu binutils-arm-linux-gnueabi"
make_opts="CC=clang LD=ld.lld NM=llvm-nm AR=llvm-ar STRIP=llvm-strip OBJCOPY=llvm-objcopy"
make_opts+=" OBJDUMP=llvm-objdump READELF=llvm-readelf LLVM_IAS=1"
host_make_opts="HOSTCC=clang HOSTCXX=clang++ HOSTLD=ld.lld HOSTAR=llvm-ar"
fi
if ! apt install -y --no-install-recommends clang-"$ver_number" \
lld-"$ver_number" llvm-"$ver_number" $additional_packages; then
err "Compiler package not found, refer to the README for details"
exit 1
fi
ln -sf /usr/bin/clang-"$ver_number" /usr/bin/clang
ln -sf /usr/bin/clang-"$ver_number" /usr/bin/clang++
ln -sf /usr/bin/ld.lld-"$ver_number" /usr/bin/ld.lld
for i in /usr/bin/llvm-*-"$ver_number"; do
ln -sf "$i" "${i/-$ver_number}"
done
export CLANG_TRIPLE="aarch64-linux-gnu-"
export CROSS_COMPILE="aarch64-linux-gnu-"
export CROSS_COMPILE_ARM32="arm-linux-gnueabi-"
elif [[ $compiler = proton-clang/* ]]; then
ver="${compiler/proton-clang\/}"
ver_number="${ver/\/binutils}"
url="https://github.com/kdrag0n/proton-clang/archive/${ver_number}.tar.gz"
binutils="$([[ $ver = */binutils ]] && echo true || echo false)"
# Due to different time in container and the host,
# disable certificate check
echo "Downloading $url"
if ! wget --no-check-certificate "$url" -O /tmp/proton-clang-"${ver_number}".tar.gz &>/dev/null; then
err "Failed downloading toolchain, refer to the README for details"
exit 1
fi
if $binutils; then
make_opts="CC=clang"
host_make_opts="HOSTCC=clang HOSTCXX=clang++"
else
make_opts="CC=clang LD=ld.lld NM=llvm-nm AR=llvm-ar STRIP=llvm-strip OBJCOPY=llvm-objcopy"
make_opts+=" OBJDUMP=llvm-objdump READELF=llvm-readelf LLVM_IAS=1"
host_make_opts="HOSTCC=clang HOSTCXX=clang++ HOSTLD=ld.lld HOSTAR=llvm-ar"
fi
apt install -y --no-install-recommends libgcc-10-dev || exit 127
extract_tarball /tmp/proton-clang-"${ver_number}".tar.gz /
cd /proton-clang-"${ver_number}"* || exit 127
proton_path="$(pwd)"
cd "$workdir"/"$kernel_path" || exit 127
export PATH="$proton_path/bin:${PATH}"
export CLANG_TRIPLE="aarch64-linux-gnu-"
export CROSS_COMPILE="aarch64-linux-gnu-"
export CROSS_COMPILE_ARM32="arm-linux-gnueabi-"
elif [[ $compiler = aosp-clang/* ]]; then
ver="${compiler/aosp-clang\/}"
ver_number="${ver/\/binutils}"
url="https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/${ver_number}.tar.gz"
binutils="$([[ $ver = */binutils ]] && echo true || echo false)"
echo "Downloading $url"
if ! wget --no-check-certificate "$url" -O /tmp/aosp-clang.tar.gz &>/dev/null; then
err "Failed downloading toolchain, refer to the README for details"
exit 1
fi
url="https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/refs/heads/master.tar.gz"
echo "Downloading $url"
if ! wget --no-check-certificate "$url" -O /tmp/aosp-gcc-arm64.tar.gz &>/dev/null; then
err "Failed downloading toolchain, refer to the README for details"
exit 1
fi
url="https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/+archive/refs/heads/master.tar.gz"
echo "Downloading $url"
if ! wget --no-check-certificate "$url" -O /tmp/aosp-gcc-arm.tar.gz &>/dev/null; then
err "Failed downloading toolchain, refer to the README for details"
exit 1
fi
url="https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/+archive/refs/heads/master.tar.gz"
echo "Downloading $url"
if ! wget --no-check-certificate "$url" -O /tmp/aosp-gcc-host.tar.gz &>/dev/null; then
err "Failed downloading toolchain, refer to the README for details"
exit 1
fi
mkdir -p /aosp-clang /aosp-gcc-arm64 /aosp-gcc-arm /aosp-gcc-host
extract_tarball /tmp/aosp-clang.tar.gz /aosp-clang
extract_tarball /tmp/aosp-gcc-arm64.tar.gz /aosp-gcc-arm64
extract_tarball /tmp/aosp-gcc-arm.tar.gz /aosp-gcc-arm
extract_tarball /tmp/aosp-gcc-host.tar.gz /aosp-gcc-host
for i in /aosp-gcc-host/bin/x86_64-linux-*; do
ln -sf "$i" "${i/x86_64-linux-}"
done
if $binutils; then
make_opts="CC=clang"
host_make_opts="HOSTCC=clang HOSTCXX=clang++"
else
make_opts="CC=clang LD=ld.lld NM=llvm-nm AR=llvm-ar STRIP=llvm-strip OBJCOPY=llvm-objcopy"
make_opts+=" OBJDUMP=llvm-objdump READELF=llvm-readelf LLVM_IAS=1"
host_make_opts="HOSTCC=clang HOSTCXX=clang++ HOSTLD=ld.lld HOSTAR=llvm-ar"
fi
apt install -y --no-install-recommends libgcc-10-dev || exit 127
export PATH="/aosp-clang/bin:/aosp-gcc-arm64/bin:/aosp-gcc-arm/bin:/aosp-gcc-host/bin:$PATH"
export CLANG_TRIPLE="aarch64-linux-gnu-"
export CROSS_COMPILE="aarch64-linux-android-"
export CROSS_COMPILE_ARM32="arm-linux-androideabi-"
else
err "Unsupported toolchain string. refer to the README for more detail"
exit 100
fi
else
err "Currently this action only supports arm64, refer to the README for more detail"
exit 100
fi
cd "$workdir"/"$kernel_path" || exit 127
start_time="$(date +%s)"
date="$(date +%d%m%Y-%I%M)"
tag="$(git branch | sed 's/*\ //g')"
echo "branch/tag: $tag"
echo "make options:" $arch_opts $make_opts $host_make_opts
msg "Generating defconfig from \`make $defconfig\`..."
if ! make O=out $arch_opts $make_opts $host_make_opts "$defconfig"; then
err "Failed generating .config, make sure it is actually available in arch/${arch}/configs/ and is a valid defconfig file"
exit 2
fi
msg "Begin building kernel..."
if ! make O=out $arch_opts $make_opts $host_make_opts -j"$(nproc --all)"; then
err "Failed building kernel, probably the toolchain is not compatible with the kernel, or kernel source problem"
exit 3
fi
set_output elapsed_time "$(echo "$(date +%s)"-"$start_time" | bc)"
msg "Packaging the kernel..."
zip_filename="${name}-${tag}-${date}.zip"
if [[ -e "$workdir"/"$zipper_path" ]]; then
cp out/arch/"$arch"/boot/"$image" "$workdir"/"$zipper_path"/"$image"
cd "$workdir"/"$zipper_path" || exit 127
rm -rf .git
zip -r9 "$zip_filename" . || exit 127
set_output outfile "$workdir"/"$zipper_path"/"$zip_filename"
cd "$workdir" || exit 127
exit 0
else
msg "No zip template provided, releasing the kernel image instead"
set_output outfile out/arch/"$arch"/boot/"$image"
exit 0
fi