scripts/jobserver-exec: parse the last --jobserver-auth= option
authorMasahiro Yamada <masahiroy@kernel.org>
Mon, 14 Nov 2022 18:10:55 +0000 (03:10 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 21 Nov 2022 01:18:39 +0000 (10:18 +0900)
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.

Link: https://www.gnu.org/software/make/manual/html_node/Job-Slots.html
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
scripts/jobserver-exec

index 8762887a970ce2479eb6a43ae654c36136369f6c..4192855f5b8b5c1e3b64480c11c8b1e001a89dcd 100755 (executable)
@@ -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.