forked from LineageOS/android_kernel_xiaomi_surya
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cirrus_build.sh
executable file
·118 lines (104 loc) · 4.96 KB
/
cirrus_build.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
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Automation script for Building Kernels on Github Actions
# Download latest Neutron clang from their repos.
mkdir -p Neutron/
curl -s https://api.github.com/repos/Neutron-Toolchains/clang-build-catalogue/releases/latest \
| grep "browser_download_url.*tar.zst" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget --output-document=Neutron.tar.zst -qi -
tar -xf Neutron.tar.zst -C Neutron/ || exit 1
# Clone dependant repositories
# git clone --depth 1 -b gcc-master https://github.com/mvaisakh/gcc-arm64.git gcc-arm64
# git clone --depth 1 -b gcc-master https://github.com/mvaisakh/gcc-arm.git gcc-arm
git clone --depth 1 -b surya https://github.com/sunscape-stuff/AnyKernel3 || exit 1
git clone --depth 1 https://github.com/Stratosphere-Kernel/Stratosphere-Canaries || exit 1
# Workaround for safe.directory permission fix
git config --global safe.directory "$GITHUB_WORKSPACE"
git config --global safe.directory /github/workspace
git config --global --add safe.directory /__w/kernel_xiaomi_surya/kernel_xiaomi_surya
# Since I can't figure out how to do this on the Cirrus YML file, we'll do it here.
git submodule update --init --recursive --remote
# Export Environment Variables.
export DATE=$(date +"%d-%m-%Y-%I-%M")
export PATH="$(pwd)/Neutron/bin:$PATH"
# export PATH="$TC_DIR/bin:$HOME/gcc-arm/bin${PATH}"
export CLANG_TRIPLE=aarch64-linux-gnu-
export ARCH=arm64
# export CROSS_COMPILE=$(pwd)/gcc-arm64/bin/aarch64-elf-
# export CROSS_COMPILE_ARM32=$(pwd)/gcc-arm/bin/arm-eabi-
export CROSS_COMPILE=aarch64-linux-gnu-
# export CROSS_COMPILE_ARM32=arm-linux-gnueabi-
# export CROSS_COMPILE_COMPAT=arm-linux-gnueabi-
export LD_LIBRARY_PATH=$TC_DIR/lib
export KBUILD_BUILD_USER="David112x"
export KBUILD_BUILD_HOST="Cirrus"
export USE_HOST_LEX=yes
export KERNEL_IMG=output/arch/arm64/boot/Image
export KERNEL_DTBO=output/arch/arm64/boot/dtbo.img
export KERNEL_DTB=output/arch/arm64/boot/dts/qcom/sdmmagpie.dtb
export DEFCONFIG=surya-ksu_defconfig
export ANYKERNEL_DIR=$(pwd)/AnyKernel3/
export BUILD_ID=$CIRRUS_BUILD_ID
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
export SYSMEM="$(($(vmstat -s | grep -i 'total memory' | sed 's/ *//' | sed 's/total//g;s/memory//g;s/K//g;s/ / /g') / 1000))"
export GITBRNCH="$(git rev-parse --abbrev-ref HEAD)"
if [ "$(cat /sys/devices/system/cpu/smt/active)" = "1" ]; then
export THREADS=$(($(nproc --all) * 2))
else
export THREADS=$(nproc --all)
fi
# Telegram API Stuff
BUILD_START=$(date +"%s")
KBUILD_COMPILER_STRING=$("$TC_DIR"/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
BOT_MSG_URL="https://api.telegram.org/bot$token/sendMessage"
BOT_BUILD_URL="https://api.telegram.org/bot$token/sendDocument"
CHATID=-1001979543351
COMMIT_HEAD=$(git log --oneline -1)
TERM=xterm
tg_post_msg() {
curl -s -X POST "$BOT_MSG_URL" -d chat_id="$CHATID" \
-d "disable_web_page_preview=true" \
-d "parse_mode=html" \
-d text="$1"
}
tg_post_build() {
#Post MD5Checksum alongwith for easeness
MD5CHECK=$(md5sum "$1" | cut -d' ' -f1)
#Show the Checksum alongwith caption
curl --progress-bar -F document=@"$1" "$BOT_BUILD_URL" \
-F chat_id="$CHATID" \
-F "disable_web_page_preview=true" \
-F "parse_mode=Markdown" \
-F caption="$2 | *MD5 Checksum : *\`$MD5CHECK\`"
}
# Make defconfig
# make $DEFCONFIG LD=aarch64-elf-ld.lld O=output/
make $DEFCONFIG -j$THREADS CC=clang LD=ld.lld AS=llvm-as AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip O=output/
# Make Kernel
echo The system has $SYSMEM MB of total memory.
echo Using $THREADS jobs for this build...
echo Building branch: $GITBRNCH
tg_post_msg "<b>Build Started on Cirrus CI</b>%0A<b>Branch: </b><code>$GITBRNCH</code>%0A<b>Build Number: </b><code>"$BUILD_ID"</code>%0A<b>Date : </b><code>$(TZ=Etc/UTC date)</code>%0A<b>Top Commit : </b><code>$COMMIT_HEAD</code>%0A"
# make -j$THREADS LD=ld.lld O=output/
make -j$THREADS CC='ccache clang -Qunused-arguments -fcolor-diagnostics' LLVM=1 LD=ld.lld LLVM_IAS=1 AS=llvm-as AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip O=output/
# Check if Image exists. If not, stop executing.
if ! [ -a $KERNEL_IMG ];
then
echo "An error has occured during compilation. Please check your code."
tg_post_msg "<b>An error has occured during compilation. Build has failed</b>%0A"
exit 1
fi
# Make Flashable Zip
cp "$KERNEL_IMG" "$ANYKERNEL_DIR"
cp "$KERNEL_DTB" "$ANYKERNEL_DIR"/dtb
cp "$KERNEL_DTBO" "$ANYKERNEL_DIR"
cd AnyKernel3
zip -r9 UPDATE-AnyKernel3.zip * -x README.md LICENSE UPDATE-AnyKernel3.zip zipsigner.jar
cp UPDATE-AnyKernel3.zip package.zip
curl -sLo zipsigner-3.0.jar https://github.com/Magisk-Modules-Repo/zipsigner/raw/master/bin/zipsigner-3.0-dexed.jar
java -jar zipsigner-3.0.jar UPDATE-AnyKernel3.zip Sunscape-$GITBRNCH-$BUILD_ID.zip
BUILD_END=$(date +"%s")
DIFF=$((BUILD_END - BUILD_START))
tg_post_build "Sunscape-$GITBRNCH-$BUILD_ID.zip" "Build took : $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)"