forked from kibria5/kernel_xiaomi_violet
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.py
148 lines (144 loc) · 5.36 KB
/
build.py
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
import os
import sys
import subprocess
import string
import random
bashfile=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
bashfile='/tmp/'+bashfile+'.sh'
f = open(bashfile, 'w')
s = """#!/bin/bash
# Telegram Config
TOKEN=$(/usr/bin/env python -c "import os; print(os.environ.get('TOKEN'))")
CHATID=$(/usr/bin/env python -c "import os; print(os.environ.get('CHATID'))")
API_KEY=$(/usr/bin/env python -c "import os; print(os.environ.get('API_KEY'))")
BOT_MSG_URL="https://api.telegram.org/bot${TOKEN}/sendMessage"
BOT_BUILD_URL="https://api.telegram.org/bot${TOKEN}/sendDocument"
# Build Machine details
cores=$(lscpu | grep "Core(s) per socket" | awk '{print $NF}')
os=$(cat /etc/issue)
time=$(TZ="Asia/Dhaka" date "+%a %b %d %r")
# send saxx msgs to tg
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"
}
# send build to tg
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\\`"
}
kernel_dir="${PWD}"
CCACHE=$(command -v ccache)
objdir="${kernel_dir}/out"
anykernel=$HOME/anykernel
builddir="${kernel_dir}/build"
ZIMAGE=$kernel_dir/out/arch/arm64/boot/Image.gz-dtb
kernel_name="perf_violet"
KERVER=$(make kernelversion)
COMMIT_HEAD=$(git log --oneline -1)
zip_name="$kernel_name-$(date +"%d%m%Y-%H%M")-signed.zip"
TC_DIR=$HOME/tc/
CLANG_DIR=$TC_DIR/clang-r522817
export CONFIG_FILE="vendor/violet-perf_defconfig"
export ARCH="arm64"
export KBUILD_BUILD_HOST=arch
export KBUILD_BUILD_USER=selfmuser
LINUX_COMPILE_BY="selfmuser"
LINUX_COMPILE_HOST="arch"
export PATH="$CLANG_DIR/bin:$PATH"
export CI_BRANCH=$(git rev-parse --abbrev-ref HEAD)
tg_post_msg "<b>Kernel : </b><code>$kernel_name</code>%0A<b>Upstream Version : </b><code>$KERVER</code>%0A<b>Machine : </b><code>$os</code>%0A<b>Cores : </b><code>$cores</code>%0A<b>Time : </b><code>$time</code>%0A<b>Branch : </b><code>$CI_BRANCH</code>%0A<b>Top Commit : </b><code>$COMMIT_HEAD</code>"
if ! [ -d "$TC_DIR" ]; then
echo "Toolchain not found! Cloning to $TC_DIR..."
tg_post_msg "<code>Toolchain not found! Cloning toolchain</code>"
if ! git clone -q --depth=1 --single-branch https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 -b master $TC_DIR; then
echo "Cloning failed! Aborting..."
exit 1
fi
fi
# Colors
NC='\\033[0m'
RED='\\033[0;31m'
LRD='\\033[1;31m'
LGR='\\033[1;32m'
make_defconfig()
{
START=$(date +"%s")
echo -e ${LGR} "########### Generating Defconfig ############${NC}"
make -s ARCH=${ARCH} O=${objdir} ${CONFIG_FILE} -j$(nproc --all)
}
compile()
{
cd ${kernel_dir}
echo -e ${LGR} "######### Compiling kernel #########${NC}"
make -j$(nproc --all) \\
O=out \\
ARCH=${ARCH}\\
CC="ccache clang" \\
CLANG_TRIPLE="aarch64-linux-gnu-" \\
CROSS_COMPILE="aarch64-linux-gnu-" \\
CROSS_COMPILE_ARM32="arm-linux-gnueabi-" \\
LLVM=1 \\
LLVM_IAS=1 \\
2>&1 | tee error.log
}
completion() {
cd ${objdir}
COMPILED_IMAGE=arch/arm64/boot/Image.gz-dtb
COMPILED_DTBO=arch/arm64/boot/dtbo.img
if [[ -f ${COMPILED_IMAGE} && ${COMPILED_DTBO} ]]; then
git clone -q https://github.com/kibria5/AnyKernel3 $anykernel
mv -f $ZIMAGE ${COMPILED_DTBO} $anykernel
cd $anykernel
find . -name "*.zip" -type f
find . -name "*.zip" -type f -delete
zip -r AnyKernel.zip *
# Sign the ZIP file using zipsigner-3.0.jar
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 AnyKernel.zip AnyKernel-signed.zip
mv AnyKernel-signed.zip $zip_name
mv $anykernel/$zip_name $HOME/$zip_name
rm -rf $anykernel
END=$(date +"%s")
DIFF=$(($END - $START))
BUILDTIME=$(echo $((${END} - ${START})) | awk '{print int ($1/3600)" Hours:"int(($1/60)%60)"Minutes:"int($1%60)" Seconds"}')
file_path="$HOME/$zip_name"
url="https://pixeldrain.com/u/$(curl -s -T "$file_path" -u :"$API_KEY" "https://pixeldrain.com/api/file/" | jq -r '.id')"
zip_size=$(du -h $HOME/$zip_name | awk '{print $1}')
tg_post_msg "<b>File Name:</b> <code>$zip_name</code>%0A<b>File Size:</b> <code>$zip_size</code>%0A<b>Download Link:</b> <a href='${url}'>Click Here</a>%0A<b>Build Time: $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)</b>"
echo
echo -e ${LGR} "############################################"
echo -e ${LGR} "############# OkThisIsEpic! ##############"
echo -e ${LGR} "############################################${NC}"
else
tg_post_build "$kernel_dir/error.log" "$CHATID" "Debug Mode Logs"
tg_post_msg "<code>Compilation failed</code>"
echo -e ${RED} "############################################"
echo -e ${RED} "## This Is Not Epic :'( ##"
echo -e ${RED} "############################################${NC}"
fi
}
make_defconfig
if [ $? -eq 0 ]; then
tg_post_msg "<code>Defconfig generated successfully</code>"
fi
compile
completion
cd ${kernel_dir}
"""
f.write(s)
f.close()
os.chmod(bashfile, 0o755)
bashcmd=bashfile
for arg in sys.argv[1:]:
bashcmd += ' '+arg
subprocess.call(bashcmd, shell=True)