Skip to contentSkip to conversation

scripts/jobserver-exec: parse the last --jobserver-auth= option

PATCH In review Masahiro Yamada 2 participants 3 messages Nov 14, 2022 – Nov 15, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/jobserver-exec: parse the last --jobserver-auth= option

In the GNU Make manual, the section "Sharing Job Slots with GNU make" says:

Be aware that the MAKEFLAGS variable may contain multiple instances of the --jobserver-auth= option. Only the last instance is relevant.

Take the last element of the array, not the first.

---

 scripts/jobserver-exec | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/jobserver-exec +3 -1
index 8762887a970c..4192855f5b8b 100755
@@ -23,7 +23,9 @@ try:
 	opts = [x for x in flags.split(" ") if x.startswith("--jobserver")]
 
 	# Parse out R,W file descriptor numbers and set them nonblocking.
-	fds = opts[0].split("=", 1)[1]
+	# If the MAKEFLAGS variable contains multiple instances of the
+	# --jobserver-auth= option, the last one is relevant.
+	fds = opts[-1].split("=", 1)[1]
 	reader, writer = [int(x) for x in fds.split(",", 1)]
 	# Open a private copy of reader to avoid setting nonblocking
 	# on an unexpecting process with the same reader fd.
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Masahiro Yamada

In the GNU Make manual, the section "Sharing Job Slots with GNU make" says:

Be aware that the MAKEFLAGS variable may contain multiple instances of the --jobserver-auth= option. Only the last instance is relevant.

Take the last element of the array, not the first.

---

 scripts/jobserver-exec | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/jobserver-exec +3 -1
index 8762887a970c..4192855f5b8b 100755
@@ -23,7 +23,9 @@ try:
 	opts = [x for x in flags.split(" ") if x.startswith("--jobserver")]
 
 	# Parse out R,W file descriptor numbers and set them nonblocking.
-	fds = opts[0].split("=", 1)[1]
+	# If the MAKEFLAGS variable contains multiple instances of the
+	# --jobserver-auth= option, the last one is relevant.
+	fds = opts[-1].split("=", 1)[1]
 	reader, writer = [int(x) for x in fds.split(",", 1)]
 	# Open a private copy of reader to avoid setting nonblocking
 	# on an unexpecting process with the same reader fd.
Signature · 1 line
2.34.1

I think it feels a bit odd to check for '--jobserver' (w/o '-auth'), but "fixing" it would require depending on make >= 4.2 (May 2016). That's probably not yet old enough, isn't it?

#2 lore raw
Quoted 24 lines · Nicolas Schier
Quoted 22 lines · Masahiro Yamada

In the GNU Make manual, the section "Sharing Job Slots with GNU make" says:

Be aware that the MAKEFLAGS variable may contain multiple instances of the --jobserver-auth= option. Only the last instance is relevant.

Take the last element of the array, not the first.

---

 scripts/jobserver-exec | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/jobserver-exec +0 -0
index 8762887a970c..4192855f5b8b 100755
@@ -23,7 +23,9 @@ try:
      opts = [x for x in flags.split(" ") if x.startswith("--jobserver")]
 
Quoted 14 lines
Quoted 10 lines
scripts/jobserver-exec +3 -2
      # Parse out R,W file descriptor numbers and set them nonblocking.
-     fds = opts[0].split("=", 1)[1]
+     # If the MAKEFLAGS variable contains multiple instances of the
+     # --jobserver-auth= option, the last one is relevant.
+     fds = opts[-1].split("=", 1)[1]
      reader, writer = [int(x) for x in fds.split(",", 1)]
      # Open a private copy of reader to avoid setting nonblocking
      # on an unexpecting process with the same reader fd.
--

2.34.1

I think it feels a bit odd to check for '--jobserver' (w/o '-auth'), but "fixing" it would require depending on make >= 4.2 (May 2016). That's probably not yet old enough, isn't it?

Right. The option was --jobserver-fds= for Make <= 4.1. I think requiring Make 4.2 is too early at this moment.

Quoted 2 lines

--
Best Regards
Masahiro Yamada