build: lock cdtest and the native MCDE builds; tools refuse outside the lock
- cdtest takes one lock around release, iso and the VM test; the nested make calls reuse it through BUILD_LOCK_HELD (re-entrant). MAKE_CMD keeps make -n cdtest from executing the recipe: GNU make runs a recipe with $(MAKE) even under -n, and the rest of the line starts a VM. - mcde-linux and mcde-host take the lock too; they read ext/src/mcde and the distfiles a release reads. - build-lock.sh: --held for the tools, --check for read-only callers, pid plus process start time for stale locks, the child is killed on INT/TERM, and nested calls reuse the outer lock. - build-stamp, cd2, cd3, cd-source, images, srctree-stage, userland, mcde-linux and mcde-host refuse to run outside the lock (the file and the message name the way in: make or tools/build-lock.sh).
This commit is contained in:
1 parent
9f55b85d4b
commit
5982a0ddde
11 files changed
+140
-12
No files matched your search
@@ -34,6 +34,11 @@ BUILD_SH := cd $(SRC) && ./build.sh \
|
||||
-U -u -j $(JOBS) -m $(MACHINE) \
|
||||
-M $(OBJ) -O $(OBJ) -x -X $(XSRC)
|
||||
|
||||
# The recursive make for cdtest. Not spelled $(MAKE): GNU make runs a recipe
|
||||
# that contains $(MAKE) even with -n, and the rest of the cdtest line would
|
||||
# start a VM; MAKE_CMD is only printed.
|
||||
MAKE_CMD := $(MAKE)
|
||||
|
||||
.PHONY: all build release install tools kernel clean-sanity stamp test compress \
|
||||
iso sourcesets isosrc cdtest userland usb mcde-linux mcde-host
|
||||
|
||||
@@ -125,9 +130,7 @@ userland:
|
||||
# measured 2026-11-07: release 8, iso 2, test 5). Not the DVD, not encryption,
|
||||
# not UEFI: tools/install-cgd.sh and `make isosrc' for those.
|
||||
cdtest:
|
||||
$(MAKE) release ARCH=$(ARCH)
|
||||
$(MAKE) iso
|
||||
tools/install-simple.sh
|
||||
@tools/build-lock.sh '$(MAKE_CMD) release ARCH=$(ARCH) && $(MAKE_CMD) iso && tools/install-simple.sh'
|
||||
|
||||
# installworld over a running system. Refused anywhere but Makronix/NetBSD:
|
||||
# a cross host has no business writing its own /usr from another system's
|
||||
@@ -159,9 +162,9 @@ clean-sanity:
|
||||
# MCDE built natively on this host, for development (tools/mcde-linux.sh); not
|
||||
# how Makronix gets it (that is pkgsrc). MCDE_DIRS: only these subdirectories.
|
||||
mcde-linux:
|
||||
tools/mcde-linux.sh $(MCDE_DIRS)
|
||||
@tools/build-lock.sh 'tools/mcde-linux.sh $(MCDE_DIRS)'
|
||||
|
||||
# MCDE for this host's own desktop, in /usr/mdt, with the path step of the
|
||||
# pkgsrc recipe (tools/mcde-host.sh); MCDE_DIRS=install copies it over /.
|
||||
mcde-host:
|
||||
tools/mcde-host.sh $(MCDE_DIRS)
|
||||
@tools/build-lock.sh 'tools/mcde-host.sh $(MCDE_DIRS)'
|
||||
+78
-7
@@ -4,6 +4,8 @@
|
||||
# build-lock.sh -- one build at a time in one tree.
|
||||
#
|
||||
# usage: build-lock.sh 'command && command ...'
|
||||
# build-lock.sh --check # is a build running?
|
||||
# build-lock.sh --held # am I inside the build lock?
|
||||
#
|
||||
# The build tree is shared state: build.sh's distribution, the sets and the
|
||||
# CD images all read and write build/obj, and clean_METALOG moves
|
||||
@@ -12,9 +14,13 @@
|
||||
# METALOG.sanitised" in copy-releasedir, not a useful error (t0286).
|
||||
#
|
||||
# The lock is a directory under build/; it holds the pid of the shell that
|
||||
# runs the command. A stale lock (the pid is gone) is taken over. The
|
||||
# command is run with sh -c, from the current directory, so the Makefile can
|
||||
# pass one string with its && chain.
|
||||
# runs the command and the start time of that process (so a pid reused after
|
||||
# a reboot is not mistaken for a live build). A stale lock (the pid is gone,
|
||||
# or the start time differs) is taken over.
|
||||
#
|
||||
# The lock is re-entrant: the command runs with BUILD_LOCK_HELD set to the
|
||||
# lock directory, and a nested build-lock.sh call (make cdtest -> make
|
||||
# release, for example) uses that instead of taking the lock again.
|
||||
|
||||
set -eu
|
||||
|
||||
@@ -27,21 +33,86 @@ die()
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The start time of a pid, in a form that can be compared. lstart is the
|
||||
# long form (Linux, NetBSD ps); start is the short fallback. Empty if the
|
||||
# ps cannot tell.
|
||||
pid_start()
|
||||
{
|
||||
start=$(ps -p "$1" -o lstart= 2>/dev/null |
|
||||
sed -e 's/^ *//' -e 's/ *$//')
|
||||
[ -n "$start" ] ||
|
||||
start=$(ps -p "$1" -o start= 2>/dev/null | tr -d ' ')
|
||||
printf '%s\n' "$start"
|
||||
}
|
||||
|
||||
case ${1:-} in
|
||||
--check)
|
||||
# Read only: is another build running?
|
||||
[ -d "$LOCK" ] || exit 0
|
||||
pid=$(cat "$LOCK/pid" 2>/dev/null || true)
|
||||
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
||||
start=$(cat "$LOCK/start" 2>/dev/null || true)
|
||||
now=$(pid_start "$pid")
|
||||
if [ -z "$start" ] || [ -z "$now" ] || [ "$start" = "$now" ]; then
|
||||
die "another build holds $LOCK (pid $pid)"
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
--held)
|
||||
# For the tools that write build/obj or releasedir: they refuse to run
|
||||
# outside a build lock (make, or build-lock.sh '...').
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
die "not inside a build; run this through make or tools/build-lock.sh"
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
[ $# -eq 1 ] || die "usage: build-lock.sh 'command && command ...'"
|
||||
|
||||
# A nested call (make cdtest -> make release, or a tool started by the lock)
|
||||
# already runs inside the lock.
|
||||
if [ -n "${BUILD_LOCK_HELD:-}" ] && [ -d "$BUILD_LOCK_HELD" ]; then
|
||||
sh -c "$1"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
mkdir -p "$TOP/build"
|
||||
|
||||
if ! mkdir "$LOCK" 2>/dev/null; then
|
||||
pid=$(cat "$LOCK/pid" 2>/dev/null || true)
|
||||
start=$(cat "$LOCK/start" 2>/dev/null || true)
|
||||
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
||||
die "another build holds $LOCK (pid $pid); refusing to start a second one"
|
||||
now=$(pid_start "$pid")
|
||||
# No stored start (old lock) or no ps answer: trust the pid.
|
||||
if [ -z "$start" ] || [ -z "$now" ] || [ "$start" = "$now" ]; then
|
||||
die "another build holds $LOCK (pid $pid); refusing to start a second one"
|
||||
fi
|
||||
# The pid lives, but it is another process: stale after a reboot.
|
||||
fi
|
||||
# The holder is gone: a build was killed or the machine rebooted.
|
||||
rm -rf "$LOCK"
|
||||
mkdir "$LOCK" 2>/dev/null ||
|
||||
die "cannot take over the stale lock $LOCK"
|
||||
fi
|
||||
echo $$ > "$LOCK/pid"
|
||||
trap 'rm -rf "$LOCK"' EXIT INT TERM HUP
|
||||
start=$(pid_start $$)
|
||||
[ -n "$start" ] && echo "$start" > "$LOCK/start"
|
||||
|
||||
sh -c "$1"
|
||||
child=
|
||||
cleanup()
|
||||
{
|
||||
if [ -n "$child" ]; then
|
||||
kill "$child" 2>/dev/null || true
|
||||
fi
|
||||
rm -rf "$LOCK"
|
||||
}
|
||||
trap 'cleanup; exit 130' INT TERM HUP
|
||||
trap cleanup EXIT
|
||||
|
||||
BUILD_LOCK_HELD=$LOCK; export BUILD_LOCK_HELD
|
||||
sh -c "$1" &
|
||||
child=$!
|
||||
rc=0
|
||||
wait "$child" || rc=$?
|
||||
exit $rc
|
||||
@@ -22,6 +22,12 @@
|
||||
set -u
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OBJ=${OBJ:-$TOP/build/obj}
|
||||
STAMP=$OBJ/.makronix-stamp
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
set -eu
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OBJ=$TOP/build/obj
|
||||
REL=$OBJ/releasedir
|
||||
SETS=$REL/source/sets
|
||||
|
||||
@@ -24,6 +24,12 @@
|
||||
set -eu
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OBJ=$TOP/build/obj
|
||||
REL=$OBJ/releasedir
|
||||
SETS=$REL/amd64/binary/sets
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
set -eu
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OBJ=$TOP/build/obj
|
||||
REL=$OBJ/releasedir
|
||||
PKGS=$TOP/build/packages/amd64/All
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
set -eu
|
||||
|
||||
TOP=${TOP:-$(cd "$(dirname "$0")/.." && pwd)}
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REL=$(ls -d "$TOP"/build/obj/rel*/images 2>/dev/null | head -1)
|
||||
[ -d "$REL" ] || { echo "images: no release directory" >&2; exit 1; }
|
||||
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
set -u
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SRC=$TOP/ext/src/mcde
|
||||
B=$TOP/build/mcde-host
|
||||
STAGE=$TOP/build/mcde-host-stage
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
set -u
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SRC=$TOP/ext/src/mcde
|
||||
B=$TOP/build/mcde-linux
|
||||
JOBS=${JOBS:-8}
|
||||
|
||||
@@ -31,6 +31,12 @@
|
||||
set -eu
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
[ $# -eq 1 ] || { echo "usage: $0 DIR" >&2; exit 1; }
|
||||
DIR=$1
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
set -eu
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# This tool writes build/obj or releasedir: only inside the build lock.
|
||||
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
|
||||
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export MAKRONIX_TOP=$TOP
|
||||
ARCH=amd64
|
||||
PKGSRC=$TOP/pkgsrc
|
||||
|
||||
Reference in new issue
Block a user