-
Notifications
You must be signed in to change notification settings - Fork 2
/
0build.sh
executable file
·259 lines (231 loc) · 8.25 KB
/
0build.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
# ===== Variables you should check ======
LOONGREPO=${LOONGREPO:=$HOME/loongarch-packages}
WORKDIR=${WORKDIR:=$HOME/repos}
ZSTLOGDIR=${ZSTLOGDIR:=$HOME/logs}
PACKAGER=${PACKAGER:="LCPU <[email protected]>"}
SCRIPTSPATH=${SCRIPTSPATH:=$HOME/loongshot/scripts}
LOGPATH=/home/arch/loong-status/build_logs # This is for webserver
LOCALREPO=/srv/http/build-repo
if [[ $# -lt 1 ]]; then
echo "Usage: ${0##*/} <pkgbase> [option]"
echo "Option:"
echo " --stag Use staging repo."
echo " --test Use testing repo."
echo " --ver Build a specific version."
echo " --repo core or extra."
echo " --clean Clean the chroot directory."
echo " --builder Build machine to use, default is 'localhost'."
echo " Remote builder syntax is <host>:<workdir>"
echo " --delsrc Delete downloaded and generated files."
echo " --debug Just build the package, don't inform server."
echo " -- Options after this will be passed to makepkg."
exit 1
fi
export LC_ALL=en_US.UTF-8
PKGBASE=$1
shift
TESTING="" # use extra-loong64-build by default
PKGVER=""
CLEAN=""
BUILDER="localhost"
# workdir for the builder
BUILDPATH="/home/arch/repos"
DEBUG=""
source /usr/share/makepkg/util/message.sh
colorize
if [ ! -d "$LOONGREPO" ] || [ ! -d "$WORKDIR" ]; then
error "Please set LOONGREPO and WORKDIR in the source code..."
exit 1
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--stag)
TESTING="-staging"
shift
;;
--test)
TESTING="-testing"
shift
;;
--ver)
shift
PKGVER=$1
shift
;;
--repo)
shift
BUILDREPO=$1
shift
;;
--clean)
CLEAN="-c"
shift
;;
--debug)
DEBUG="yes"
shift
;;
--builder)
shift
BUILDER=${1%:*}
BP=${1#*:}
if [[ "$BP" != "$BUILDER" ]]; then
BUILDPATH="$BP"
fi
shift
;;
--delsrc)
NOKEEP="--delete --delete-excluded"
shift
;;
--)
shift
break
;;
*)
shift
;;
esac
done
EXTRAARG="$@"
build_package() {
# packages beloong only to loong
if [[ -f $LOONGREPO/$PKGBASE/PKGBUILD ]]; then
cp $LOONGREPO/$PKGBASE $WORKDIR/ -a
cd $WORKDIR/$PKGBASE
PKGNAME=$(. PKGBUILD; echo $pkgname)
else
# clone arch package repo
if [[ -d $WORKDIR/$PKGBASE ]]; then
cd $WORKDIR/$PKGBASE
pkgctl repo switch main -f
git pull 2>&1 || return
else
cd $WORKDIR 2>&1 || return
pkgctl repo clone --protocol=https $PKGBASE 2>&1 || return
cd $PKGBASE
fi
PKGNAME=$(. PKGBUILD; echo $pkgname)
if [[ -z "$PKGVER" ]]; then
# get the release tag from x86_64's repo
if [[ ! -z "$TESTING" ]]; then
REPOSWITCH=-${TESTING%ing}
fi
PKGVER=`$SCRIPTSPATH/compare86.py $REPOSWITCH -p $PKGNAME |grep x86_64|awk -F= '{print $2}'`
fi
# switch to the current release tag
if [[ ! -z "$PKGVER" ]]; then
if ! pkgctl repo switch ${PKGVER//:/-}; then
msg "Release tag could not be found."
return
fi
fi
# apply patch
if [[ -d "$LOONGREPO/$PKGBASE" ]]; then
if ! patch -Np1 -i $LOONGREPO/$PKGBASE/loong.patch; then
msg "Fail to apply loong's patch."
return
fi
# copy additional files
find $LOONGREPO/$PKGBASE -type f -name "*" ! -name "loong.patch" -exec cp {} . \;
msg "Loong's patch applied."
fi
fi
# package may not in arch's repo
if [[ -z "$PKGVER" ]]; then
PKGVERREL=$(source PKGBUILD; echo $epoch${epoch:+:}$pkgver-$pkgrel)
else
PKGVERREL=$PKGVER
fi
if [[ -z "$BUILDREPO" ]]; then
BUILDREPO=$($SCRIPTSPATH/compare86.py $REPOSWITCH -p $PKGNAME | awk '{print $5}' | tail -1)
BUILDREPO=${BUILDREPO%-staging}
fi
if grep -qFx "$PKGBASE" $SCRIPTSPATH/trueany.lst; then
MIRRORSITE=https://mirrors.pku.edu.cn/archlinux
cd $LOCALREPO/temp-$BUILDREPO$TESTING/os/loong64
(source $WORKDIR/$PKGBASE/PKGBUILD;
for pkg in ${pkgname[@]}; do
FILENAME=$pkg-$PKGVERREL-any.pkg.tar.zst
wget $MIRRORSITE/$BUILDREPO$TESTING/os/x86_64/$FILENAME
wget $MIRRORSITE/$BUILDREPO$TESTING/os/x86_64/$FILENAME.sig
repo-add -R temp-$BUILDREPO$TESTING.db.tar.gz $FILENAME
done)
return 2
fi
# Try to find the pkgver from tier0 server
_PKGVER=$($SCRIPTSPATH/compare86.py -sTp $PKGNAME | grep "$BUILDREPO$TESTING of loong64 with ver=$PKGVERREL" | awk -F= '{print $2}')
if [[ ! -z "$_PKGVER" ]]; then
# Same package found in server. Incrementing point pkgrel...
PKGREL=${_PKGVER#*-}
PKGREL=$(echo $PKGREL + .1 | bc)
sed -i "s/^pkgrel=.*/pkgrel=$PKGREL/" PKGBUILD
PKGVERREL=${PKGVERREL%-*}-$PKGREL
fi
# for rust packages, $CARCH need to change to `uname -m`=loongarch64
sed -i '/cargo fetch/s/\$CARCH\|\${CARCH}\|x86_64/`uname -m`/' PKGBUILD
# When use cpython, $CARCH also need to chage to `uname -m`
sed -i 's/\$CARCH-cpython-\|\${CARCH}-cpython-/`uname -m`-cpython-/g; s/lib\.linux-x86_64-cpython/lib.linux-`uname -m`-cpython/' PKGBUILD
# More lua packages are building with luarocks, so..
sed -i 's/linux-\$CARCH.rock/linux-`uname -m`.rock/g' PKGBUILD
# insert two lines of code after cd to the source.
update_config() {
cd $WORKDIR/$PKGBASE
sed -i '/^build()/,/configure/ {/^[[:space:]]*cd[[:space:]]\+/ { s/$/\n for c_s in $(find -type f -name config.sub -o -name configure.sub); do cp -f \/usr\/share\/automake-1.1?\/config.sub "$c_s"; done\n for c_g in $(find -type f -name config.guess -o -name configure.guess); do cp -f \/usr\/share\/automake-1.1?\/config.guess "$c_g"; done/; t;};}' PKGBUILD
}
if grep -q "^$PKGBASE$" "$LOONGREPO/update_config"; then
update_config
msg "Updating config.{sub,guess}."
fi
if grep -q "^$PKGBASE$" "$LOONGREPO/ruby_mapping"; then
echo "checkdepends+=(ruby-mapping)" >> PKGBUILD
fi
for arg in ${EXTRAARG[@]}; do
msg "Build with $arg."
done
STARTTIME=$SECONDS
rsync -avzP $WORKDIR/$PKGBASE/ $BUILDER:$BUILDPATH/$PKGBASE/ $NOKEEP --exclude=.*
if [[ ! $? -eq 0 ]]; then
msg "Can't copy PKGBUILD to builder."
return
fi
ssh -t $BUILDER "cd $BUILDPATH/$PKGBASE; PACKAGER=\"$PACKAGER\" extra$TESTING-loong64-build $CLEAN -- -- -A -L $EXTRAARG" 2>/dev/null
EXITCODE=$?
ENDTIME=$SECONDS
TIMECOST=$((ENDTIME - STARTTIME))
# add the zst file to the local-repo
if [[ "$EXITCODE" -eq 0 ]]; then
(source PKGBUILD;
if [[ "$arch" == "any" ]]; then
ARCH="any"
else
ARCH="loong64"
fi
cd $LOCALREPO/temp-$BUILDREPO$TESTING/os/loong64
for pkg in ${pkgname[@]}; do
FILENAME=$pkg-$PKGVERREL-$ARCH.pkg.tar.zst
ssh -t $BUILDER "cd $BUILDPATH/$PKGBASE; [[ -f $FILENAME.sig ]] && rm $FILENAME.sig; gpg --detach-sign $FILENAME"
scp $BUILDER:$BUILDPATH/$PKGBASE/$FILENAME{,.sig} .
chmod 664 $FILENAME{,.sig}
repo-add -R temp-$BUILDREPO$TESTING.db.tar.gz $FILENAME
done)
msg "$PKGBASE-$PKGVERREL built on $BUILDER, time cost: $TIMECOST"
else
msg "$PKGBASE-$PKGVERREL failed on $BUILDER, time cost: $TIMECOST"
fi
}
build_package | tee all.log
if [[ ${PIPESTATUS[0]} -eq 2 ]] || [[ "$DEBUG" == "yes" ]]; then
exit 1
else
# 1. mkdir for log. 2. upload. 3. parse the log
mkdir -p $LOGPATH/$PKGBASE
cp all.log $LOGPATH/$PKGBASE/
parselog.py $PKGBASE
if [[ -f $WORKDIR/$PKGBASE/PKGBUILD ]]; then
PKGVERREL=$(source $WORKDIR/$PKGBASE/PKGBUILD; echo $epoch${epoch:+:}$pkgver-$pkgrel)
mkdir -p $ZSTLOGDIR/$PKGBASE
mv all.log $ZSTLOGDIR/$PKGBASE/$PKGBASE-$PKGVERREL.log
fi
fi