From cde3b7051e4c9276a35f608e7709e3a7e480b01e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:18:45 +0100 Subject: init.sh: return from child in set_env instead This is earlier than the current check, thus preventing the initialisation of a git repository and/or the recreation of xbmktmp and xbmklocal by erroneous parent executions of lbmk while another parent is running - the latter of which could have caused a massively unpredictable build failure, so this is also a pre-emptive bug fix, fixing all kinds of weird bugs. Signed-off-by: Leah Rowe --- include/init.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 2dd9e88f..60dd3dd9 100644 --- a/include/init.sh +++ b/include/init.sh @@ -146,6 +146,17 @@ xbmk_set_env() [ -z "${XBMK_THREADS+x}" ] && export XBMK_THREADS=1 expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \ 1>/dev/null 2>/dev/null || export XBMK_THREADS=1; : + + # unify all temporary files/directories in a single TMPDIR + [ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ + unset TMPDIR + [ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" && xbmktmp="$TMPDIR" + [ -z "${TMPDIR+x}" ] || return 1 # child instance, so return + + # parent instance of xbmk, so don't return. set up TMPDIR + export TMPDIR="/tmp" + export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" + xbmktmp="$TMPDIR" } xbmk_git_init() @@ -171,17 +182,6 @@ xbmk_create_tmpdir() { x_ mkdir -p "$xbmklocal" - # unify all temporary files/directories in a single TMPDIR - [ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ - unset TMPDIR - [ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" && xbmktmp="$TMPDIR" - [ -z "${TMPDIR+x}" ] || return 1 # child instance, so return - - # parent instance of xbmk, so don't return. set up TMPDIR - export TMPDIR="/tmp" - export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" - xbmktmp="$TMPDIR" - # /tmp might be a tmpfs, so for large files we use ./tmp, # not to be confused with xbmktmp (xbmktmp points to /tmp) remkdir "$xbmktmp" "$xbmklocal" -- cgit v1.2.1 From e05a18d35131acd2007afc56aa07a321f6f2dfdb Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:21:30 +0100 Subject: init.sh: check the lock file BEFORE git init this way, initialisation will not be performed erroneously while another parent instance of lbmk is running. Signed-off-by: Leah Rowe --- include/init.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 60dd3dd9..807174a8 100644 --- a/include/init.sh +++ b/include/init.sh @@ -31,8 +31,8 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in set_pyver set_version set_env git_init create_tmpdir \ - lock create_pathdirs child_exec; do + for init_cmd in set_pyver set_version set_env lock git_init \ + create_tmpdir create_pathdirs child_exec; do xbmk_$init_cmd "$@" || break done } @@ -159,6 +159,12 @@ xbmk_set_env() xbmktmp="$TMPDIR" } +xbmk_lock() +{ + [ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?" + touch "$xbmklock" || err "cannot create '$xbmklock'"; : +} + xbmk_git_init() { for gitarg in "--global user.name" "--global user.email"; do @@ -187,12 +193,6 @@ xbmk_create_tmpdir() remkdir "$xbmktmp" "$xbmklocal" } -xbmk_lock() -{ - [ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?" - touch "$xbmklock" || err "cannot create '$xbmklock'"; : -} - xbmk_create_pathdirs() { remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" -- cgit v1.2.1 From 253aa81a3f991b8951c964e62859573b7a971440 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:25:35 +0100 Subject: init.sh: move PATH init to set_env we must only set this in the parent instance, not child instances. this prevents the variable from being over-populated with repeated entries. Signed-off-by: Leah Rowe --- include/init.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 807174a8..2c65d0b6 100644 --- a/include/init.sh +++ b/include/init.sh @@ -12,11 +12,10 @@ projectsite="https://libreboot.org/" [ -z "${PATH+x}" ] && \ export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" -xbmkpath="$PATH" eval "`setvars "" _nogit board reinstall versiondate aur_notice configdir \ datadir version xbmkpwd relname xbmkpwd xbmktmp python pyver xbmklocal \ - xbmklock cvxbmk cvchk`" + xbmklock cvxbmk cvchk xbmkpath`" xbmk_init() { @@ -123,6 +122,7 @@ xbmk_set_version() xbmk_set_env() { + xbmkpath="$PATH" export LOCALVERSION="-$projectname-${version%%-*}" # XBMK_CACHE is a directory, for caching downloads and git repon @@ -157,6 +157,9 @@ xbmk_set_env() export TMPDIR="/tmp" export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" xbmktmp="$TMPDIR" + + export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" + xbmkpath="$PATH" } xbmk_lock() @@ -196,7 +199,6 @@ xbmk_create_tmpdir() xbmk_create_pathdirs() { remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" - export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" ( # set up python v3.x in PATH, in case it's not set up correctly. # see code above that detected the correct python3 command. -- cgit v1.2.1 From c75bc0449d01a3a1495e75998b27fbc2a624a2ce Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:28:15 +0100 Subject: init.sh: move gnupath creation to create_tmpdir Signed-off-by: Leah Rowe --- include/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 2c65d0b6..ed11dfd3 100644 --- a/include/init.sh +++ b/include/init.sh @@ -194,11 +194,11 @@ xbmk_create_tmpdir() # /tmp might be a tmpfs, so for large files we use ./tmp, # not to be confused with xbmktmp (xbmktmp points to /tmp) remkdir "$xbmktmp" "$xbmklocal" + remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" } xbmk_create_pathdirs() { - remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" ( # set up python v3.x in PATH, in case it's not set up correctly. # see code above that detected the correct python3 command. -- cgit v1.2.1 From 0343081d9050ca62d188face7d6fb401f43ac883 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:28:57 +0100 Subject: init.sh: xbmk_create_tmpdir to xbmk_mkdirs this function now simply creates directories that lbmk will use, rather than creating specific directories. Signed-off-by: Leah Rowe --- include/init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index ed11dfd3..a49879d9 100644 --- a/include/init.sh +++ b/include/init.sh @@ -31,7 +31,7 @@ xbmk_init() [ "$(id -u)" != "0" ] || err "this command as root is not permitted" for init_cmd in set_pyver set_version set_env lock git_init \ - create_tmpdir create_pathdirs child_exec; do + mkdirs create_pathdirs child_exec; do xbmk_$init_cmd "$@" || break done } @@ -187,7 +187,7 @@ xbmk_git_init() 2>/dev/null; : } -xbmk_create_tmpdir() +xbmk_mkdirs() { x_ mkdir -p "$xbmklocal" -- cgit v1.2.1 From 36ffe6ef501e170d52a54f70713dba8bf88ba5d2 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:29:54 +0100 Subject: init.sh: remove useless comment Signed-off-by: Leah Rowe --- include/init.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index a49879d9..b41ca872 100644 --- a/include/init.sh +++ b/include/init.sh @@ -191,8 +191,6 @@ xbmk_mkdirs() { x_ mkdir -p "$xbmklocal" - # /tmp might be a tmpfs, so for large files we use ./tmp, - # not to be confused with xbmktmp (xbmktmp points to /tmp) remkdir "$xbmktmp" "$xbmklocal" remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" } -- cgit v1.2.1 From 4aa69a7d1f02733d3776e7c18ec081ff8182a75e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:30:11 +0100 Subject: init.sh: remove useless command we mkdir -p xbmklocal, only to remkdir it immediately afterward, which is the intended behaviour; on parent instances, xbmklocal is to be re-created fresh. Signed-off-by: Leah Rowe --- include/init.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index b41ca872..ccbad2b5 100644 --- a/include/init.sh +++ b/include/init.sh @@ -189,8 +189,6 @@ xbmk_git_init() xbmk_mkdirs() { - x_ mkdir -p "$xbmklocal" - remkdir "$xbmktmp" "$xbmklocal" remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" } -- cgit v1.2.1 From d0bee6b4ebba914b0ac2f16689bc23c5f6cbf866 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:38:11 +0100 Subject: init.sh: Set python version only on parent Do it after the creation of xbmkpath. This avoids performing an unnecessary check, since PATH will have already been corrected for child instances; Python will already be correct there. Signed-off-by: Leah Rowe --- include/init.sh | 96 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index ccbad2b5..6c45b44d 100644 --- a/include/init.sh +++ b/include/init.sh @@ -30,8 +30,8 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in set_pyver set_version set_env lock git_init \ - mkdirs create_pathdirs child_exec; do + for init_cmd in set_version set_env lock git_init \ + mkdirs set_pyver create_pathdirs child_exec; do xbmk_$init_cmd "$@" || break done } @@ -50,52 +50,6 @@ xbmkpkg() printf "You need AUR packages: %s\n" "$aur_notice" 1>&2; : } -xbmk_set_pyver() -{ - pyv="import sys; print(sys.version_info[:])" - python="python3" - pybin python3 1>/dev/null || python="python" - pyver="2" && [ "$python" = "python3" ] && pyver="3" - pybin "$python" 1>/dev/null || pyver="" - [ -z "$pyver" ] || "`pybin "$python"`" -c "$pyv" 1>/dev/null \ - 2>/dev/null || err "Cannot detect host Python version." - [ -n "$pyver" ] && \ - pyver="$("$(pybin "$python")" -c "$pyv" | awk '{print $1}')" && \ - pyver="${pyver#(}" && pyver="${pyver%,}" - [ "${pyver%%.*}" = "3" ] || err "Bad python version (must by 3.x)"; : -} - -# Use direct path, to prevent a hang if Python is using a virtual environment, -# not command -v, to prevent a hang when checking python's version -# See: https://docs.python.org/3/library/venv.html#how-venvs-work -pybin() -{ - py="import sys; quit(1) if sys.prefix == sys.base_prefix else quit(0)" - - venv=1 - command -v "$1" 1>/dev/null 2>/dev/null || venv=0 - [ $venv -lt 1 ] || "$1" -c "$py" 1>/dev/null 2>/dev/null || venv=0 - - # ideally, don't rely on PATH or hardcoded paths if python venv. - # use the *real*, direct executable linked to by the venv symlink - if [ $venv -gt 0 ] && [ -L "`command -v "$1" 2>/dev/null`" ]; then - pypath="$(findpath \ - "$(command -v "$1" 2>/dev/null)" 2>/dev/null || :)" - [ -e "$pypath" ] && [ ! -d "$pypath" ] && \ - [ -x "$pypath" ] && printf "%s\n" "$pypath" && return 0; : - fi - - # if python venv: fall back to common PATH directories for checking - [ $venv -gt 0 ] && for pypath in "/usr/local/bin" "/usr/bin"; do - [ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \ - [ -x "$pypath/$1" ] && printf "%s/%s\n" "$pypath" "$1" && \ - return 0 - done && return 1 - - # Defer to normal command -v if not a venv - command -v "$1" 2>/dev/null || return 1 -} - xbmk_set_version() { [ ! -f ".version" ] || read -r version < ".version" || :; : @@ -193,6 +147,52 @@ xbmk_mkdirs() remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" } +xbmk_set_pyver() +{ + pyv="import sys; print(sys.version_info[:])" + python="python3" + pybin python3 1>/dev/null || python="python" + pyver="2" && [ "$python" = "python3" ] && pyver="3" + pybin "$python" 1>/dev/null || pyver="" + [ -z "$pyver" ] || "`pybin "$python"`" -c "$pyv" 1>/dev/null \ + 2>/dev/null || err "Cannot detect host Python version." + [ -n "$pyver" ] && \ + pyver="$("$(pybin "$python")" -c "$pyv" | awk '{print $1}')" && \ + pyver="${pyver#(}" && pyver="${pyver%,}" + [ "${pyver%%.*}" = "3" ] || err "Bad python version (must by 3.x)"; : +} + +# Use direct path, to prevent a hang if Python is using a virtual environment, +# not command -v, to prevent a hang when checking python's version +# See: https://docs.python.org/3/library/venv.html#how-venvs-work +pybin() +{ + py="import sys; quit(1) if sys.prefix == sys.base_prefix else quit(0)" + + venv=1 + command -v "$1" 1>/dev/null 2>/dev/null || venv=0 + [ $venv -lt 1 ] || "$1" -c "$py" 1>/dev/null 2>/dev/null || venv=0 + + # ideally, don't rely on PATH or hardcoded paths if python venv. + # use the *real*, direct executable linked to by the venv symlink + if [ $venv -gt 0 ] && [ -L "`command -v "$1" 2>/dev/null`" ]; then + pypath="$(findpath \ + "$(command -v "$1" 2>/dev/null)" 2>/dev/null || :)" + [ -e "$pypath" ] && [ ! -d "$pypath" ] && \ + [ -x "$pypath" ] && printf "%s\n" "$pypath" && return 0; : + fi + + # if python venv: fall back to common PATH directories for checking + [ $venv -gt 0 ] && for pypath in "/usr/local/bin" "/usr/bin"; do + [ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \ + [ -x "$pypath/$1" ] && printf "%s/%s\n" "$pypath" "$1" && \ + return 0 + done && return 1 + + # Defer to normal command -v if not a venv + command -v "$1" 2>/dev/null || return 1 +} + xbmk_create_pathdirs() { ( -- cgit v1.2.1 From 484afcb91969b9325c448a6a77ad97a4813f7bfb Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:40:28 +0100 Subject: init.sh: merge create_pathdirs with set_pyver all this function does now is create the python symlink, based on work that was already performed in set_pyver Signed-off-by: Leah Rowe --- include/init.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 6c45b44d..13592d83 100644 --- a/include/init.sh +++ b/include/init.sh @@ -31,7 +31,7 @@ xbmk_init() [ "$(id -u)" != "0" ] || err "this command as root is not permitted" for init_cmd in set_version set_env lock git_init \ - mkdirs set_pyver create_pathdirs child_exec; do + mkdirs set_pyver child_exec; do xbmk_$init_cmd "$@" || break done } @@ -159,7 +159,14 @@ xbmk_set_pyver() [ -n "$pyver" ] && \ pyver="$("$(pybin "$python")" -c "$pyv" | awk '{print $1}')" && \ pyver="${pyver#(}" && pyver="${pyver%,}" - [ "${pyver%%.*}" = "3" ] || err "Bad python version (must by 3.x)"; : + [ "${pyver%%.*}" = "3" ] || err "Bad python version (must by 3.x)" + + ( + # set up python v3.x in PATH, in case it's not set up correctly. + # see code above that detected the correct python3 command. + x_ cd "$XBMK_CACHE/xbmkpath" + x_ ln -s "`pybin "$python"`" python + ) || err "Can't set up python symlink in $XBMK_CACHE/xbmkpath"; : } # Use direct path, to prevent a hang if Python is using a virtual environment, @@ -193,16 +200,6 @@ pybin() command -v "$1" 2>/dev/null || return 1 } -xbmk_create_pathdirs() -{ - ( - # set up python v3.x in PATH, in case it's not set up correctly. - # see code above that detected the correct python3 command. - x_ cd "$XBMK_CACHE/xbmkpath" - x_ ln -s "`pybin "$python"`" python - ) || err "Can't set up python symlink in $XBMK_CACHE/xbmkpath"; : -} - xbmk_child_exec() { xbmk_rval=0 -- cgit v1.2.1 From ac36ea7f950a88e56be82e046004c9780c9e0803 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 11:54:51 +0100 Subject: init.sh: initialise variables AFTER path That way, unnecessary work is avoided on child instances. Of course, the current check assumes that TMPDIR wasn't already set by a wily user before running lbmk, but then those sorts of users probably know what they're doing. If they don't know, they will soon find out. Therefore, I have added additional checks on child instances, preventing the build system from running if XBMK_CACHE is not set; if it isn't, then that could very easy lead to certain system files being overwritten. The user must never know what happens if XBMK_CACHE is unset. We simply will not allow it. Signed-off-by: Leah Rowe --- include/init.sh | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 13592d83..363f0b18 100644 --- a/include/init.sh +++ b/include/init.sh @@ -76,9 +76,29 @@ xbmk_set_version() xbmk_set_env() { + is_child="n" + xbmkpath="$PATH" export LOCALVERSION="-$projectname-${version%%-*}" + # unify all temporary files/directories in a single TMPDIR + [ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ + unset TMPDIR + [ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" && xbmktmp="$TMPDIR" + [ -z "${TMPDIR+x}" ] || is_child="y" # child instance, so return + + if [ "$is_child" = "y" ]; then + [ -z "${XBMK_CACHE+x}" ] && err "XBMK_CACHE unset on child" + [ -z "${XBMK_THREADS+x}" ] && err "XBMK_THREADS unset on child" + e "lock" f missing && err "lock file absent on child" + return 1 + fi + + # parent instance of xbmk, so don't return. set up TMPDIR + export TMPDIR="/tmp" + export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" + xbmktmp="$TMPDIR" + # XBMK_CACHE is a directory, for caching downloads and git repon [ -z "${XBMK_CACHE+x}" ] && export XBMK_CACHE="$xbmkpwd/cache" [ -z "$XBMK_CACHE" ] && export XBMK_CACHE="$xbmkpwd/cache" @@ -91,6 +111,9 @@ xbmk_set_env() [ ! -e "$XBMK_CACHE" ] || \ [ -d "$XBMK_CACHE" ] || err "cachedir '$XBMK_CACHE' is a file"; : + export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" + xbmkpath="$PATH" + # 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) [ -z "${XBMK_RELEASE+x}" ] && export XBMK_RELEASE="n" @@ -100,20 +123,6 @@ xbmk_set_env() [ -z "${XBMK_THREADS+x}" ] && export XBMK_THREADS=1 expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \ 1>/dev/null 2>/dev/null || export XBMK_THREADS=1; : - - # unify all temporary files/directories in a single TMPDIR - [ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ - unset TMPDIR - [ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" && xbmktmp="$TMPDIR" - [ -z "${TMPDIR+x}" ] || return 1 # child instance, so return - - # parent instance of xbmk, so don't return. set up TMPDIR - export TMPDIR="/tmp" - export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" - xbmktmp="$TMPDIR" - - export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" - xbmkpath="$PATH" } xbmk_lock() -- cgit v1.2.1 From 6b603b9fbf45f6f391f84ecc8ced7896722f6b02 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 12:07:10 +0100 Subject: init.sh: only set xbmk version on parent instance On child instances, we need only read. Apply the principle of least privilege. Signed-off-by: Leah Rowe --- include/init.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 363f0b18..e94157f0 100644 --- a/include/init.sh +++ b/include/init.sh @@ -30,7 +30,7 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in set_version set_env lock git_init \ + for init_cmd in get_version set_env lock set_version git_init \ mkdirs set_pyver child_exec; do xbmk_$init_cmd "$@" || break done @@ -50,7 +50,7 @@ xbmkpkg() printf "You need AUR packages: %s\n" "$aur_notice" 1>&2; : } -xbmk_set_version() +xbmk_get_version() { [ ! -f ".version" ] || read -r version < ".version" || :; : [ ! -f ".versiondate" ] || read -r versiondate < ".versiondate" || :; : @@ -68,9 +68,6 @@ xbmk_set_version() --pretty='%ct' HEAD)" || versiondate="$versiondate_" chkvars version versiondate - printf "%s\n" "$version" > ".version" || err "can't save version" - printf "%s\n" "$versiondate" > ".versiondate" || err "can't save date" - relname="$projectname-$version" } @@ -131,6 +128,12 @@ xbmk_lock() touch "$xbmklock" || err "cannot create '$xbmklock'"; : } +xbmk_set_version() +{ + printf "%s\n" "$version" > ".version" || err "can't save version" + printf "%s\n" "$versiondate" > ".versiondate" || err "can't save date" +} + xbmk_git_init() { for gitarg in "--global user.name" "--global user.email"; do -- cgit v1.2.1 From 94437278dc7c3635e760f8781e9e151575845cad Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 12:51:56 +0100 Subject: init.sh: simplify unknown version creation we don't need to read or write a file at all, in that case. we only then need to generate one if running ./mk release. the scenario in which no .git and no version files exist is when someone grabs the build system from a snapshot generated by e.g. forgejo instances. it's ill advised, so we advise against it, but it is mitigated in code. Signed-off-by: Leah Rowe --- include/init.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index e94157f0..20d63068 100644 --- a/include/init.sh +++ b/include/init.sh @@ -55,10 +55,8 @@ xbmk_get_version() [ ! -f ".version" ] || read -r version < ".version" || :; : [ ! -f ".versiondate" ] || read -r versiondate < ".versiondate" || :; : - [ -e ".git" ] || [ -f ".version" ] || printf "unknown\n" > ".version" \ - || err "Cannot generate unknown .version file" - [ -e ".git" ] || [ -f ".versiondate" ] || printf "1716415872\n" > \ - ".versiondate" || err "Can't generate unknown versiondate file"; : + [ ! -e ".git" ] && [ ! -f ".version" ] && version="unknown" + [ ! -e ".git" ] && [ ! -f ".versiondate" ] && versiondate="1716415872" version_="$version" [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ -- cgit v1.2.1 From 99f09f25ef34c6836f0d13cae2ad071504715ddf Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 12:58:42 +0100 Subject: init.sh: only update version files on parent don't update them on child instances, since it's a waste of time; the lock file prevents further execution, so we are just wasting time writing to disk. Signed-off-by: Leah Rowe --- include/init.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 20d63068..cd290ebe 100644 --- a/include/init.sh +++ b/include/init.sh @@ -30,7 +30,7 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in get_version set_env lock set_version git_init \ + for init_cmd in get_version set_env lock git_init \ mkdirs set_pyver child_exec; do xbmk_$init_cmd "$@" || break done @@ -58,15 +58,7 @@ xbmk_get_version() [ ! -e ".git" ] && [ ! -f ".version" ] && version="unknown" [ ! -e ".git" ] && [ ! -f ".versiondate" ] && versiondate="1716415872" - version_="$version" - [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ - version="git-$(git rev-parse HEAD 2>&1)" || version="$version_" - versiondate_="$versiondate" - [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ - --pretty='%ct' HEAD)" || versiondate="$versiondate_" - - chkvars version versiondate - relname="$projectname-$version" + [ -n "$version" ] && relname="$projectname-$version"; : } xbmk_set_env() @@ -74,7 +66,6 @@ xbmk_set_env() is_child="n" xbmkpath="$PATH" - export LOCALVERSION="-$projectname-${version%%-*}" # unify all temporary files/directories in a single TMPDIR [ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ @@ -117,7 +108,10 @@ xbmk_set_env() [ -z "${XBMK_THREADS+x}" ] && export XBMK_THREADS=1 expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \ - 1>/dev/null 2>/dev/null || export XBMK_THREADS=1; : + 1>/dev/null 2>/dev/null || export XBMK_THREADS=1 + + xbmk_set_version + export LOCALVERSION="-$projectname-${version%%-*}" } xbmk_lock() @@ -128,8 +122,17 @@ xbmk_lock() xbmk_set_version() { - printf "%s\n" "$version" > ".version" || err "can't save version" - printf "%s\n" "$versiondate" > ".versiondate" || err "can't save date" + version_="$version" + [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ + version="git-$(git rev-parse HEAD 2>&1)" || version="$version_" + versiondate_="$versiondate" + [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ + --pretty='%ct' HEAD)" || versiondate="$versiondate_" + + chkvars version versiondate + update_xbmkver "." + + relname="$projectname-$version" } xbmk_git_init() -- cgit v1.2.1 From 485a60e2f6ab0c4eb7b08fd07a2e7be5d0c40402 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 13:08:49 +0100 Subject: init.sh: error if version not read we no longer rely on the .git version being read by child instances, so we MUST ensure that it is being read. Signed-off-by: Leah Rowe --- include/init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index cd290ebe..117a1818 100644 --- a/include/init.sh +++ b/include/init.sh @@ -52,8 +52,8 @@ xbmkpkg() xbmk_get_version() { - [ ! -f ".version" ] || read -r version < ".version" || :; : - [ ! -f ".versiondate" ] || read -r versiondate < ".versiondate" || :; : + [ ! -f ".version" ] || read -r version < ".version" || err + [ ! -f ".versiondate" ] || read -r versiondate < ".versiondate" || err [ ! -e ".git" ] && [ ! -f ".version" ] && version="unknown" [ ! -e ".git" ] && [ ! -f ".versiondate" ] && versiondate="1716415872" -- cgit v1.2.1 From 5f022acbf47724adead781136d866e8220a83e6d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 13:10:22 +0100 Subject: init.sh: check version/versiondate once read once again, we are being stricter in child instances. we must ensure that these variables are set by xbmk. Signed-off-by: Leah Rowe --- include/init.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 117a1818..ac145f56 100644 --- a/include/init.sh +++ b/include/init.sh @@ -54,6 +54,8 @@ xbmk_get_version() { [ ! -f ".version" ] || read -r version < ".version" || err [ ! -f ".versiondate" ] || read -r versiondate < ".versiondate" || err + [ ! -f ".version" ] || chkvars version + [ ! -f ".versiondate" ] || chkvars versiondate [ ! -e ".git" ] && [ ! -f ".version" ] && version="unknown" [ ! -e ".git" ] && [ ! -f ".versiondate" ] && versiondate="1716415872" -- cgit v1.2.1 From 158c56072c075231eec3422b653f01ddaa451ab6 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 13:25:37 +0100 Subject: init.sh: merge xbmk_mkdirs with set_env it's just two lines, and they relate. Signed-off-by: Leah Rowe --- include/init.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index ac145f56..1791ef78 100644 --- a/include/init.sh +++ b/include/init.sh @@ -30,8 +30,8 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in get_version set_env lock git_init \ - mkdirs set_pyver child_exec; do + for init_cmd in get_version set_env lock git_init set_pyver child_exec + do xbmk_$init_cmd "$@" || break done } @@ -114,6 +114,9 @@ xbmk_set_env() xbmk_set_version export LOCALVERSION="-$projectname-${version%%-*}" + + remkdir "$xbmktmp" "$xbmklocal" + remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" } xbmk_lock() @@ -156,12 +159,6 @@ xbmk_git_init() 2>/dev/null; : } -xbmk_mkdirs() -{ - remkdir "$xbmktmp" "$xbmklocal" - remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" -} - xbmk_set_pyver() { pyv="import sys; print(sys.version_info[:])" -- cgit v1.2.1 From 962902a1c4a0b3b9ce942980f42311528d4a4398 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 13:28:31 +0100 Subject: init.sh: set pyver from set_env it's related to this function, no point calling from main Signed-off-by: Leah Rowe --- include/init.sh | 82 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 1791ef78..49193f0f 100644 --- a/include/init.sh +++ b/include/init.sh @@ -30,7 +30,7 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in get_version set_env lock git_init set_pyver child_exec + for init_cmd in get_version set_env lock git_init child_exec do xbmk_$init_cmd "$@" || break done @@ -117,46 +117,8 @@ xbmk_set_env() remkdir "$xbmktmp" "$xbmklocal" remkdir "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" -} - -xbmk_lock() -{ - [ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?" - touch "$xbmklock" || err "cannot create '$xbmklock'"; : -} - -xbmk_set_version() -{ - version_="$version" - [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ - version="git-$(git rev-parse HEAD 2>&1)" || version="$version_" - versiondate_="$versiondate" - [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ - --pretty='%ct' HEAD)" || versiondate="$versiondate_" - - chkvars version versiondate - update_xbmkver "." - - relname="$projectname-$version" -} - -xbmk_git_init() -{ - for gitarg in "--global user.name" "--global user.email"; do - gitcmd="git config $gitarg"; $gitcmd 1>/dev/null 2>/dev/null \ - || err "Run this first: $gitcmd \"your ${gitcmd##*.}\"" - done - - [ -L ".git" ] && return 1 - [ -e ".git" ] && return 0 - eval "`setvars "$(date -Rud @$versiondate)" cdate _nogit`" - x_ git init 1>/dev/null 2>/dev/null - x_ git add -A . 1>/dev/null 2>/dev/null - x_ git commit -m "$projectname $version" --date "$cdate" \ - --author="xbmk " 1>/dev/null 2>/dev/null - x_ git tag -a "$version" -m "$projectname $version" 1>/dev/null \ - 2>/dev/null; : + xbmk_set_pyver } xbmk_set_pyver() @@ -212,6 +174,46 @@ pybin() command -v "$1" 2>/dev/null || return 1 } +xbmk_lock() +{ + [ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?" + touch "$xbmklock" || err "cannot create '$xbmklock'"; : +} + +xbmk_set_version() +{ + version_="$version" + [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ + version="git-$(git rev-parse HEAD 2>&1)" || version="$version_" + versiondate_="$versiondate" + [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ + --pretty='%ct' HEAD)" || versiondate="$versiondate_" + + chkvars version versiondate + update_xbmkver "." + + relname="$projectname-$version" +} + +xbmk_git_init() +{ + for gitarg in "--global user.name" "--global user.email"; do + gitcmd="git config $gitarg"; $gitcmd 1>/dev/null 2>/dev/null \ + || err "Run this first: $gitcmd \"your ${gitcmd##*.}\"" + done + + [ -L ".git" ] && return 1 + [ -e ".git" ] && return 0 + eval "`setvars "$(date -Rud @$versiondate)" cdate _nogit`" + + x_ git init 1>/dev/null 2>/dev/null + x_ git add -A . 1>/dev/null 2>/dev/null + x_ git commit -m "$projectname $version" --date "$cdate" \ + --author="xbmk " 1>/dev/null 2>/dev/null + x_ git tag -a "$version" -m "$projectname $version" 1>/dev/null \ + 2>/dev/null; : +} + xbmk_child_exec() { xbmk_rval=0 -- cgit v1.2.1 From fc4006ce877231f63a941eca903c0af9416e8ab8 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 13:29:51 +0100 Subject: init.sh: move xbmk_set_version it's called before set_pyver, so move it above that Signed-off-by: Leah Rowe --- include/init.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 49193f0f..35512469 100644 --- a/include/init.sh +++ b/include/init.sh @@ -121,6 +121,21 @@ xbmk_set_env() xbmk_set_pyver } +xbmk_set_version() +{ + version_="$version" + [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ + version="git-$(git rev-parse HEAD 2>&1)" || version="$version_" + versiondate_="$versiondate" + [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ + --pretty='%ct' HEAD)" || versiondate="$versiondate_" + + chkvars version versiondate + update_xbmkver "." + + relname="$projectname-$version" +} + xbmk_set_pyver() { pyv="import sys; print(sys.version_info[:])" @@ -180,21 +195,6 @@ xbmk_lock() touch "$xbmklock" || err "cannot create '$xbmklock'"; : } -xbmk_set_version() -{ - version_="$version" - [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ - version="git-$(git rev-parse HEAD 2>&1)" || version="$version_" - versiondate_="$versiondate" - [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ - --pretty='%ct' HEAD)" || versiondate="$versiondate_" - - chkvars version versiondate - update_xbmkver "." - - relname="$projectname-$version" -} - xbmk_git_init() { for gitarg in "--global user.name" "--global user.email"; do -- cgit v1.2.1 From 2702a43a86d51aba2123d620ce2f383d8fc41311 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 18 May 2025 13:32:24 +0100 Subject: init.sh: merge xbmk_lock() with xbmk_set_env() it's just two lines, and we want much more granular control of where the lock is enforced. it should be JUST after confirming that the instance is a parent. it is at this moment that we should bail if a lock file exists, because this signals that another instance of xbmk is running. Signed-off-by: Leah Rowe --- include/init.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'include/init.sh') diff --git a/include/init.sh b/include/init.sh index 35512469..ee19c398 100644 --- a/include/init.sh +++ b/include/init.sh @@ -30,8 +30,7 @@ xbmk_init() id -u 1>/dev/null 2>/dev/null || err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || err "this command as root is not permitted" - for init_cmd in get_version set_env lock git_init child_exec - do + for init_cmd in get_version set_env git_init child_exec; do xbmk_$init_cmd "$@" || break done } @@ -82,6 +81,9 @@ xbmk_set_env() return 1 fi + [ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?" + touch "$xbmklock" || err "cannot create '$xbmklock'"; : + # parent instance of xbmk, so don't return. set up TMPDIR export TMPDIR="/tmp" export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" @@ -189,12 +191,6 @@ pybin() command -v "$1" 2>/dev/null || return 1 } -xbmk_lock() -{ - [ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?" - touch "$xbmklock" || err "cannot create '$xbmklock'"; : -} - xbmk_git_init() { for gitarg in "--global user.name" "--global user.email"; do -- cgit v1.2.1