[U-Boot] [PATCH] Allow for parallel builds and saved output

Mike Frysinger vapier at gentoo.org
Sun Nov 20 22:23:48 CET 2011


On Thursday 03 November 2011 03:28:29 Andy Fleming wrote:
> +if [ ! "${BUILD_NBUILDS}" ] ; then
> +	BUILD_NBUILDS="1"
> +fi

: ${BUILD_NBUILDS:=1}

> +	if [ ! "${BUILD_DIR}" ] ; then
> +		BUILD_DIR="./build"
> +	fi

: ${BUILD_DIR:=./build}

> +	mkdir -p ${BUILD_DIR}/ERR

mkdir -p "${BUILD_DIR}/ERR"

>  if [ ! "${BUILD_DIR}" ] ; then
>  	BUILD_DIR="."
>  fi

: ${BUILD_DIR:=.}

> +		mkdir -p ${output_dir}

mkdir -p "${output_dir}"

> +		${MAKE} clean
> +		find "${output_dir}" -type f -name '*.depend' | xargs rm

why not use distclean and avoid the `find` ?  otherwise, this find should be:
	find "${output_dir}" -type f -name '*.depend' -exec rm -f {} +

> +			ERR_CNT=$((ERR_CNT + 1))

	: $(( ERR_CNT += 1 ))

> -			build_target ${t}
> +			if [ "$BUILD_NBUILDS" -gt 1 ] ; then
> +				build_target ${t} &
> +			else
> +				build_target ${t}
> +			fi

you could keep this one line as:
	build_target ${t} &
	[ ${BUILD_NBUILDS} -eq 1 ] && wait

> +			TOTAL_CNT=$((TOTAL_CNT + 1))

: $(( TOTAL_CNT += 1 ))

> +			CURRENT_COUNT=$((CURRENT_COUNT + 1))

: $(( CURRENT_COUNT += 1 ))

> +		# Limit number of parallel builds
> +		if [ ${CURRENT_COUNT} -gt ${BUILD_NBUILDS} ] ; then
> +			CURRENT_COUNT=0;
> +			wait;
>  		fi

you don't need those semicolons.  also, this is not as good as it should be: 
if you're running 10 jobs in parallel, you fork 10, and then you wait for all 
of them to finish before forking another set of 10.

what you could do is something like:
	JOB_IDX=0
	JOB_IDX_FIRST=0
	BUILD_NBUILDS=1

	... foreach target ... ; do
		build_target &
		pids[$(( JOB_IDX++ ))]=$!
		if [ $(( JOB_IDX - JOB_IDX_FIRST )) -ge ${BUILD_NBUILDS} ] ; then
			wait ${pids[$(( JOB_IDX_FIRST++ ))]}
		fi
	done
	wait

this isn't perfect as it assumes the first job launched will always finish first, 
but it's a lot closer than the current code.

> +		for file in `ls ${OUTPUT_PREFIX}/ERR/`; do
> +			ERR_LIST="${ERR_LIST} $file"
> +		done

ERR_LIST=$(ls ${OUTPUT_PREFIX}/ERR/)

> +		ERR_CNT=`ls -l ${OUTPUT_PREFIX}/ERR/ | wc | awk '{print $1}'`

you should use -1 instead of -l
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111120/79c6ca60/attachment.pgp>


More information about the U-Boot mailing list