From 7f0c59d5c1291c087eccc4fc70014190de6a439f Mon Sep 17 00:00:00 2001 From: Greg MacLellan Date: Wed, 5 Oct 2016 04:32:03 -0400 Subject: [PATCH] Add MAX_STAGE and RUN_STAGE variables (#21) * Add MAX_STAGES variable If set, only runs up to that stage * Show "Skipping stageX" message for all skipped stages * Add RUN_STAGE variable to run a single stage * Document RUN_STAGE and MAX_STAGE * Removed SKIP file support for main stage --- README.md | 3 ++- build.sh | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index bf4c65f..dd0cfe9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ #TODO -1. Simplify running a single stage 1. Documentation #Dependencies @@ -17,6 +16,8 @@ The following environment variables are supported: * `IMG_NAME`, the name of the distribution to build (required) * `APT_PROXY`, proxy/cache URL to be included in the build + * `MAX_STAGE`, to only run up to this stage. (default `4`, eg: `MAX_STAGE=2`) + * `RUN_STAGE`, to only run a single stage (eg: `RUN_STAGE=1`) A simple example for building Raspbian: diff --git a/build.sh b/build.sh index c6abdae..8942314 100755 --- a/build.sh +++ b/build.sh @@ -88,24 +88,22 @@ run_stage(){ if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}" fi - if [ ! -f SKIP ]; then - if [ "${CLEAN}" = "1" ]; then - if [ -d ${ROOTFS_DIR} ]; then - rm -rf ${ROOTFS_DIR} - fi + if [ "${CLEAN}" = "1" ]; then + if [ -d ${ROOTFS_DIR} ]; then + rm -rf ${ROOTFS_DIR} fi - if [ -x prerun.sh ]; then - log "Begin ${STAGE_DIR}/prerun.sh" - ./prerun.sh - log "End ${STAGE_DIR}/prerun.sh" - fi - for SUB_STAGE_DIR in ${STAGE_DIR}/*; do - if [ -d ${SUB_STAGE_DIR} ] && - [ ! -f ${SUB_STAGE_DIR}/SKIP ]; then - run_sub_stage - fi - done fi + if [ -x prerun.sh ]; then + log "Begin ${STAGE_DIR}/prerun.sh" + ./prerun.sh + log "End ${STAGE_DIR}/prerun.sh" + fi + for SUB_STAGE_DIR in ${STAGE_DIR}/*; do + if [ -d ${SUB_STAGE_DIR} ] && + [ ! -f ${SUB_STAGE_DIR}/SKIP ]; then + run_sub_stage + fi + done unmount ${WORK_DIR}/${STAGE} PREV_STAGE=${STAGE} PREV_STAGE_DIR=${STAGE_DIR} @@ -128,6 +126,12 @@ if [ -z "${IMG_NAME}" ]; then exit 1 fi +if [ -n "${RUN_STAGE}" ]; then + echo "Running ONLY stage${RUN_STAGE}" +elif [ -n "${MAX_STAGE}" ]; then + echo "Running stage${MAX_STAGE} build" +fi + export IMG_DATE=${IMG_DATE:-"$(date -u +%Y-%m-%d)"} export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -166,7 +170,12 @@ mkdir -p ${WORK_DIR} log "Begin ${BASE_DIR}" for STAGE_DIR in ${BASE_DIR}/stage*; do - run_stage + STAGE_DIR_NUM=$(echo $STAGE_DIR | grep -o -E "[0-9]+$") + if [[ (-z $RUN_STAGE || $STAGE_DIR_NUM -eq $RUN_STAGE) && (-z $MAX_STAGE || $STAGE_DIR_NUM -le $MAX_STAGE) ]]; then + run_stage + else + echo "Skipping ${STAGE_DIR}" + fi done CLEAN=1