Skip to contentSkip to conversation

MAKEALL: sanity check command-line options more

PATCH Applied Ahmad Fatoum 2 participants 10 messages Feb 23

lore
Share & tools
lore
#0 lore raw

cover MAKEALL: sanity check command-line options more

I watched how Claude Code stumbles to use MAKEALL correctly for a while and indeed MAKEALL could really use some improvement in user experience.

This series adds some sanity checks to make it more difficult to misuse.

Ahmad Fatoum (4):
MAKEALL: early exit if config specified, but no arch
MAKEALL: devel mode: abort if no positional config
MAKEALL: error out on options placed after the defconfig argument
MAKEALL: flock build directory to prevent concurrent builds

 MAKEALL | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/4 MAKEALL: early exit if config specified, but no arch

The behavior of MAKEALL to just build all configs and ignore the specified config is confusing, so add a check guarding against this.

---
 MAKEALL | 6 ++++++
 1 file changed, 6 insertions(+)
MAKEALL +6 -0
index 1e6d0c97b868..001b46a14726 100755
@@ -461,6 +461,12 @@ else
 				echo "Skipping test due to failed build"
 			fi
 		else
+			if [ ! "${ARCH}" ]; then
+				echo "ARCH must be specified via the -a option or environment"
+				usage
+				exit 1
+			fi
+
 			do_build_defconfig ${ARCH} $config
 		fi
 	done
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/4 MAKEALL: devel mode: abort if no positional config

In reply to Ahmad Fatoum

devel mode is supposed to make it easy to get started with a particular config that's built into build/, so let's also expect a single config to have been specified.

---
 MAKEALL | 4 ++++
 1 file changed, 4 insertions(+)
