2014-05-28 01:34:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-06-14 01:25:09 +02:00
|
|
|
# This script serves two purposes. First, it can bootstrap the standalone
|
|
|
|
# Blueprint to generate the minibp binary. To do this simply run the script
|
|
|
|
# with no arguments from the desired build directory.
|
|
|
|
#
|
|
|
|
# It can also be invoked from another script to bootstrap a custom Blueprint-
|
|
|
|
# based build system. To do this, the invoking script must first set some or
|
|
|
|
# all of the following environment variables, which are documented below where
|
|
|
|
# their default values are set:
|
|
|
|
#
|
|
|
|
# BOOTSTRAP
|
|
|
|
# SRCDIR
|
2015-07-14 03:11:49 +02:00
|
|
|
# BUILDDIR
|
2014-06-14 01:25:09 +02:00
|
|
|
# BOOTSTRAP_MANIFEST
|
|
|
|
# GOROOT
|
|
|
|
# GOOS
|
|
|
|
# GOARCH
|
|
|
|
# GOCHAR
|
|
|
|
#
|
|
|
|
# The invoking script should then run this script, passing along all of its
|
|
|
|
# command line arguments.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2015-06-24 02:21:00 +02:00
|
|
|
EXTRA_ARGS=""
|
|
|
|
|
2014-06-14 01:25:09 +02:00
|
|
|
# BOOTSTRAP should be set to the path of the bootstrap script. It can be
|
|
|
|
# either an absolute path or one relative to the build directory (which of
|
|
|
|
# these is used should probably match what's used for SRCDIR).
|
|
|
|
[ -z "$BOOTSTRAP" ] && BOOTSTRAP="${BASH_SOURCE[0]}"
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
# SRCDIR should be set to the path of the root source directory. It can be
|
|
|
|
# either an absolute path or a path relative to the build directory. Whether
|
2014-06-14 01:25:09 +02:00
|
|
|
# its an absolute or relative path determines whether the build directory can
|
|
|
|
# be moved relative to or along with the source directory without re-running
|
|
|
|
# the bootstrap script.
|
|
|
|
[ -z "$SRCDIR" ] && SRCDIR=`dirname "${BOOTSTRAP}"`
|
|
|
|
|
2015-07-14 03:11:49 +02:00
|
|
|
# BUILDDIR should be set to the path to store build results. By default, this
|
|
|
|
# is the current directory, but it may be set to an absolute or relative path.
|
|
|
|
[ -z "$BUILDDIR" ] && BUILDDIR=.
|
|
|
|
|
2015-06-11 01:55:02 +02:00
|
|
|
# TOPNAME should be set to the name of the top-level Blueprints file
|
|
|
|
[ -z "$TOPNAME" ] && TOPNAME="Blueprints"
|
|
|
|
|
2014-06-14 01:25:09 +02:00
|
|
|
# BOOTSTRAP_MANIFEST is the path to the bootstrap Ninja file that is part of
|
|
|
|
# the source tree. It is used to bootstrap a build output directory from when
|
|
|
|
# the script is run manually by a user.
|
|
|
|
[ -z "$BOOTSTRAP_MANIFEST" ] && BOOTSTRAP_MANIFEST="${SRCDIR}/build.ninja.in"
|
|
|
|
|
|
|
|
# These variables should be set by auto-detecting or knowing a priori the host
|
|
|
|
# Go toolchain properties.
|
|
|
|
[ -z "$GOROOT" ] && GOROOT=`go env GOROOT`
|
|
|
|
[ -z "$GOOS" ] && GOOS=`go env GOHOSTOS`
|
|
|
|
[ -z "$GOARCH" ] && GOARCH=`go env GOHOSTARCH`
|
|
|
|
[ -z "$GOCHAR" ] && GOCHAR=`go env GOCHAR`
|
|
|
|
|
2015-06-24 02:21:00 +02:00
|
|
|
# If RUN_TESTS is set, behave like -t was passed in as an option.
|
|
|
|
[ ! -z "$RUN_TESTS" ] && EXTRA_ARGS="$EXTRA_ARGS -t"
|
|
|
|
|
2015-08-02 00:07:27 +02:00
|
|
|
GOTOOLDIR="$GOROOT/pkg/tool/${GOOS}_$GOARCH"
|
|
|
|
GOCOMPILE="$GOTOOLDIR/${GOCHAR}g"
|
|
|
|
GOLINK="$GOTOOLDIR/${GOCHAR}l"
|
|
|
|
|
|
|
|
if [ ! -f $GOCOMPILE ]; then
|
|
|
|
GOCOMPILE="$GOTOOLDIR/compile"
|
|
|
|
fi
|
|
|
|
if [ ! -f $GOLINK ]; then
|
|
|
|
GOLINK="$GOTOOLDIR/link"
|
|
|
|
fi
|
|
|
|
if [[ ! -f $GOCOMPILE || ! -f $GOLINK ]]; then
|
|
|
|
echo "Cannot find go tools under $GOROOT"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-06-14 01:25:09 +02:00
|
|
|
usage() {
|
|
|
|
echo "Usage of ${BOOTSTRAP}:"
|
|
|
|
echo " -h: print a help message and exit"
|
|
|
|
echo " -r: regenerate ${BOOTSTRAP_MANIFEST}"
|
2015-06-24 02:21:00 +02:00
|
|
|
echo " -t: include tests when regenerating manifest"
|
2014-06-14 01:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse the command line flags.
|
|
|
|
IN="$BOOTSTRAP_MANIFEST"
|
|
|
|
REGEN_BOOTSTRAP_MANIFEST=false
|
2015-07-14 03:11:49 +02:00
|
|
|
while getopts ":b:hi:rt" opt; do
|
2014-06-14 01:25:09 +02:00
|
|
|
case $opt in
|
2015-07-14 03:11:49 +02:00
|
|
|
b) BUILDDIR="$OPTARG";;
|
2014-06-14 01:25:09 +02:00
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
i) IN="$OPTARG";;
|
|
|
|
r) REGEN_BOOTSTRAP_MANIFEST=true;;
|
2015-06-24 02:21:00 +02:00
|
|
|
t) EXTRA_ARGS="$EXTRA_ARGS -t";;
|
2014-06-14 01:25:09 +02:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $REGEN_BOOTSTRAP_MANIFEST = true ]; then
|
|
|
|
# This assumes that the script is being run from a build output directory
|
|
|
|
# that has been built in the past.
|
2015-07-14 03:11:49 +02:00
|
|
|
if [ -x $BUILDDIR/.bootstrap/bin/minibp ]; then
|
2014-06-14 01:25:09 +02:00
|
|
|
echo "Regenerating $BOOTSTRAP_MANIFEST"
|
2015-07-14 03:11:49 +02:00
|
|
|
$BUILDDIR/.bootstrap/bin/minibp $EXTRA_ARGS -o $BOOTSTRAP_MANIFEST $SRCDIR/$TOPNAME
|
2014-06-14 01:25:09 +02:00
|
|
|
else
|
2015-07-14 03:11:49 +02:00
|
|
|
echo "Executable minibp not found at $BUILDDIR/.bootstrap/bin/minibp" >&2
|
2014-06-14 01:25:09 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2015-07-14 03:11:49 +02:00
|
|
|
mkdir -p $BUILDDIR
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
sed -e "s|@@SrcDir@@|$SRCDIR|g" \
|
2015-07-14 03:11:49 +02:00
|
|
|
-e "s|@@BuildDir@@|$BUILDDIR|g" \
|
2014-05-28 01:34:41 +02:00
|
|
|
-e "s|@@GoRoot@@|$GOROOT|g" \
|
2015-08-02 00:07:27 +02:00
|
|
|
-e "s|@@GoCompile@@|$GOCOMPILE|g" \
|
|
|
|
-e "s|@@GoLink@@|$GOLINK|g" \
|
2014-05-28 01:34:41 +02:00
|
|
|
-e "s|@@Bootstrap@@|$BOOTSTRAP|g" \
|
|
|
|
-e "s|@@BootstrapManifest@@|$BOOTSTRAP_MANIFEST|g" \
|
2015-07-14 03:11:49 +02:00
|
|
|
$IN > $BUILDDIR/build.ninja
|