buildgcc: Make package build() function more versatile

Refactor build() to make things more flexible:

Add a parameter that tells if we build a package for the host or for a
target architecture. This is just passed to the build_$package()
function and can be used later to take different steps in each case
(e.g. for bootstrapping a host gcc).

Move .success files into the destination directory. That way we can tell
that a package has been built even if the package build directory has
been removed.

Change-Id: I52a7245714a040d11f6e1ac8bdbff8057bb7f0a1
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/13471
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Nico Huber 2016-01-26 16:09:31 +01:00 committed by Nico Huber
parent b2213edc65
commit 11ea2b378b
1 changed files with 34 additions and 16 deletions

View File

@ -296,39 +296,57 @@ package_uses_targetarch()
fi fi
} }
build() { generic_build()
{
package=$1 package=$1
host_target=$2
builddir=$3
success=$4
fn_exists build_$package || return fn_exists build_$package || return
version="$(eval echo \$$package"_VERSION")" version="$(eval echo \$$package"_VERSION")"
package_uses_targetarch "$package" && \
BUILDDIR=build-${TARGETARCH}-$package || \
BUILDDIR=build-$package
mkdir -p ${BUILDDIR} mkdir -p "$builddir"
is_package_enabled "$package" && \ if [ -f "$success" ]; then
if [ -f ${BUILDDIR}/.success ]; then
printf "Skipping $package as it is already built\n" printf "Skipping $package as it is already built\n"
else else
printf "Building $package $version ... " printf "Building $package $version ... "
DIR=$PWD DIR="$PWD"
cd ${BUILDDIR} cd "$builddir"
rm -f .failed rm -f .failed
build_${package} > build.log 2>&1 build_${package} $host_target > build.log 2>&1
cd $DIR/${BUILDDIR} cd "$DIR"
if [ ! -f .failed ]; then touch .success; fi if [ ! -f "$builddir/.failed" ]; then
cd .. touch "$success";
else
if [ -r "${BUILDDIR}/.failed" ]; then printf "${RED}failed${NC}. Check $builddir/build.log.\n"
printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n"
exit 1 exit 1
fi fi
printf "${green}ok${NC}\n" printf "${green}ok${NC}\n"
fi fi
} }
build_for_host()
{
generic_build $1 host build-$1 "${TARGETDIR}/.$1.success"
}
build_for_target()
{
generic_build $1 target build-${TARGETARCH}-$1 "${TARGETDIR}/.${TARGETARCH}-$1.success"
}
build()
{
if package_uses_targetarch $1; then
build_for_target $1
else
build_for_host $1
fi
}
cleanup() cleanup()
{ {
if [ $SAVETEMPS -ne 0 ]; then if [ $SAVETEMPS -ne 0 ]; then