diff options
Diffstat (limited to 'include')
-rwxr-xr-x | include/err.sh | 57 | ||||
-rwxr-xr-x | include/git.sh | 42 | ||||
-rwxr-xr-x | include/mrc.sh | 22 | ||||
-rwxr-xr-x | include/option.sh | 18 |
4 files changed, 84 insertions, 55 deletions
diff --git a/include/err.sh b/include/err.sh index cab81d02..a94275f3 100755 --- a/include/err.sh +++ b/include/err.sh @@ -1,20 +1,43 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org> +export LC_COLLATE=C +export LC_ALL=C + version=""; versiondate=""; projectname=""; _nogit="" +err="err_"; tmpdir=""; lbmk_status="" -x_() { - [ $# -lt 1 ] || ${@} || err_exit err ${@} -} -xx_() { - [ $# -lt 1 ] || ${@} || err_exit fail ${@} -} +# if "y": a coreboot target won't be built if target.cfg says release="n" +# (this is used to exclude certain build targets from releases) +lbmk_release= +set | grep LBMK_RELEASE 1>/dev/null 2>/dev/null || lbmk_release="n" || : +[ -z "$lbmk_release" ] && lbmk_release="$LBMK_RELEASE" +[ "$lbmk_release" = "n" ] || [ "$lbmk_release" = "y" ] || lbmk_release="n" +export LBMK_RELEASE="$lbmk_release" -err_exit() -{ - _fail="${1}" && shift 1 - echo "Non-zero exit: $@" - $_fail "Unhandled error" +# if set to n via export, status checks will be skipped during +# all builds, and all targets will be built regardless of status. +# this replicates the old behaviour of lbmk, prior to the checks. +set | grep LBMK_STATUS 1>/dev/null 2>/dev/null && lbmk_status="$LBMK_STATUS" +[ "$lbmk_status" = "y" ] || [ "$lbmk_status" = "n" ] || lbmk_status="y" +export LBMK_STATUS="$lbmk_status" + +tmpdir_was_set="y" +set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n" +if [ "${tmpdir_was_set}" = "y" ]; then + [ "${TMPDIR%_*}" = "/tmp/lbmk" ] || tmpdir_was_set="n" +fi +if [ "${tmpdir_was_set}" = "n" ]; then + export TMPDIR="/tmp" + tmpdir="$(mktemp -d -t lbmk_XXXXXXXX)" + export TMPDIR="${tmpdir}" +else + export TMPDIR="${TMPDIR}" + tmpdir="${TMPDIR}" +fi + +x_() { + [ $# -lt 1 ] || ${@} || $err "Unhandled non-zero exit: $@"; return 0 } check_git() @@ -30,8 +53,7 @@ check_git() git_err() { printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2 - fail "Git name/email not configured" || \ - err "Git name/email not configured" + $err "Git name/email not configured" } check_project() @@ -49,9 +71,8 @@ check_project() --pretty='%ct' HEAD)" || versiondate="${versiondate_}" for p in projectname version versiondate; do - eval "[ -n \"\$$p\" ] || fail \"$p unset\" || err \"$p unset\"" - p_="x_ printf \"%s\\n\" \"\$$p\" > $p" - eval "x$p_ || $p_" + eval "[ -n \"\$$p\" ] || $err \"$p unset\"" + eval "x_ printf \"%s\\n\" \"\$$p\" > $p" done export LOCALVERSION="-${projectname}-${version%%-*}" } @@ -59,7 +80,7 @@ check_project() setvars() { _setvars="" - [ $# -lt 2 ] && err "setvars: too few arguments" + [ $# -lt 2 ] && $err "setvars: too few arguments" val="${1}" && shift 1 for var in $@; do _setvars="${var}=\"${val}\"; ${_setvars}" @@ -67,7 +88,7 @@ setvars() printf "%s\n" "${_setvars% }" } -err() +err_() { printf "ERROR %s: %s\n" "${0}" "${1}" 1>&2 exit 1 diff --git a/include/git.sh b/include/git.sh index 1fb8046d..5c456706 100755 --- a/include/git.sh +++ b/include/git.sh @@ -29,7 +29,7 @@ fetch_from_upstream() fetch_config() { - rm -f "${cfgsdir}/"*/seen || err "fetch_config ${cfgsdir}: !rm seen" + rm -f "${cfgsdir}/"*/seen || $err "fetch_config ${cfgsdir}: !rm seen" eval "$(setvars "" xtree tree_depend)" while true; do eval "$(setvars "" rev tree)" @@ -44,12 +44,12 @@ fetch_config() load_target_config() { - [ -f "$cfgsdir/$1/target.cfg" ] || err "$1: target.cfg missing" + [ -f "$cfgsdir/$1/target.cfg" ] || $err "$1: target.cfg missing" [ -f "${cfgsdir}/${1}/seen" ] && \ - err "${_xm} check: infinite loop in tree definitions" + $err "${_xm} check: infinite loop in tree definitions" - . "$cfgsdir/$1/target.cfg" || err "load_target_config !$cfgsdir/$1" - touch "$cfgsdir/$1/seen" || err "load_config $cfgsdir/$1: !mk seen" + . "$cfgsdir/$1/target.cfg" || $err "load_target_config !$cfgsdir/$1" + touch "$cfgsdir/$1/seen" || $err "load_config $cfgsdir/$1: !mk seen" } prepare_new_tree() @@ -57,7 +57,7 @@ prepare_new_tree() printf "Creating %s tree %s (%s)\n" "$project" "$tree" "$_target" cp -R "src/${project}/${project}" "${tmpgit}" || \ - err "prepare_new_tree ${project}/${tree}: can't make tmpclone" + $err "prepare_new_tree ${project}/${tree}: can't make tmpclone" git_prep "$PWD/$cfgsdir/$tree/patches" "src/$project/$tree" "update" } @@ -65,15 +65,15 @@ fetch_project_repo() { eval "$(setvars "" xtree tree_depend)" - scan_config "${project}" "config/git" "err" - [ -z "${loc+x}" ] && err "fetch_project_repo $project: loc not set" - [ -z "${url+x}" ] && err "fetch_project_repo $project: url not set" + scan_config "${project}" "config/git" + [ -z "${loc+x}" ] && $err "fetch_project_repo $project: loc not set" + [ -z "${url+x}" ] && $err "fetch_project_repo $project: url not set" clone_project [ -z "${depend}" ] || for d in ${depend} ; do x_ ./update trees -f ${d} done - rm -Rf "${tmpgit}" || err "fetch_repo: !rm -Rf ${tmpgit}" + rm -Rf "${tmpgit}" || $err "fetch_repo: !rm -Rf ${tmpgit}" } clone_project() @@ -86,7 +86,7 @@ clone_project() fi git clone $url "$tmpgit" || git clone $bkup_url "$tmpgit" \ - || err "clone_project: could not download ${project}" + || $err "clone_project: could not download ${project}" git_prep "$PWD/config/$project/patches" "$loc" } @@ -95,26 +95,26 @@ git_prep() _patchdir="$1" _loc="$2" - [ -z "${rev+x}" ] && err "git_prep $_loc: rev not set" - git -C "$tmpgit" reset --hard $rev || err "git -C $_loc: !reset $rev" - git_am_patches "$tmpgit" "$_patchdir" || err "!am $_loc $_patchdir" + [ -z "${rev+x}" ] && $err "git_prep $_loc: rev not set" + git -C "$tmpgit" reset --hard $rev || $err "git -C $_loc: !reset $rev" + git_am_patches "$tmpgit" "$_patchdir" || $err "!am $_loc $_patchdir" if [ "$project" != "coreboot" ] || [ $# -gt 2 ]; then [ ! -f "$tmpgit/.gitmodules" ] || git -C "$tmpgit" submodule \ - update --init --checkout || err "git_prep $_loc: !submod" + update --init --checkout || $err "git_prep $_loc: !submod" if [ "$project" = "coreboot" ] && [ -n "$xtree" ] && \ [ "$xtree" != "$tree" ]; then ( - cd "$tmpgit/util" || err "prep $_loc: !cd $tmpgit/util" - rm -Rf crossgcc || err "prep $_loc: !rm xgcc" + cd "$tmpgit/util" || $err "prep $_loc: !cd $tmpgit/util" + rm -Rf crossgcc || $err "prep $_loc: !rm xgcc" ln -s "../../$xtree/util/crossgcc" crossgcc || \ - err "prep $_loc: can't create xgcc symlink" - ) || err "prep $_loc: can't create xgcc symlink" + $err "prep $_loc: can't create xgcc symlink" + ) || $err "prep $_loc: can't create xgcc symlink" fi fi [ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}" - mv "$tmpgit" "$_loc" || err "git_prep: !mv $tmpgit $_loc" + mv "$tmpgit" "$_loc" || $err "git_prep: !mv $tmpgit $_loc" [ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \ x_ ./update project trees -f coreboot "$xtree"; return 0 } @@ -123,7 +123,7 @@ git_am_patches() { for _patch in "$2/"*; do [ -L "$_patch" ] || [ ! -f "$_patch" ] || git -C "$1" am \ - "$_patch" || err "git_am $1 $2: !git am $_patch"; continue + "$_patch" || $err "git_am $1 $2: !git am $_patch"; continue done for _patches in "$2/"*; do [ ! -L "$_patches" ] && [ -d "$_patches" ] && \ diff --git a/include/mrc.sh b/include/mrc.sh index 32c68a83..901a3c3b 100755 --- a/include/mrc.sh +++ b/include/mrc.sh @@ -14,7 +14,7 @@ extract_ref() # but refcode is downloaded alongside mrc. in cases where lbmk # erred, downloading only mrc, we must ensure downloading refcode [ -n "$CONFIG_MRC_FILE" ] || \ - err "extract_ref $board: CONFIG_MRC_FILE not defined" + $err "extract_ref $board: CONFIG_MRC_FILE not defined" # the extract_mrc function actually downloads the refcode fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE" @@ -22,9 +22,9 @@ extract_ref() extract_mrc() { - [ -z "$MRC_board" ] && err "extract_mrc $MRC_hash: MRC_board not set" + [ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set" [ -z "${CONFIG_MRC_FILE}" ] && \ - err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set" + $err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set" SHELLBALL="chromeos-firmwareupdate-${MRC_board}" @@ -32,10 +32,10 @@ extract_mrc() x_ cd "${appdir}" extract_partition "${MRC_url##*/}" extract_archive "${SHELLBALL}" . - ) || err "mrc download/extract failure" + ) || $err "mrc download/extract failure" "${cbfstool}" "${appdir}/"bios.bin extract -n mrc.bin \ - -f "$_dest" -r RO_SECTION || err "extract_mrc: cbfstool $_dest" + -f "$_dest" -r RO_SECTION || $err "extract_mrc: cbfstool $_dest" [ -n "$CONFIG_REFCODE_BLOB_FILE" ] && extract_refcode; return 0 } @@ -51,10 +51,10 @@ extract_partition() dd if="${1%.zip}" of="root-a.ext2" bs=1024 \ skip=$(( ${START} / 1024 )) count=$(( ${SIZE} / 1024 )) || \ - err "extract_partition, dd ${1%.zip}, root-a.ext2" + $err "extract_partition, dd ${1%.zip}, root-a.ext2" printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \ - | debugfs "root-a.ext2" || err "can't extract shellball" + | debugfs "root-a.ext2" || $err "can't extract shellball" } extract_refcode() @@ -66,16 +66,16 @@ extract_refcode() # incompatible with older versions before coreboot 4.14, # so we need coreboot 4.13 cbfstool for certain refcode files [ -n "$cbfstoolref" ] || \ - err "extract_refcode $board: MRC_refcode_cbtree not set" + $err "extract_refcode $board: MRC_refcode_cbtree not set" mkdir -p "${_refdest%/*}" || \ - err "extract_refcode $board: !mkdir -p ${_refdest%/*}" + $err "extract_refcode $board: !mkdir -p ${_refdest%/*}" "$cbfstoolref" "$appdir/bios.bin" extract \ -m x86 -n fallback/refcode -f "$_refdest" -r RO_SECTION \ - || err "extract_refcode $board: !cbfstoolref $_refdest" + || $err "extract_refcode $board: !cbfstoolref $_refdest" # enable the Intel GbE device, if told by offset MRC_refcode_gbe [ -z "$MRC_refcode_gbe" ] || dd if="config/ifd/hp820g2/1.bin" \ of="$_refdest" bs=1 seek=$MRC_refcode_gbe count=1 conv=notrunc || \ - err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0 + $err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0 } diff --git a/include/option.sh b/include/option.sh index 2284fb0b..eb792775 100755 --- a/include/option.sh +++ b/include/option.sh @@ -22,6 +22,15 @@ eval "$(setvars "" CONFIG_BOARD_DELL_E6400 CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN \ CONFIG_IFD_BIN_PATH CONFIG_MRC_FILE _dest board boarddir \ CONFIG_HAVE_REFCODE_BLOB CONFIG_REFCODE_BLOB_FILE)" +threads= +set | grep LBMK_THREADS 1>/dev/null 2>/dev/null && threads="$LBMK_THREADS" +[ -z "$threads" ] && threads=1 + +expr "X$threads" : "X-\{0,1\}[0123456789][0123456789]*$" \ + 1>/dev/null 2>/dev/null || threads=1 # user specified a non-integer + +export LBMK_THREADS="$threads" + items() { rval=1 @@ -43,10 +52,9 @@ scan_config() { awkstr=" /\{.*${1}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }" confdir="${2}" - _fail="${3}" revfile="$(mktemp -t sources.XXXXXXXXXX)" cat "${confdir}/"* > "${revfile}" || \ - "${_fail}" "scan_config ${confdir}: Cannot concatenate files" + $err "scan_config ${confdir}: Cannot concatenate files" while read -r line ; do set ${line} 1>/dev/null 2>/dev/null || : if [ "${1%:}" = "depend" ]; then @@ -57,7 +65,7 @@ scan_config() done << EOF $(eval "awk '${awkstr}' \"${revfile}\"") EOF - rm -f "$revfile" || "$_fail" "scan_config: Cannot remove tmpfile" + rm -f "$revfile" || $err "scan_config: Cannot remove tmpfile" } check_defconfig() @@ -81,6 +89,6 @@ handle_coreboot_utils() remkdir() { - rm -Rf "${1}" || err "remkdir: !rm -Rf \"${1}\"" - mkdir -p "${1}" || err "remkdir: !mkdir -p \"${1}\"" + rm -Rf "${1}" || $err "remkdir: !rm -Rf \"${1}\"" + mkdir -p "${1}" || $err "remkdir: !mkdir -p \"${1}\"" } |