]> git.pld-linux.org Git - projects/cleanbuild.git/blame - cleanbuild
find pkgconfig for python builds
[projects/cleanbuild.git] / cleanbuild
CommitLineData
82208ca0 1#!/usr/bin/sudo /bin/sh
2
82208ca0 3RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
4DEST="th"
11aa2a39 5SRC="-n th-x86_64-test"
82208ca0 6SUFFIX=""
7CACHEDIR="$PWD/poldekcache"
08b388ad 8RPMMACROS=""
9BUILDERRC=""
febc90ba 10IGNORE=""
5cff6047 11CHROOTSIZE="4G"
3cb48d43 12ignore() { IGNORE="$IGNORE $*"; }
311d51c7 13NODEBUG=true
5e0e7403 14CLEANAFTER=false
15FORCE_UMOUNT=false
c8aae0a1 16NOREBUILDDB=true
646fa345
ER
17# Whatever you set here as value, consider that it may not be shorter than
18# /usr/lib/debug (or /usr/src/debug) for debuginfo to work.
19# You get "Only dest dir longer than base dir not supported" error otherwise.
20BUILDDIR=/usr/src/BUILD
82208ca0 21
cca1186a 22[ -r .cleanbuildrc ] && . ./.cleanbuildrc
23
24[ -z "$USER" ] && echo "USER not defined" && exit 1
e02fff67 25[ "$USER" = "root" ] && echo "USER must not be root" && exit 1
82208ca0 26
27export LC_ALL=C
28unset LANGUAGE
29unset LANG
30
31usage() {
32 [ $# -gt 0 ] && echo "$*"
33 echo "Usage:"
34 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
35 echo " ./build [cleanbuild options] specname [builder options]"
36 echo " ./clean [cleanbuild options]"
febc90ba 37 echo " ./create [cleanbuild options]"
82208ca0 38 echo " ./install [cleanbuild options] packages"
39 echo ""
40 echo "cleanbuild options:"
41 echo " -32, -64, -th-i486 - select architecture"
91d5d67b 42 echo " --cleanafter | -ca - clean after build"
5e0e7403 43 echo " --forceumount | -fu - force umount tmpfs"
91d5d67b 44 echo " --debug - enable debug"
3cc55bb0 45 echo " -a, -b, -c, -d, -e - select alternative chroot directory"
82208ca0 46 exit 1
47}
48
49FETCH=false
50CLEAN=false
febc90ba 51CREATE=false
82208ca0 52BUILD=false
53INSTALL=false
82208ca0 54
55case "$0" in
febc90ba 56 *clean)
57 CLEAN=exit_after
58 ;;
82208ca0 59 *cleanbuild)
60 FETCH=true
61 CLEAN=true
febc90ba 62 CREATE=true
82208ca0 63 BUILD=true
64 ;;
82208ca0 65 *build)
febc90ba 66 CREATE=true
82208ca0 67 BUILD=true
68 ;;
febc90ba 69 *create)
82208ca0 70 CLEAN=true
febc90ba 71 CREATE=exit_after
82208ca0 72 ;;
73 *install)
febc90ba 74 CREATE=true
75 INSTALL=exit_after
82208ca0 76 ;;
77 *)
78 usage
79 ;;
80esac
81
82while [ $# -gt 0 ]; do
83 OPT="${1}"
84 case "$OPT" in
85 -32) OPT="-th-i686" ;;
86 -64) OPT="-th-x86_64" ;;
87 -th-32) OPT="-th-i686" ;;
88 -th-64) OPT="-th-x86_64" ;;
560aa27b 89 -ti-32) OPT="-ti-i686" ;;
90 -ti-64) OPT="-ti-x86_64" ;;
82208ca0 91 -ac) OPT="-ac-amd64" ;;
92 -ac-32) OPT="-ac-i586" ;;
93 -ac-64) OPT="-ac-amd64" ;;
94 esac
95
96 V="${OPT#-}"
97 case "$OPT" in
98 -th-i[46]86 | -th-x86_64)
99 DEST="$V"
11aa2a39 100 SRC="-n $V-ready"
82208ca0 101 ;;
560aa27b 102 -th-i[46]86-test | -th-x86_64-test)
103 DEST="$V"
104 SRC="-n $V"
105 ;;
106 -ti-i[56]86 | -ti-x86_64)
107 DEST="$V"
108 SRC="-n $V-ready"
109 ;;
110 -ti-i[56]86-test | -ti-x86_64-test)
111 DEST="$V"
112 SRC="-n $V"
113 ;;
82208ca0 114 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
115 DEST="$V"
11aa2a39 116 SRC="-n $V-ready"
82208ca0 117 ;;
5cff6047 118 -[1-9]G | -[1-9][0-9]G )
119 CHROOTSIZE="$V"
120 ;;
febc90ba 121 --cleanafter | -ca)
82208ca0 122 CLEANAFTER=true
123 ;;
311d51c7 124 --debug)
125 NODEBUG=false
126 ;;
5e0e7403 127 --forceumount | -fu)
128 FORCE_UMOUNT=true
c6fcd6a8 129 ;;
3cc55bb0 130 -[a-e])
82208ca0 131 SUFFIX="$OPT"
132 ;;
133 -~*)
134 SUFFIX="$V"
135 ;;
136 *)
137 break
138 ;;
139 esac
140 shift
141done
142
143if $BUILD; then
144 [ $# -ne 0 ] || usage
145 build_pkg="${1}"
6361ea4c 146 build_pkg="${build_pkg%/}"
147 build_pkg="${build_pkg%.spec}"
148 build_pkg="${build_pkg#*/}"
82208ca0 149 shift
150
151 builder_options="$*"
152fi
153
311d51c7 154$NODEBUG || set -x
155
febc90ba 156CHNAME="chroot-$DEST$SUFFIX"
157CHDIR="$PWD/$CHNAME"
158CHHOME="/home/users/$USER"
159
160warn()
161{
82208ca0 162 echo -n -e "\033[31;1m" >&2
163 echo -n "$*" >&2
164 echo -e "\033[0m" >&2
165}
febc90ba 166
167die()
168{
82208ca0 169 code=$1
170 shift
171 warn "$*"
172 exit $code
173}
febc90ba 174
175info()
176{
82208ca0 177 echo -n -e "\033[32m"
178 echo -n "$*"
179 echo -e "\033[0m"
180}
febc90ba 181
182title()
183{
82208ca0 184 [ -t 1 ] || return 0
185 local msg="$CHNAME: $build_pkg: $*"
186 case "$TERM" in
187 cygwin|xterm*)
188 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
189 ;;
190 screen*)
191 echo -ne "\033]0;$msg\007" >&2
192 ;;
193 esac
194 return 0
195}
196
febc90ba 197exit_after()
198{
199 return 0;
200}
82208ca0 201
febc90ba 202check_running()
203{
82208ca0 204 [ -r "$CHDIR/.pid" ] || return
205 PID=$(< "$CHDIR/.pid")
206 if [ -d /proc/$PID ]; then
207 die 10 "Another process ($PID) already running in $CHNAME"
208 fi
209}
210
82208ca0 211for D in installed buildlogs $CACHEDIR; do
212 if [ ! -d "$D" ]; then
febc90ba 213 info "mkdir $D"
82208ca0 214 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
215 fi
216done
217
82208ca0 218ignore \
219 vserver-packages \
220 upstart\* \
aa0c3fdf
ER
221 compat-\* \
222 systemd-init \
223 kmod \
82208ca0 224 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
225 xorg-data-xbitmaps \
226 compat-gcc\* \
227 libpng1\* \
b66f1de3 228 libjpeg libjpeg-devel \
932132fc 229 freetype1-devel-* \
82208ca0 230 anacron fcron hc-cron \
231 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
232 ghostscript-esp \
b66f1de3 233 perl-Scalar-List-Utils \
a395dfc5 234 perl-ExtUtils-Install \
82208ca0 235 \*-multilib-\* \
3cb48d43 236 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
82208ca0 237
238
febc90ba 239rebuilddb()
240{
c8aae0a1 241 $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
82208ca0 242}
243
febc90ba 244poldek()
245{
311d51c7 246 $NODEBUG || set -x
82208ca0 247 rebuilddb
11aa2a39 248 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
82208ca0 249}
250
251
febc90ba 252build_umount()
253{
82208ca0 254 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
255 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
256 done
257}
258
febc90ba 259build_remove_root()
260{
714fcf38 261 $NODEBUG || set -x
5e0e7403 262 if $FORCE_UMOUNT; then
c6fcd6a8 263 # safety checks.
264 [ "$CHDIR" ] || exit 1
265 [ -d "$CHDIR" ] || exit 1
266 rm -rf $CHDIR/*
267 umount -l $CHDIR
268 else
269 umount $CHDIR
270 fi
82208ca0 271 rmdir $CHDIR
272}
273
febc90ba 274clean()
275{
82208ca0 276 info "Cleaning $CHNAME"
7bf0c1e6 277 title "cleaning chroot"
82208ca0 278 build_umount
279 build_remove_root
82208ca0 280}
281
febc90ba 282build_prepare_root()
283{
7bf0c1e6 284 title "preparing chroot"
82208ca0 285 set -e
311d51c7 286 $NODEBUG || set -x
82208ca0 287 mkdir $CHDIR
5cff6047 288 mount -t tmpfs -o size=$CHROOTSIZE,relatime /dev/null $CHDIR
82208ca0 289 echo $$ > $CHDIR/.pid
290
ef4e7e6c
ER
291 rpmversion=$(rpm -E '%(v=%{_rpmversion}; IFS=.; set -- $v; echo $1)')
292 rpmversion=${rpmversion:-4}
293
294 if [ "$rpmversion" -ge 5 ]; then
295 rpm --root=$CHDIR -qa
296 else
297 rpm --root=$CHDIR --initdb
298 fi
82208ca0 299 poldek --up || :
b66f1de3 300 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils util-linux git-core gawk
abb791ce 301 echo Poldek exit: $?
82208ca0 302
303 for DIR in dev proc sys; do
49e71696 304 # We need to create these directories manually, because they are marked
305 # as netsharedpath in cleanbuild poldek.conf
306 mkdir $CHDIR/$DIR
82208ca0 307 mount -o bind /$DIR $CHDIR/$DIR
308 done
309
750858a5
ER
310 chroot $CHDIR groupadd $(id $USER -gn) -g$(id $USER -g)
311 chroot $CHDIR useradd -m $USER -u$(id $USER -u) -g $(id $USER -gn)
b259c625 312
313 # replicate files which already belong to $USER
314 # so they will have correct owner and permissions
82208ca0 315 cp -a $CHDIR/$CHHOME/{tmp,rpm}
646fa345 316 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
b259c625 317
82208ca0 318 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
646fa345
ER
319 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
320 %_builddir $BUILDDIR
82208ca0 321 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
11aa2a39 322 %_rpmdirname cleanRPMS
323 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
82208ca0 324 %distribution CleanPLD
325 %_binary_payload w1.gzdio
326EOM
08b388ad 327 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
b259c625 328
329 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
82208ca0 330 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
331 TITLECHANGE=no
332EORC
08b388ad 333 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
334
82208ca0 335 set +e
336}
337
febc90ba 338build_mount_home()
339{
311d51c7 340 $NODEBUG || set -x
82208ca0 341 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
342}
343
82208ca0 344
febc90ba 345print_installed()
346{
82208ca0 347 echo=$1
348 if [ -r installed/$build_pkg ]; then
349 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
350 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
351 cat installed/$build_pkg
352 fi
353}
354
febc90ba 355addlist()
356{
82208ca0 357 LIST="$1"
358
359 print_installed info
11aa2a39 360
361 return
82208ca0 362 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
363 print_installed echo >> $LIST
364}
365
febc90ba 366builddie()
367{
82208ca0 368 LIST="$1"; shift
369 CODE="$1"; shift
370 MSG="$*"
371
febc90ba 372 rm -f $CHDIR/.pid
373
82208ca0 374 $CLEANAFTER && clean
375 title "failed !"
376
377 addlist "ERROR_$LIST"
378 die $CODE "$MSG"
379}
380
381LAST_INSTALL=""
febc90ba 382poldek_install()
383{
82208ca0 384 I="$1";
385 # Nothing to install
386 [ -n "$I" ] || return 1
387 # Installing same packets second time
388 [ "$LAST_INSTALL" != "$I" ] || return 1
389 LAST_INSTALL="$I"
390
391 info "Installing" $I
392 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
393 ret=
394 if grep -q "Preparing... ##################################################" $$.poldek_install \
395 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
396 then
397 info "Poldek:" $I "installed"
398 ret=0
399 elif grep -q "Nothing to do" $$.poldek_install; then
400 warn "Poldek:" $I "installed already"
401 ret=1
402 fi
403 rm $$.poldek_install
404 [ -n "$ret" ] && return $ret
405
406 # try harder
407 poldek -u $I && return 0
408 poldek -u $I && return 0
409 warn "Poldek:" "Could not install" $I
410 return 1
411}
412
febc90ba 413maybe_call()
414{
415 local cond="$1"; shift
416 local func="$1"; shift
417
e02fff67 418 [ $cond = "false" ] && return
febc90ba 419 $func "$@"
e02fff67 420 [ $cond = "exit_after" ] && exit
febc90ba 421}
422
423fetch()
424{
425 info "Fetching $build_pkg"
426 title "fetch"
311d51c7 427 $NODEBUG || set -x
febc90ba 428 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
429 || die 11 "Fetch failed"
430}
431
432create()
433{
311d51c7 434 $NODEBUG || set -x
febc90ba 435 su $USER -c "poldek -s $RPMS_FROM --mkidx"
436
437 if [ ! -d $CHDIR ]; then
438 info "Preparing $CHNAME"
439 build_prepare_root
440 build_mount_home
441 fi
442}
443
444
abb791ce
ER
445info "Configured Poldek sources"
446poldek -l
447
febc90ba 448maybe_call $FETCH fetch
449
450check_running
451
452maybe_call $CLEAN clean
453
454maybe_call $CREATE create
455
456echo $$ > $CHDIR/.pid
457
458maybe_call $INSTALL poldek_install "$*"
459
460$BUILD || exit
461
462if [ -p /tmp/fixfreq ]; then
463 echo $$ > /tmp/fixfreq
82208ca0 464fi
465
466while true; do
467 info "Building $build_pkg in $CHNAME"
468 rebuilddb
71469ba3 469 find $CHDIR/usr/lib{,64} -name "*.la" -print0 | \
1595b5d5 470 xargs -0 -r sed -i -e "s@dependency_libs=.*@dependency_libs=' '@"
82208ca0 471 buildlog="buildlogs/$build_pkg"
472 if [ -r $buildlog ]; then
473 i=1
474 while [ -r $buildlog.$i ]; do
475 i=$((i+1))
476 done
477 info "moving $buildlog to $buildlog.$i"
478 mv $buildlog $buildlog.$i
479 fi
11aa2a39 480 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
82208ca0 481 title "building"
7bb76476 482 ./teeboth $buildlog chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options"
483 ECODE=$?
82208ca0 484
485 if grep -q "error: Failed build dependencies:" $buildlog; then
486 SEARCH=$(cat $buildlog | awk '/^Error:/ { p = 0 }; { if ( p ) { f="p"; if ( $1 ~ /^\// ) f="f"; printf "search -%c %s; ", f, $1; } }; /error: Failed build dependencies:/ { p = 1 }')
487 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
488
489 if poldek_install "$INSTALL"; then
490 info "Deps installed"
491 continue
492 else
493 addlist ERROR_BRINSTALL
494 die 4 "Cannot install BRs"
495 fi
496 fi
497
f34b364a 498 ./findbr $CHDIR/$BUILDDIR $buildlog > $$.installed
82208ca0 499 installed_something=false
500 while read pkg msg; do
501 if poldek_install $pkg; then
502 info "findbr:" $pkg "installed"
503 echo "$pkg $msg" >> installed/$build_pkg
504 ./addbr $build_pkg "$pkg" "$msg"
505 installed_something=true
506 else
507 warn "findbr:" $pkg "not installed"
508 fi
509 done < $$.installed
510 rm -f $$.installed
511 $installed_something && continue
512
513 if [ $ECODE -eq 0 ]; then
514 $CLEANAFTER && clean
515 addlist BUILT_OK
11aa2a39 516 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
82208ca0 517 info "$build_pkg built OK !"
518 title "OK !"
519 exit 0
520 else
521 builddie UNKNOWN 1 "Got error but dunno what to do !"
522 fi
523done
524
525
526# vim: ts=4 sw=4 filetype=sh
This page took 0.15689 seconds and 4 git commands to generate.