github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/blueprint/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  #   WRAPPER
    14  #   SRCDIR
    15  #   BLUEPRINTDIR
    16  #   BUILDDIR
    17  #   NINJA_BUILDDIR
    18  #   GOROOT
    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  if [ -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"
    37  fi
    38  
    39  # 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
    41  # 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}"`
    45  
    46  # BLUEPRINTDIR should be set to the path to the blueprint source. It generally
    47  # should start with SRCDIR.
    48  [ -z "$BLUEPRINTDIR" ] && BLUEPRINTDIR="${SRCDIR}"
    49  
    50  # 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  
    54  # 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  
    58  # TOPNAME should be set to the name of the top-level Blueprints file
    59  [ -z "$TOPNAME" ] && TOPNAME="Blueprints"
    60  
    61  # 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`
    64  
    65  usage() {
    66      echo "Usage of ${BOOTSTRAP}:"
    67      echo "  -h: print a help message and exit"
    68      echo "  -b <builddir>: set the build directory"
    69      echo "  -t: run tests"
    70  }
    71  
    72  # Parse the command line flags.
    73  while getopts ":b:ht" opt; do
    74      case $opt in
    75          b) BUILDDIR="$OPTARG";;
    76          t) RUN_TESTS=true;;
    77          h)
    78              usage
    79              exit 1
    80              ;;
    81          \?)
    82              echo "Invalid option: -$OPTARG" >&2
    83              usage
    84              exit 1
    85              ;;
    86          :)
    87              echo "Option -$OPTARG requires an argument." >&2
    88              exit 1
    89              ;;
    90      esac
    91  done
    92  
    93  # If RUN_TESTS is set, behave like -t was passed in as an option.
    94  [ ! -z "$RUN_TESTS" ] && EXTRA_ARGS="${EXTRA_ARGS} -t"
    95  
    96  # Allow the caller to pass in a list of module files
    97  if [ -z "${BLUEPRINT_LIST_FILE}" ]; then
    98    BLUEPRINT_LIST_FILE="${BUILDDIR}/.bootstrap/bplist"
    99  fi
   100  EXTRA_ARGS="${EXTRA_ARGS} -l ${BLUEPRINT_LIST_FILE}"
   101  
   102  mkdir -p $BUILDDIR/.minibootstrap
   103  
   104  echo "bootstrapBuildDir = $BUILDDIR" > $BUILDDIR/.minibootstrap/build.ninja
   105  echo "topFile = $SRCDIR/$TOPNAME" >> $BUILDDIR/.minibootstrap/build.ninja
   106  echo "extraArgs = $EXTRA_ARGS" >> $BUILDDIR/.minibootstrap/build.ninja
   107  echo "builddir = $NINJA_BUILDDIR" >> $BUILDDIR/.minibootstrap/build.ninja
   108  echo "include $BLUEPRINTDIR/bootstrap/build.ninja" >> $BUILDDIR/.minibootstrap/build.ninja
   109  
   110  echo "BLUEPRINT_BOOTSTRAP_VERSION=2" > $BUILDDIR/.blueprint.bootstrap
   111  echo "SRCDIR=\"${SRCDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
   112  echo "BLUEPRINTDIR=\"${BLUEPRINTDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
   113  echo "NINJA_BUILDDIR=\"${NINJA_BUILDDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
   114  echo "GOROOT=\"${GOROOT}\"" >> $BUILDDIR/.blueprint.bootstrap
   115  echo "TOPNAME=\"${TOPNAME}\"" >> $BUILDDIR/.blueprint.bootstrap
   116  
   117  touch "${BUILDDIR}/.out-dir"
   118  
   119  if [ ! -z "$WRAPPER" ]; then
   120      cp $WRAPPER $BUILDDIR/
   121  fi