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
This commit is contained in:
Greg MacLellan 2016-10-05 04:32:03 -04:00 committed by XECDesign
parent 62406bad92
commit 7f0c59d5c1
2 changed files with 28 additions and 18 deletions

View File

@ -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:

View File

@ -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