forked from azrim/myscripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
santoni.sh
129 lines (110 loc) · 3.87 KB
/
santoni.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
#!/usr/bin/env bash
# Copyright (C) 2019-2020 Jago Gardiner (nysascape)
#
# Licensed under the Raphielscape Public License, Version 1.d (the "License");
# you may not use this file except in compliance with the License.
#
# CI build script
# Needed exports
export TELEGRAM_TOKEN=1157809262:AAHNbCHG-XcjgpGuDflcTX8Z_OJiXcjdDr0
export ANYKERNEL=$(pwd)/anykernel3
# Avoid hardcoding things
KERNEL=perf-caf-9-10
DEFCONFIG=santoni_treble_defconfig
DEVICE=santoni
CIPROVIDER=CircleCI
PARSE_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
PARSE_ORIGIN="$(git config --get remote.origin.url)"
COMMIT_POINT="$(git log --pretty=format:'%h : %s' -1)"
# Export custom KBUILD
export OUTFILE=${OUTDIR}/arch/arm64/boot/Image.gz-dtb
export KBUILD_BUILD_HOST=Termux
# Kernel groups
CI_CHANNEL=-1001488385343
# Set default local datetime
DATE=$(TZ=Asia/Jakarta date +"%Y%m%d-%T")
BUILD_DATE=$(TZ=Asia/Jakarta date +"%Y%m%d-%H%M")
# Clang is annoying
PATH="${KERNELDIR}/clang/bin:${PATH}"
# Kernel revision
KERNELRELEASE=santoni
# Function to replace defconfig versioning
setversioning() {
# For staging branch
KERNELNAME="${KERNEL}-${KERNELRELEASE}-treble-${BUILD_DATE}"
# Export our new localversion and zipnames
export KERNELTYPE KERNELNAME
export TEMPZIPNAME="${KERNELNAME}.zip"
export ZIPNAME="${KERNELNAME}.zip"
}
# Send to channel
tg_channelcast() {
"${TELEGRAM}" -c "${CI_CHANNEL}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
# Fix long kernel strings
kernelstringfix() {
git config --global user.name "predator112"
git config --global user.email "[email protected]"
git add .
git commit -m "stop adding dirty"
}
# Make the kernel
makekernel() {
# Clean any old AnyKernel
rm -rf ${ANYKERNEL}
git clone https://github.com/11-whyred-new/AnyKernel3 -b master anykernel3
kernelstringfix
make O=out ARCH=arm64 ${DEFCONFIG}
if [[ "${COMPILER_TYPE}" =~ "clang"* ]]; then
make -j$(nproc) O=out ARCH=arm64 CC=clang CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=aarch64-linux-gnu- CROSS_COMPILE_ARM32=arm-linux-gnueabi-
else
make -j$(nproc --all) O=out ARCH=arm64 CROSS_COMPILE="${KERNELDIR}/gcc/bin/aarch64-elf-" CROSS_COMPILE_ARM32="${KERNELDIR}/gcc32/bin/arm-eabi-"
fi
# Check if compilation is done successfully.
if ! [ -f "${OUTFILE}" ]; then
END=$(date +"%s")
DIFF=$(( END - START ))
echo -e "Kernel compilation failed, See buildlog to fix errors"
tg_channelcast "Build for ${DEVICE} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check ${CIPROVIDER} for errors!"
exit 1
fi
}
# Ship the compiled kernel
shipkernel() {
# Copy compiled kernel
cp "${OUTDIR}"/arch/arm64/boot/Image.gz-dtb "${ANYKERNEL}"/
# Zip the kernel, or fail
cd "${ANYKERNEL}" || exit
zip -r9 "${TEMPZIPNAME}" *
# Ship it to the CI channel
"${TELEGRAM}" -f "$ZIPNAME" -c "${CI_CHANNEL}"
# Go back for any extra builds
cd ..
}
# Fix for CI builds running out of memory
fixcilto() {
sed -i 's/CONFIG_LTO=y/# CONFIG_LTO is not set/g' arch/arm64/configs/${DEFCONFIG}
sed -i 's/CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y/# CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is not set/g' arch/arm64/configs/${DEFCONFIG}
}
## Start the kernel buildflow ##
setversioning
fixcilto
tg_channelcast "<b>CI Build Triggered</b>" \
"Compiler: <code>${COMPILER_STRING}</code>" \
"Device: ${DEVICE}" \
"Kernel: <code>${KERNEL}, ${KERNELRELEASE}</code>" \
"Linux Version: <code>$(make kernelversion)</code>" \
"Branch: <code>${PARSE_BRANCH}</code>" \
"Commit point: <code>${COMMIT_POINT}</code>" \
"Clocked at: <code>$(date +%Y%m%d-%H%M)</code>"
START=$(date +"%s")
makekernel || exit 1
shipkernel
END=$(date +"%s")
DIFF=$(( END - START ))
tg_channelcast "Build for ${DEVICE} with ${COMPILER_STRING} <b>succeed</b> took $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)!"