blob: b08bf1e169560d9e716f908a2410ccc4dd417468 [file] [log] [blame]
Jamie Gennis1bc967e2014-05-27 16:34:41 -07001#!/bin/bash
2
Jamie Gennis7330a232014-06-13 16:25:09 -07003# This script serves two purposes. First, it can bootstrap the standalone
4# Blueprint to generate the minibp binary. To do this simply run the script
5# with no arguments from the desired build directory.
6#
7# It can also be invoked from another script to bootstrap a custom Blueprint-
8# based build system. To do this, the invoking script must first set some or
9# all of the following environment variables, which are documented below where
10# their default values are set:
11#
12# BOOTSTRAP
Dan Willemsend79f1af2015-12-09 18:03:13 -080013# WRAPPER
Jamie Gennis7330a232014-06-13 16:25:09 -070014# SRCDIR
Dan Willemsen1e723212017-07-18 19:37:37 -070015# BLUEPRINTDIR
Dan Willemsenf0ca9012015-07-13 18:11:49 -070016# BUILDDIR
Dan Willemsencd4e0ce2017-07-19 22:43:30 -070017# NINJA_BUILDDIR
Jamie Gennis7330a232014-06-13 16:25:09 -070018# GOROOT
Jamie Gennis7330a232014-06-13 16:25:09 -070019#
20# The invoking script should then run this script, passing along all of its
21# command line arguments.
22
23set -e
24
Dan Willemsen87ba2942015-06-23 17:21:00 -070025EXTRA_ARGS=""
26
Jamie Gennis7330a232014-06-13 16:25:09 -070027# BOOTSTRAP should be set to the path of the bootstrap script. It can be
28# either an absolute path or one relative to the build directory (which of
29# these is used should probably match what's used for SRCDIR).
Dan Willemsend79f1af2015-12-09 18:03:13 -080030if [ -z "$BOOTSTRAP" ]; then
31 BOOTSTRAP="${BASH_SOURCE[0]}"
32
33 # WRAPPER should only be set if you want a ninja wrapper script to be
34 # installed into the builddir. It is set to blueprint's blueprint.bash
35 # only if BOOTSTRAP and WRAPPER are unset.
36 [ -z "$WRAPPER" ] && WRAPPER="`dirname "${BOOTSTRAP}"`/blueprint.bash"
37fi
Jamie Gennis7330a232014-06-13 16:25:09 -070038
Jamie Gennis1bc967e2014-05-27 16:34:41 -070039# SRCDIR should be set to the path of the root source directory. It can be
40# either an absolute path or a path relative to the build directory. Whether
Jamie Gennis7330a232014-06-13 16:25:09 -070041# its an absolute or relative path determines whether the build directory can
42# be moved relative to or along with the source directory without re-running
43# the bootstrap script.
44[ -z "$SRCDIR" ] && SRCDIR=`dirname "${BOOTSTRAP}"`
Jamie Gennis1bc967e2014-05-27 16:34:41 -070045
Dan Willemsen1e723212017-07-18 19:37:37 -070046# BLUEPRINTDIR should be set to the path to the blueprint source. It generally
47# should start with SRCDIR.
48[ -z "$BLUEPRINTDIR" ] && BLUEPRINTDIR="${SRCDIR}"
49
Dan Willemsenf0ca9012015-07-13 18:11:49 -070050# BUILDDIR should be set to the path to store build results. By default, this
51# is the current directory, but it may be set to an absolute or relative path.
52[ -z "$BUILDDIR" ] && BUILDDIR=.
53
Dan Willemsencd4e0ce2017-07-19 22:43:30 -070054# NINJA_BUILDDIR should be set to the path to store the .ninja_log/.ninja_deps
55# files. By default this is the same as $BUILDDIR.
56[ -z "$NINJA_BUILDDIR" ] && NINJA_BUILDDIR="${BUILDDIR}"
57
Dan Willemsen2527cc62015-06-10 16:55:02 -070058# TOPNAME should be set to the name of the top-level Blueprints file
59[ -z "$TOPNAME" ] && TOPNAME="Blueprints"
60
Jamie Gennis7330a232014-06-13 16:25:09 -070061# These variables should be set by auto-detecting or knowing a priori the host
62# Go toolchain properties.
63[ -z "$GOROOT" ] && GOROOT=`go env GOROOT`
Jamie Gennis1bc967e2014-05-27 16:34:41 -070064
Jamie Gennis7330a232014-06-13 16:25:09 -070065usage() {
66 echo "Usage of ${BOOTSTRAP}:"
67 echo " -h: print a help message and exit"
Dan Willemsen1e723212017-07-18 19:37:37 -070068 echo " -b <builddir>: set the build directory"
69 echo " -t: run tests"
Colin Cross0cdec992020-07-09 14:24:56 -070070 echo " -n: use validations to depend on tests"
Jamie Gennis7330a232014-06-13 16:25:09 -070071}
72
73# Parse the command line flags.
Colin Cross0cdec992020-07-09 14:24:56 -070074while getopts ":b:hnt" opt; do
Jamie Gennis7330a232014-06-13 16:25:09 -070075 case $opt in
Dan Willemsenf0ca9012015-07-13 18:11:49 -070076 b) BUILDDIR="$OPTARG";;
Colin Cross0cdec992020-07-09 14:24:56 -070077 n) USE_VALIDATIONS=true;;
Jeff Gastonc3e28442017-08-09 15:13:12 -070078 t) RUN_TESTS=true;;
Jamie Gennis7330a232014-06-13 16:25:09 -070079 h)
80 usage
81 exit 1
82 ;;
Jamie Gennis7330a232014-06-13 16:25:09 -070083 \?)
84 echo "Invalid option: -$OPTARG" >&2
85 usage
86 exit 1
87 ;;
88 :)
89 echo "Option -$OPTARG requires an argument." >&2
90 exit 1
91 ;;
92 esac
93done
94
Jeff Gastonc3e28442017-08-09 15:13:12 -070095# If RUN_TESTS is set, behave like -t was passed in as an option.
96[ ! -z "$RUN_TESTS" ] && EXTRA_ARGS="${EXTRA_ARGS} -t"
97
Colin Cross0cdec992020-07-09 14:24:56 -070098# If $USE_VALIDATIONS is set, pass --use-validations.
99[ ! -z "$USE_VALIDATIONS" ] && EXTRA_ARGS="${EXTRA_ARGS} --use-validations"
100
Dan Willemsendac90d32018-10-25 22:02:10 -0700101# If EMPTY_NINJA_FILE is set, have the primary build write out a 0-byte ninja
102# file instead of a full length one. Useful if you don't plan on executing the
103# build, but want to verify the primary builder execution.
104[ ! -z "$EMPTY_NINJA_FILE" ] && EXTRA_ARGS="${EXTRA_ARGS} --empty-ninja-file"
105
Jeff Gastonc3e28442017-08-09 15:13:12 -0700106# Allow the caller to pass in a list of module files
107if [ -z "${BLUEPRINT_LIST_FILE}" ]; then
108 BLUEPRINT_LIST_FILE="${BUILDDIR}/.bootstrap/bplist"
109fi
110EXTRA_ARGS="${EXTRA_ARGS} -l ${BLUEPRINT_LIST_FILE}"
111
Dan Willemsen7d0dddd2016-08-13 12:42:11 -0700112mkdir -p $BUILDDIR/.minibootstrap
Dan Willemsenf0ca9012015-07-13 18:11:49 -0700113
Dan Willemsen1e723212017-07-18 19:37:37 -0700114echo "bootstrapBuildDir = $BUILDDIR" > $BUILDDIR/.minibootstrap/build.ninja
115echo "topFile = $SRCDIR/$TOPNAME" >> $BUILDDIR/.minibootstrap/build.ninja
116echo "extraArgs = $EXTRA_ARGS" >> $BUILDDIR/.minibootstrap/build.ninja
Dan Willemsencd4e0ce2017-07-19 22:43:30 -0700117echo "builddir = $NINJA_BUILDDIR" >> $BUILDDIR/.minibootstrap/build.ninja
Dan Willemsen1e723212017-07-18 19:37:37 -0700118echo "include $BLUEPRINTDIR/bootstrap/build.ninja" >> $BUILDDIR/.minibootstrap/build.ninja
Dan Willemsend79f1af2015-12-09 18:03:13 -0800119
Dan Willemsenab223a52018-07-05 21:56:59 -0700120if [ ! -f "$BUILDDIR/.minibootstrap/build-globs.ninja" ]; then
121 touch "$BUILDDIR/.minibootstrap/build-globs.ninja"
122fi
123
Jeff Gastonc3e28442017-08-09 15:13:12 -0700124echo "BLUEPRINT_BOOTSTRAP_VERSION=2" > $BUILDDIR/.blueprint.bootstrap
Dan Willemsen1e723212017-07-18 19:37:37 -0700125echo "SRCDIR=\"${SRCDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
126echo "BLUEPRINTDIR=\"${BLUEPRINTDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
Dan Willemsencd4e0ce2017-07-19 22:43:30 -0700127echo "NINJA_BUILDDIR=\"${NINJA_BUILDDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
Dan Willemsen1e723212017-07-18 19:37:37 -0700128echo "GOROOT=\"${GOROOT}\"" >> $BUILDDIR/.blueprint.bootstrap
Jeff Gastonc3e28442017-08-09 15:13:12 -0700129echo "TOPNAME=\"${TOPNAME}\"" >> $BUILDDIR/.blueprint.bootstrap
130
131touch "${BUILDDIR}/.out-dir"
Dan Willemsend79f1af2015-12-09 18:03:13 -0800132
133if [ ! -z "$WRAPPER" ]; then
134 cp $WRAPPER $BUILDDIR/
135fi