Clean up the bootstrap script a little.
This change makes the bootstrap script take two optional flag-based command line arguments rather than using positional arguments. The -i argument replaces the old positional arguments (one of which was simply not needed), and the -r flag now causes the script to regenerate the bootstrap Ninja file for use when working on Blueprint itself. Additionally this change allows all the configuration variables used in the script to be overridden by environment variables. This makes it possible to create a very simple bootstrap script for a customized Blueprint-based build system by invoking this script after setting up the proper environment variables. Change-Id: I60f890061ae237a68719e1e2d345d1a8e87c851c
This commit is contained in:
parent
d4e1018e19
commit
7330a23887
3 changed files with 84 additions and 22 deletions
|
@ -46,7 +46,7 @@ var (
|
||||||
|
|
||||||
bootstrap = blueprint.StaticRule("bootstrap",
|
bootstrap = blueprint.StaticRule("bootstrap",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "$Bootstrap $in $BootstrapManifest",
|
Command: "$Bootstrap -i $in",
|
||||||
Description: "bootstrap $in",
|
Description: "bootstrap $in",
|
||||||
Generator: true,
|
Generator: true,
|
||||||
})
|
})
|
||||||
|
@ -64,7 +64,7 @@ var (
|
||||||
// This workaround can be avoided entirely by making a simple change
|
// This workaround can be avoided entirely by making a simple change
|
||||||
// to Ninja that would allow it to rebuild the manifest twice rather
|
// to Ninja that would allow it to rebuild the manifest twice rather
|
||||||
// than just once.
|
// than just once.
|
||||||
Command: "$Bootstrap $in && ninja",
|
Command: "$Bootstrap -i $in && ninja",
|
||||||
Description: "re-bootstrap $in",
|
Description: "re-bootstrap $in",
|
||||||
Generator: true,
|
Generator: true,
|
||||||
})
|
})
|
||||||
|
|
100
bootstrap.bash
100
bootstrap.bash
|
@ -1,29 +1,91 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# BOOTSTRAP_MANIFEST
|
||||||
|
# GOROOT
|
||||||
|
# GOOS
|
||||||
|
# GOARCH
|
||||||
|
# GOCHAR
|
||||||
|
#
|
||||||
|
# The invoking script should then run this script, passing along all of its
|
||||||
|
# command line arguments.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# 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]}"
|
||||||
|
|
||||||
# SRCDIR should be set to the path of the root source directory. It can be
|
# 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
|
# either an absolute path or a path relative to the build directory. Whether
|
||||||
# its an absolute or relative path determines whether the build directory can be
|
# its an absolute or relative path determines whether the build directory can
|
||||||
# moved relative to or along with the source directory without re-running the
|
# be moved relative to or along with the source directory without re-running
|
||||||
# bootstrap script.
|
# the bootstrap script.
|
||||||
SRCDIR=`dirname "${BASH_SOURCE[0]}"`
|
[ -z "$SRCDIR" ] && SRCDIR=`dirname "${BOOTSTRAP}"`
|
||||||
|
|
||||||
# BOOTSTRAP should be set to the path of this script. It can be either an
|
# BOOTSTRAP_MANIFEST is the path to the bootstrap Ninja file that is part of
|
||||||
# absolute path or one relative to the build directory (which of these is used
|
# the source tree. It is used to bootstrap a build output directory from when
|
||||||
# should probably match what's used for SRCDIR).
|
# the script is run manually by a user.
|
||||||
BOOTSTRAP="${BASH_SOURCE[0]}"
|
[ -z "$BOOTSTRAP_MANIFEST" ] && BOOTSTRAP_MANIFEST="${SRCDIR}/build.ninja.in"
|
||||||
|
|
||||||
# These variables should be set by auto-detecting or knowing a priori the Go
|
# These variables should be set by auto-detecting or knowing a priori the host
|
||||||
# toolchain properties.
|
# Go toolchain properties.
|
||||||
GOROOT=`go env GOROOT`
|
[ -z "$GOROOT" ] && GOROOT=`go env GOROOT`
|
||||||
GOOS=`go env GOHOSTOS`
|
[ -z "$GOOS" ] && GOOS=`go env GOHOSTOS`
|
||||||
GOARCH=`go env GOHOSTARCH`
|
[ -z "$GOARCH" ] && GOARCH=`go env GOHOSTARCH`
|
||||||
GOCHAR=`go env GOCHAR`
|
[ -z "$GOCHAR" ] && GOCHAR=`go env GOCHAR`
|
||||||
|
|
||||||
case "$#" in
|
usage() {
|
||||||
1) IN="$1";BOOTSTRAP_MANIFEST="$1";;
|
echo "Usage of ${BOOTSTRAP}:"
|
||||||
2) IN="$1";BOOTSTRAP_MANIFEST="$2";;
|
echo " -h: print a help message and exit"
|
||||||
*) IN="${SRCDIR}/build.ninja.in";BOOTSTRAP_MANIFEST="$IN";;
|
echo " -r: regenerate ${BOOTSTRAP_MANIFEST}"
|
||||||
esac
|
}
|
||||||
|
|
||||||
|
# Parse the command line flags.
|
||||||
|
IN="$BOOTSTRAP_MANIFEST"
|
||||||
|
REGEN_BOOTSTRAP_MANIFEST=false
|
||||||
|
while getopts ":hi:r" opt; do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
i) IN="$OPTARG";;
|
||||||
|
r) REGEN_BOOTSTRAP_MANIFEST=true;;
|
||||||
|
\?)
|
||||||
|
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.
|
||||||
|
if [ -x .bootstrap/bin/minibp ]; then
|
||||||
|
echo "Regenerating $BOOTSTRAP_MANIFEST"
|
||||||
|
./.bootstrap/bin/minibp -o $BOOTSTRAP_MANIFEST $SRCDIR/Blueprints
|
||||||
|
else
|
||||||
|
echo "Executable minibp not found at .bootstrap/bin/minibp" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
sed -e "s|@@SrcDir@@|$SRCDIR|g" \
|
sed -e "s|@@SrcDir@@|$SRCDIR|g" \
|
||||||
-e "s|@@GoRoot@@|$GOROOT|g" \
|
-e "s|@@GoRoot@@|$GOROOT|g" \
|
||||||
|
|
|
@ -50,7 +50,7 @@ rule g.bootstrap.cp
|
||||||
description = cp ${out}
|
description = cp ${out}
|
||||||
|
|
||||||
rule g.bootstrap.bootstrap
|
rule g.bootstrap.bootstrap
|
||||||
command = ${g.bootstrap.Bootstrap} ${in} ${g.bootstrap.BootstrapManifest}
|
command = ${g.bootstrap.Bootstrap} -i ${in}
|
||||||
description = bootstrap ${in}
|
description = bootstrap ${in}
|
||||||
generator = true
|
generator = true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue