Home | History | Annotate | Download | only in blueprint
      1 #!/bin/bash
      2 
      3 # This script is intented to wrap the execution of ninja so that we
      4 # can do some checks before each ninja run.
      5 #
      6 # It can either be run with a standalone Blueprint checkout to generate
      7 # the minibp binary, or can be used by another script as part of a custom
      8 # Blueprint-based build system. When used by another script, the following
      9 # environment variables can be set to configure this script, which are
     10 # documented below:
     11 #
     12 #   BUILDDIR
     13 #   SKIP_NINJA
     14 #
     15 # When run in a standalone Blueprint checkout, bootstrap.bash will install
     16 # this script into the $BUILDDIR, where it may be executed.
     17 #
     18 # For embedding into a custom build system, the current directory when this
     19 # script executes should be the same directory that $BOOTSTRAP should be
     20 # called from.
     21 
     22 set -e
     23 
     24 # BUILDDIR should be set to the path to store build results. By default,
     25 # this is the directory containing this script, but can be set explicitly
     26 # if the custom build system only wants to install their own wrapper.
     27 [ -z "$BUILDDIR" ] && BUILDDIR=`dirname "${BASH_SOURCE[0]}"`
     28 
     29 # NINJA should be set to the path of the ninja executable. By default, this
     30 # is just "ninja", and will be looked up in $PATH.
     31 [ -z "$NINJA" ] && NINJA=ninja
     32 
     33 
     34 if [ ! -f "${BUILDDIR}/.blueprint.bootstrap" ]; then
     35     echo "Please run bootstrap.bash (.blueprint.bootstrap missing)" >&2
     36     exit 1
     37 fi
     38 
     39 # .blueprint.bootstrap provides saved values from the bootstrap.bash script:
     40 #
     41 #   BOOTSTRAP
     42 #   BOOTSTRAP_MANIFEST
     43 #
     44 source "${BUILDDIR}/.blueprint.bootstrap"
     45 
     46 GEN_BOOTSTRAP_MANIFEST="${BUILDDIR}/.minibootstrap/build.ninja.in"
     47 if [ -f "${GEN_BOOTSTRAP_MANIFEST}" ]; then
     48     if [ "${BOOTSTRAP_MANIFEST}" -nt "${GEN_BOOTSTRAP_MANIFEST}" ]; then
     49         "${BOOTSTRAP}" -i "${BOOTSTRAP_MANIFEST}"
     50     fi
     51 else
     52     "${BOOTSTRAP}" -i "${BOOTSTRAP_MANIFEST}"
     53 fi
     54 
     55 # Build minibp and the primary build.ninja
     56 "${NINJA}" -w dupbuild=err -f "${BUILDDIR}/.minibootstrap/build.ninja"
     57 
     58 # Build the primary builder and the main build.ninja
     59 "${NINJA}" -w dupbuild=err -f "${BUILDDIR}/.bootstrap/build.ninja"
     60 
     61 # SKIP_NINJA can be used by wrappers that wish to run ninja themselves.
     62 if [ -z "$SKIP_NINJA" ]; then
     63     "${NINJA}" -w dupbuild=err -f "${BUILDDIR}/build.ninja" "$@"
     64 else
     65     exit 0
     66 fi
     67