MAKEALL +4 -0
index 001b46a14726..c36aed625820 100755
@@ -391,6 +391,10 @@ fi
 
 if [ $# -eq 0 ]
 then
+	if [ "$DEVEL" = "1" ]; then
+		echo "DEVEL mode build requires specifying the config as positional argument"
+		exit 1
+	fi
 	if [ ! "${ARCH}" ] || [ ! -d arch/${ARCH} ]
 	then
 		do_build_all
Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/4 MAKEALL: error out on options placed after the defconfig argument

In reply to Ahmad Fatoum

getopts stops parsing at the first non-option argument, so options like -k after the defconfig name silently end up as positional arguments. For bare defconfigs these get misinterpreted as pytest options and are silently ignored, leading to a build without the intended configuration.

Detect this by checking for trailing arguments when any positional argument is a bare defconfig (not a labgrid .yaml config, where extra arguments are intentionally forwarded to pytest).

---
 MAKEALL | 9 +++++++++
 1 file changed, 9 insertions(+)
MAKEALL +9 -0
index c36aed625820..dd0b7f8003cc 100755
@@ -440,6 +440,15 @@ else
 
 		configs+=($i)
 	done
+	if [ ${#pytest_opts[@]} -gt 0 ]; then
+		for i in "${configs[@]}"; do
+			if ! [[ $i =~ .yaml$ ]]; then
+				echo "error: unexpected arguments after defconfig: ${pytest_opts[*]}" >&2
+				echo "hint: place all options before the defconfig argument" >&2
+				exit 1
+			fi
+		done
+	fi
 	for i in "${configs[@]}"; do
 		config=$i
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
Signature · 1 line
2.47.3
#4 lore raw

Re: [PATCH 3/4] MAKEALL: error out on options placed after the defconfig argument

Quoted 9 lines · Ahmad Fatoum

getopts stops parsing at the first non-option argument, so options like -k after the defconfig name silently end up as positional arguments. For bare defconfigs these get misinterpreted as pytest options and are silently ignored, leading to a build without the intended configuration.

Detect this by checking for trailing arguments when any positional argument is a bare defconfig (not a labgrid .yaml config, where extra arguments are intentionally forwarded to pytest).

Can't we use getopt for MAKEALL instead of getopts? getopt just does the right thing.

Sascha

Quoted 32 lines
---
 MAKEALL | 9 +++++++++
 1 file changed, 9 insertions(+)
MAKEALL +9 -0
index c36aed625820..dd0b7f8003cc 100755
@@ -440,6 +440,15 @@ else
 
 		configs+=($i)
 	done
+	if [ ${#pytest_opts[@]} -gt 0 ]; then
+		for i in "${configs[@]}"; do
+			if ! [[ $i =~ .yaml$ ]]; then
+				echo "error: unexpected arguments after defconfig: ${pytest_opts[*]}" >&2
+				echo "hint: place all options before the defconfig argument" >&2
+				exit 1
+			fi
+		done
+	fi
 	for i in "${configs[@]}"; do
 		config=$i
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
Signature · 1 line
2.47.3
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw

Re: [PATCH 3/4] MAKEALL: error out on options placed after the defconfig argument

Hi,

Quoted 7 lines · Sascha Hauer
Quoted 6 lines · Ahmad Fatoum

getopts stops parsing at the first non-option argument, so options like -k after the defconfig name silently end up as positional arguments. For bare defconfigs these get misinterpreted as pytest options and are silently ignored, leading to a build without the intended configuration.

Quoted 6 lines
Quoted 3 lines

Detect this by checking for trailing arguments when any positional argument is a bare defconfig (not a labgrid .yaml config, where extra arguments are intentionally forwarded to pytest).

Can't we use getopt for MAKEALL instead of getopts? getopt just does the right thing.

When using MAKEALL with a labgrid yaml instead of a defconfig, it derives the defconfig name and interprets the options after the yaml as pytest options, so use of getopt would break that.

Cheers,
Ahmad

Quoted 36 lines

Sascha

Quoted 32 lines
---
 MAKEALL | 9 +++++++++
 1 file changed, 9 insertions(+)
MAKEALL +9 -0
index c36aed625820..dd0b7f8003cc 100755
@@ -440,6 +440,15 @@ else
 
 		configs+=($i)
 	done
+	if [ ${#pytest_opts[@]} -gt 0 ]; then
+		for i in "${configs[@]}"; do
+			if ! [[ $i =~ .yaml$ ]]; then
+				echo "error: unexpected arguments after defconfig: ${pytest_opts[*]}" >&2
+				echo "hint: place all options before the defconfig argument" >&2
+				exit 1
+			fi
+		done
+	fi
 	for i in "${configs[@]}"; do
 		config=$i
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
Signature · 1 line
2.47.3
#6 lore raw

Re: [PATCH 3/4] MAKEALL: error out on options placed after the defconfig argument

Quoted 14 lines · Ahmad Fatoum

Hi,

Quoted 11 lines · Sascha Hauer
Quoted 9 lines · Ahmad Fatoum

getopts stops parsing at the first non-option argument, so options like -k after the defconfig name silently end up as positional arguments. For bare defconfigs these get misinterpreted as pytest options and are silently ignored, leading to a build without the intended configuration.

Detect this by checking for trailing arguments when any positional argument is a bare defconfig (not a labgrid .yaml config, where extra arguments are intentionally forwarded to pytest).

Quoted 6 lines
Quoted 2 lines

Can't we use getopt for MAKEALL instead of getopts? getopt just does the right thing.

When using MAKEALL with a labgrid yaml instead of a defconfig, it derives the defconfig name and interprets the options after the yaml as pytest options, so use of getopt would break that.

You can use -- as final argument which stops getopt parsing.

Sascha

Quoted 42 lines

Cheers,
Ahmad

Quoted 36 lines

Sascha

Quoted 32 lines
---
 MAKEALL | 9 +++++++++
 1 file changed, 9 insertions(+)
MAKEALL +9 -0
index c36aed625820..dd0b7f8003cc 100755
@@ -440,6 +440,15 @@ else
 
 		configs+=($i)
 	done
+	if [ ${#pytest_opts[@]} -gt 0 ]; then
+		for i in "${configs[@]}"; do
+			if ! [[ $i =~ .yaml$ ]]; then
+				echo "error: unexpected arguments after defconfig: ${pytest_opts[*]}" >&2
+				echo "hint: place all options before the defconfig argument" >&2
+				exit 1
+			fi
+		done
+	fi
 	for i in "${configs[@]}"; do
 		config=$i
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
Signature · 1 line
2.47.3
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#7 lore raw

Re: [PATCH 3/4] MAKEALL: error out on options placed after the defconfig argument

Quoted 15 lines · Sascha Hauer
Quoted 14 lines · Ahmad Fatoum

Hi,

Quoted 11 lines · Sascha Hauer
Quoted 9 lines · Ahmad Fatoum

getopts stops parsing at the first non-option argument, so options like -k after the defconfig name silently end up as positional arguments. For bare defconfigs these get misinterpreted as pytest options and are silently ignored, leading to a build without the intended configuration.

Detect this by checking for trailing arguments when any positional argument is a bare defconfig (not a labgrid .yaml config, where extra arguments are intentionally forwarded to pytest).

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Can't we use getopt for MAKEALL instead of getopts? getopt just does the right thing.

When using MAKEALL with a labgrid yaml instead of a defconfig, it derives the defconfig name and interprets the options after the yaml as pytest options, so use of getopt would break that.

You can use -- as final argument which stops getopt parsing.

Fair enough, I think 1,2,4 are good to go though?
I will rework 3/4 later.

Thanks,
Ahmad

Quoted 46 lines

Sascha

Quoted 42 lines

Cheers,
Ahmad

Quoted 36 lines

Sascha

Quoted 32 lines
---
 MAKEALL | 9 +++++++++
 1 file changed, 9 insertions(+)
MAKEALL +9 -0
index c36aed625820..dd0b7f8003cc 100755
@@ -440,6 +440,15 @@ else
 
 		configs+=($i)
 	done
+	if [ ${#pytest_opts[@]} -gt 0 ]; then
+		for i in "${configs[@]}"; do
+			if ! [[ $i =~ .yaml$ ]]; then
+				echo "error: unexpected arguments after defconfig: ${pytest_opts[*]}" >&2
+				echo "hint: place all options before the defconfig argument" >&2
+				exit 1
+			fi
+		done
+	fi
 	for i in "${configs[@]}"; do
 		config=$i
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
Signature · 1 line
2.47.3
#8 lore raw

PATCH 4/4 MAKEALL: flock build directory to prevent concurrent builds

In reply to Ahmad Fatoum

Two MAKEALL processes using the same build directory concurrently will corrupt each other's build. Take an exclusive flock on the build directory at startup so a second MAKEALL targeting the same directory fails immediately with a clear error message.

To keep the lock valid across non-incremental rebuilds, clear the directory contents with find -delete instead of rm -rf, preserving the directory inode the lock is held on.

---
 MAKEALL | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
MAKEALL +10 -1
index dd0b7f8003cc..7a6fe61f5e84 100755
@@ -133,7 +133,7 @@ do_build_defconfig() {
 	local log_err="${logdir}/${defconfig}/errors.log"
 	local err=0
 
-	[ "$INCREMENTAL" != "1" ] && rm -rf "${BUILDDIR}"
+	[ "$INCREMENTAL" != "1" ] && find "${BUILDDIR}" -mindepth 1 -delete
 	[ -n "$logdir" ] && mkdir -p "${logdir}/${defconfig}"
 
 	MAKE="make -j${JOBS} ARCH=${arch} O=${BUILDDIR}"
@@ -384,6 +384,15 @@ then
 	mkdir "${logdir}" || exit 1
 fi
 
+# Take an exclusive lock on the build directory to prevent parallel builds
+# from corrupting each other.
+mkdir -p "${BUILDDIR}"
+exec 9<"${BUILDDIR}"
+if ! flock -n 9; then
+	echo "error: another MAKEALL is already using build directory '${BUILDDIR}'" >&2
+	exit 1
+fi
+
 if [ ! "${REGEX}" ]
 then
 	REGEX="*"
Signature · 1 line
2.47.3
Applied
#9 lore raw

Re: (subset) [PATCH 0/4] MAKEALL: sanity check command-line options more

In reply to Ahmad Fatoum
Quoted 5 lines · Ahmad Fatoum

I watched how Claude Code stumbles to use MAKEALL correctly for a while and indeed MAKEALL could really use some improvement in user experience.

This series adds some sanity checks to make it more difficult to misuse.

Quoted 7 lines

Ahmad Fatoum (4):
MAKEALL: early exit if config specified, but no arch
MAKEALL: devel mode: abort if no positional config
MAKEALL: error out on options placed after the defconfig argument
MAKEALL: flock build directory to prevent concurrent builds

[...]

Applied, thanks!

[1/4] MAKEALL: early exit if config specified, but no arch
https://git.pengutronix.de/cgit/barebox/commit/?id=ec05602df38e (link may not be stable)
[2/4] MAKEALL: devel mode: abort if no positional config
https://git.pengutronix.de/cgit/barebox/commit/?id=b1cef49ae15a (link may not be stable)
[4/4] MAKEALL: flock build directory to prevent concurrent builds
https://git.pengutronix.de/cgit/barebox/commit/?id=9fa9842b35fb (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>