github.com/colincross/blueprint@v0.0.0-20150626231830-9c067caf2eb5/bootstrap.bash (about) 1 #!/bin/bash 2 3 # 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 13 # SRCDIR 14 # BOOTSTRAP_MANIFEST 15 # GOROOT 16 # GOOS 17 # GOARCH 18 # GOCHAR 19 # 20 # The invoking script should then run this script, passing along all of its 21 # command line arguments. 22 23 set -e 24 25 EXTRA_ARGS="" 26 27 # 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). 30 [ -z "$BOOTSTRAP" ] && BOOTSTRAP="${BASH_SOURCE[0]}" 31 32 # SRCDIR should be set to the path of the root source directory. It can be 33 # either an absolute path or a path relative to the build directory. Whether 34 # its an absolute or relative path determines whether the build directory can 35 # be moved relative to or along with the source directory without re-running 36 # the bootstrap script. 37 [ -z "$SRCDIR" ] && SRCDIR=`dirname "${BOOTSTRAP}"` 38 39 # TOPNAME should be set to the name of the top-level Blueprints file 40 [ -z "$TOPNAME" ] && TOPNAME="Blueprints" 41 42 # BOOTSTRAP_MANIFEST is the path to the bootstrap Ninja file that is part of 43 # the source tree. It is used to bootstrap a build output directory from when 44 # the script is run manually by a user. 45 [ -z "$BOOTSTRAP_MANIFEST" ] && BOOTSTRAP_MANIFEST="${SRCDIR}/build.ninja.in" 46 47 # These variables should be set by auto-detecting or knowing a priori the host 48 # Go toolchain properties. 49 [ -z "$GOROOT" ] && GOROOT=`go env GOROOT` 50 [ -z "$GOOS" ] && GOOS=`go env GOHOSTOS` 51 [ -z "$GOARCH" ] && GOARCH=`go env GOHOSTARCH` 52 [ -z "$GOCHAR" ] && GOCHAR=`go env GOCHAR` 53 54 # If RUN_TESTS is set, behave like -t was passed in as an option. 55 [ ! -z "$RUN_TESTS" ] && EXTRA_ARGS="$EXTRA_ARGS -t" 56 57 usage() { 58 echo "Usage of ${BOOTSTRAP}:" 59 echo " -h: print a help message and exit" 60 echo " -r: regenerate ${BOOTSTRAP_MANIFEST}" 61 echo " -t: include tests when regenerating manifest" 62 } 63 64 # Parse the command line flags. 65 IN="$BOOTSTRAP_MANIFEST" 66 REGEN_BOOTSTRAP_MANIFEST=false 67 while getopts ":hi:rt" opt; do 68 case $opt in 69 h) 70 usage 71 exit 1 72 ;; 73 i) IN="$OPTARG";; 74 r) REGEN_BOOTSTRAP_MANIFEST=true;; 75 t) EXTRA_ARGS="$EXTRA_ARGS -t";; 76 \?) 77 echo "Invalid option: -$OPTARG" >&2 78 usage 79 exit 1 80 ;; 81 :) 82 echo "Option -$OPTARG requires an argument." >&2 83 exit 1 84 ;; 85 esac 86 done 87 88 if [ $REGEN_BOOTSTRAP_MANIFEST = true ]; then 89 # This assumes that the script is being run from a build output directory 90 # that has been built in the past. 91 if [ -x .bootstrap/bin/minibp ]; then 92 echo "Regenerating $BOOTSTRAP_MANIFEST" 93 ./.bootstrap/bin/minibp $EXTRA_ARGS -o $BOOTSTRAP_MANIFEST $SRCDIR/$TOPNAME 94 else 95 echo "Executable minibp not found at .bootstrap/bin/minibp" >&2 96 exit 1 97 fi 98 fi 99 100 sed -e "s|@@SrcDir@@|$SRCDIR|g" \ 101 -e "s|@@GoRoot@@|$GOROOT|g" \ 102 -e "s|@@GoOS@@|$GOOS|g" \ 103 -e "s|@@GoArch@@|$GOARCH|g" \ 104 -e "s|@@GoChar@@|$GOCHAR|g" \ 105 -e "s|@@Bootstrap@@|$BOOTSTRAP|g" \ 106 -e "s|@@BootstrapManifest@@|$BOOTSTRAP_MANIFEST|g" \ 107 $IN > build.ninja