#!/bin/bash
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: scripts/Build-Target
|
|
# Copyright (C) 2006 - 2009 The OpenSDE Project
|
|
# Copyright (C) 2004 - 2006 The T2 SDE Project
|
|
# Copyright (C) 1998 - 2003 Clifford Wolf
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
#
|
|
# Run this command from the ROCK directory as ./scripts/Build-Target
|
|
# after running the ./scripts/Config and ./scripts/Download commands.
|
|
#
|
|
# It compiles/builds all the packages and stores them tar balls suitable
|
|
# for distribution.
|
|
#
|
|
# This script is the ROCK work-horse. It builds in a chroot environment
|
|
# (stage 2..9) and goes through a number of build stages:
|
|
#
|
|
|
|
config=default
|
|
build_only_this_job=
|
|
daemon_mode=0
|
|
autodownload=1
|
|
options="$*"
|
|
downloadopt="-q"
|
|
|
|
while [ $# -gt 0 ] ; do
|
|
case "$1" in
|
|
-cfg) config=$2 ; shift ;;
|
|
-job) build_only_this_job=$2 ; shift ;;
|
|
-daemon) daemon_mode=1 ;;
|
|
-nodaemon) daemon_mode=0 ;;
|
|
-nodownload) autodownload=0 ;;
|
|
*) echo "Usage: $0 [ -daemon ] [ -nodownload ] [ -cfg config ]" \
|
|
"[ -job <stage>-<package> ]" ; exit 1 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
./lib/sde-config/migrate.sh "$config" || exit 1
|
|
|
|
if [ "$daemon_mode" = 1 ] ; then
|
|
. config/$config/config
|
|
echo "Running $0 in the background (messages go to logfile only).."
|
|
echo "Logfile: build/$SDECFG_ID/TOOLCHAIN/logs/build_target.log"
|
|
nohup $0 $options -nodaemon > /dev/null 2> /dev/null < /dev/null &
|
|
exit 0
|
|
fi
|
|
|
|
. lib/functions.in
|
|
. lib/parse-config
|
|
|
|
build_root="$base/build/$SDECFG_ID"
|
|
build_toolchain="$base/build/$SDECFG_ID/TOOLCHAIN"
|
|
build_logs="$build_toolchain/logs" ; mkdir -p "${build_logs}"
|
|
build_pkgs="$build_toolchain/pkgs" ; mkdir -p "${build_root}"
|
|
|
|
if [ "$SDECFG_PARANOIA_CHECK" = 1 ] ; then
|
|
./bin/sde-check-system || exit 1
|
|
fi
|
|
|
|
# Package Build loop - executed by build-target
|
|
#
|
|
pkgloop() {
|
|
local x= y=
|
|
|
|
if [ "$SDECFG_NOBROKENDEPS" = 1 ]; then
|
|
nobrokendeps="-nobrokendeps"
|
|
else
|
|
nobrokendeps=
|
|
fi
|
|
if [ -z "$build_only_this_job" ]; then
|
|
|
|
if [ "`ls ${build_root}/var/adm/logs/*.err 2> /dev/null`" ] ; then
|
|
echo_header "Removing old error logs ..."
|
|
for y in 0 1 2 3 4 5 6 7 8 9; do
|
|
if [ "$SDECFG_RETRY_BROKEN" -eq 1 -o $y -le "$SDECFG_CONTINUE_ON_ERROR_AFTER" ]; then
|
|
for x in ${build_root}/var/adm/logs/$y-*.err ; do
|
|
if [ -f $x ]; then
|
|
echo_status "Removing ${x#$build_root/} ..."
|
|
rm -f $x
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
fi
|
|
if [ "`ls ${build_root}/var/adm/logs/*.out 2> /dev/null`" ] ; then
|
|
echo_header "Removing old output logs ..."
|
|
for x in ${build_root}/var/adm/logs/*.out ; do
|
|
echo_status "Removing ${x#$build_root/} ..."
|
|
rm -f $x
|
|
done
|
|
fi
|
|
|
|
while
|
|
next="`./scripts/Create-PkgQueue \
|
|
-cfg "$config" -single $nobrokendeps`"
|
|
[ "$next" ]
|
|
do
|
|
pkgloop_package $next
|
|
done
|
|
|
|
else
|
|
rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.log"
|
|
rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.err"
|
|
next="$( awk 'BEGIN { FS=" "; }
|
|
$5 == "'${build_only_this_job#*-}'" && \
|
|
$2 ~ /'${build_only_this_job%%-*}'/ \
|
|
{ $1="'${build_only_this_job%%-*}' 0";
|
|
print; exit; }' < config/$config/packages )"
|
|
[ "$next" ] && pkgloop_package $next
|
|
exit 0
|
|
fi
|
|
|
|
local invalidfiles="tmp/invalid-files-$config.lst"
|
|
local pkglst=`mktemp` errors=0; rm -f "$invalidfiles"
|
|
echo_header "Searching for old lingering files ..."
|
|
sed '/^[^X]/d ; s,.*=,,' config/$config/packages | cut -d' ' -f5 |
|
|
if [ $SDECFG_PKGFILE_VER = 1 ] ; then
|
|
while read p; do
|
|
v=$( grep '^Package Name and Version:' \
|
|
build/$SDECFG_ID/var/adm/packages/$p \
|
|
2>/dev/null | cut -f6 -d' ' )
|
|
echo "$p-$v"
|
|
done
|
|
else
|
|
cat
|
|
fi > $pkglst
|
|
for file in $( ls build/$SDECFG_ID/TOOLCHAIN/pkgs/ 2> /dev/null ) ; do
|
|
x="$file"
|
|
case $SDECFG_PKGFILE_TYPE in
|
|
tar.*) x=${x%.$SDECFG_PKGFILE_TYPE} ;;
|
|
none) : ;;
|
|
esac
|
|
if ! grep -qx "$x" $pkglst && ! test "$x" = packages.db ; then
|
|
file="build/$SDECFG_ID/TOOLCHAIN/pkgs/$file"
|
|
echo_error "$file should not be present (now in $invalidfiles)!"
|
|
mkdir -p tmp; echo "$file" >> "$invalidfiles"
|
|
errors=1
|
|
fi
|
|
done
|
|
for dir in build/$SDECFG_ID/var/adm/{cache,cksums,dependencies,descs,flists,md5sums,packages} ; do
|
|
for file in $( ls $dir 2> /dev/null ) ; do
|
|
if [ $SDECFG_PKGFILE_VER = 1 ] ; then
|
|
x="$file-"
|
|
else
|
|
x="$file"
|
|
fi
|
|
if ! grep -q "$x" $pkglst ; then
|
|
echo_error "$dir/$file should not be present (now in $invalidfiles)!"
|
|
mkdir -p tmp; echo "$dir/$file" >> "$invalidfiles"
|
|
errors=1
|
|
fi
|
|
done
|
|
done
|
|
for file in $( ls build/$SDECFG_ID/var/adm/logs/ ) ; do
|
|
x="`echo $file | sed -e 's/^.-//' -e 's/\.log//' -e 's/\.err//' -e s'/\.out//'`"
|
|
if [ $SDECFG_PKGFILE_VER = 1 ] ; then
|
|
x=$x-
|
|
else
|
|
x=$x
|
|
fi
|
|
|
|
if ! grep -q "$x" $pkglst ; then
|
|
file="build/$SDECFG_ID/var/adm/logs/$file"
|
|
echo_error "$file should not be present (now in $invalidfiles)!"
|
|
mkdir -p tmp; echo "$file" >> "$invalidfiles"
|
|
errors=1
|
|
fi
|
|
done
|
|
[ $errors = 0 ] && echo_status "None found."
|
|
rm $pkglst
|
|
}
|
|
|
|
# Process one line of output generated by Create-PkgQueue
|
|
#
|
|
pkgloop_package() {
|
|
for x in stagelevel pkg_depnr pkg_stages pkg_pri pkg_tree \
|
|
pkg_name pkg_ver pkg_prefix pkg_extra
|
|
do eval "$x=\$1" ; shift ; done
|
|
|
|
[ "$build_only_this_job" -a \
|
|
"$stagelevel-$pkg_name" != "$build_only_this_job" ] && return
|
|
|
|
[ $(expr "$pkg_stages" : ".*$stagelevel.*") -eq 0 ] && return
|
|
pkg_laststage=$(echo "$pkg_stages" | sed "s,-,,g; s,.*\(.\),\1,")
|
|
|
|
cmd_root="-root auto"
|
|
[ $stagelevel -gt 1 ] && cmd_root="$cmd_root -chroot"
|
|
|
|
if [ "$pkg_prefix" != "/" ] ; then
|
|
cmd_prefix="-prefix $pkg_prefix"
|
|
else cmd_prefix= ; fi
|
|
|
|
if [ "$autodownload" = 1 ]; then
|
|
./bin/sde-download -cfg $config $downloadopt $pkg_name
|
|
fi
|
|
|
|
cmd_buildpkg="./scripts/Build-Pkg -$stagelevel -cfg $config"
|
|
cmd_buildpkg="$cmd_buildpkg $cmd_root $cmd_prefix $pkg_name"
|
|
|
|
# Execute action handler
|
|
if ! pkgloop_action && \
|
|
[ $stagelevel -le "$SDECFG_CONTINUE_ON_ERROR_AFTER" ] ; then
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.log -a \
|
|
! -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err ]
|
|
then
|
|
echo_header "Package build ended abnormally!"
|
|
echo_error "Usually a package build creates either a *.log"
|
|
echo_error "or a *.err file. Neither the 1st nor the 2nd is"
|
|
echo_error "there. So I'm going to create a *.err file now"
|
|
echo_error "and abort the build process."
|
|
touch ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err
|
|
exit 1
|
|
fi
|
|
|
|
if [ $stagelevel -gt 0 -a $pkg_laststage -eq $stagelevel -a "$SDECFG_PKGFILE_TYPE" != none ]; then
|
|
if [ -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err ]; then
|
|
echo_error "Creation of binary package isn't possible, because the package was not"
|
|
echo_error "built successfully in (at least) the current stage."
|
|
else
|
|
./lib/sde-binary/package.sh --type "$SDECFG_PKGFILE_TYPE" \
|
|
$( if [ "${SDECFG_PKGFILE_VER}" = 1 ]; then echo '--versioned'; fi ) \
|
|
--root "${build_root}" --output "${build_pkgs}" ${pkg_name}
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Action executed by pkgloop(). This function may be redefined
|
|
# before calling pkgloop().
|
|
#
|
|
pkgloop_action() {
|
|
local rc=
|
|
$cmd_buildpkg
|
|
rc=$?
|
|
|
|
if [ -f "config/$config/.stop" ]; then
|
|
rm -f "config/$config/.stop"
|
|
exit 0
|
|
fi
|
|
|
|
return $rc
|
|
}
|
|
|
|
# Try to umount any directories mounted by Build-Pkg -chroot
|
|
# if we are the last process using them.
|
|
#
|
|
umount_chroot() {
|
|
exec 201> /dev/null
|
|
if ! ( cd ${build_logs}; fuser *.log > /dev/null 2>&1 ); then
|
|
echo_status "Unmounting loop mounts ..."
|
|
umount -d -f $build_toolchain/{loop,config,download} 2> /dev/null
|
|
umount -d -f -l $build_toolchain/{loop,config,download} 2> /dev/null
|
|
umount -d -f $build_root/proc 2> /dev/null
|
|
umount -d -f -l $build_root/proc 2> /dev/null
|
|
fi
|
|
}
|
|
|
|
# must trap outside the group command
|
|
trap 'umount_chroot' EXIT
|
|
|
|
{
|
|
ln -sf build_target_$$.log ${build_logs}/build_target.log
|
|
./bin/sde-build-tools -1 -c $config
|
|
_built=0
|
|
for x in $(get_expanded ./target/%/build.sh $targetchain generic); do
|
|
if [ -f $x ]; then
|
|
. $x
|
|
_built=1
|
|
break
|
|
fi
|
|
done
|
|
[ $_built = 1 ] || echo_warning "No target/*/build.sh controlling the build!"
|
|
} 2>&1 201>> "${build_logs}/build_target_$$.log" | \
|
|
tee -a "${build_logs}/build_target_$$.log"
|
|
|