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 22set -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# .blueprint.bootstrap provides saved values from the bootstrap.bash script: 30# 31# BOOTSTRAP 32# BOOTSTRAP_MANIFEST 33# 34# If it doesn't exist, we probably just need to re-run bootstrap.bash, which 35# ninja will do when switching stages. So just skip to ninja. 36if [ -f "${BUILDDIR}/.blueprint.bootstrap" ]; then 37 source "${BUILDDIR}/.blueprint.bootstrap" 38 39 # Pick the newer of .bootstrap/bootstrap.ninja.in or $BOOTSTRAP_MANIFEST, 40 # and copy it to .bootstrap/build.ninja.in 41 GEN_BOOTSTRAP_MANIFEST="${BUILDDIR}/.bootstrap/bootstrap.ninja.in" 42 if [ -f "${GEN_BOOTSTRAP_MANIFEST}" ]; then 43 if [ "${GEN_BOOTSTRAP_MANIFEST}" -nt "${BOOTSTRAP_MANIFEST}" ]; then 44 BOOTSTRAP_MANIFEST="${GEN_BOOTSTRAP_MANIFEST}" 45 fi 46 fi 47 48 # Copy the selected manifest to $BUILDDIR/.bootstrap/build.ninja.in 49 mkdir -p "${BUILDDIR}/.bootstrap" 50 cp "${BOOTSTRAP_MANIFEST}" "${BUILDDIR}/.bootstrap/build.ninja.in" 51 52 # Bootstrap it to $BUILDDIR/build.ninja 53 "${BOOTSTRAP}" -i "${BUILDDIR}/.bootstrap/build.ninja.in" 54fi 55 56# SKIP_NINJA can be used by wrappers that wish to run ninja themselves. 57if [ -z "$SKIP_NINJA" ]; then 58 ninja -C "${BUILDDIR}" "$@" 59else 60 exit 0 61fi 62