Skip to content

Commit 68a7f8c

Browse files
committed
fix: last --jobserver-auth wins
From the GNU make manual[^1]: > Be aware that the `MAKEFLAGS` variable may contain multiple > instances of the `--jobserver-auth=` option. > Only the last instance is relevant. Hence this commit makes it so. With this commit, `--jobserver-auth` also takes precedence over `--jobserver-fds`, even when `--jobserver-fds` is the last instance of these flags. This is made intentionally since `--jobserver-fds` was an undocumented internal-only flag before `--jobserver-auth` made public, according to this announcement[^2]. [^1]: https://www.gnu.org/software/make/manual/make.html#Job-Slots [^2]: https://git.savannah.gnu.org/cgit/make.git/tree/NEWS?h=4.2#n31
1 parent 1575c78 commit 68a7f8c

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/lib.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,25 @@ impl HelperState {
582582
}
583583
}
584584

585+
/// Finds and returns the value of `--jobserver-auth=<VALUE>` in the given
586+
/// environment variable.
587+
///
588+
/// Precedence rules:
589+
///
590+
/// * The last instance wins [^1].
591+
/// * `--jobserver-fds=` as a fallback when no `--jobserver-auth=` is present [^2].
592+
///
593+
/// [^1]: See ["GNU `make` manual: Sharing Job Slots with GNU `make`"](https://www.gnu.org/software/make/manual/make.html#Job-Slots)
594+
/// _"Be aware that the `MAKEFLAGS` variable may contain multiple instances of
595+
/// the `--jobserver-auth=` option. Only the last instance is relevant."_
596+
///
597+
/// [^2]: Refer to [the release announcement](https://git.savannah.gnu.org/cgit/make.git/tree/NEWS?h=4.2#n31)
598+
/// of GNU Make 4.2, which states that `--jobserver-fds` was initially an
599+
/// internal-only flag and was later renamed to `--jobserver-auth`.
585600
fn find_jobserver_auth(var: &str) -> Option<&str> {
586-
["--jobserver-fds=", "--jobserver-auth="]
601+
["--jobserver-auth=", "--jobserver-fds="]
587602
.iter()
588-
.find_map(|&arg| var.split_once(arg).map(|(_, s)| s))
603+
.find_map(|&arg| var.rsplit_once(arg).map(|(_, s)| s))
589604
.and_then(|s| s.split(' ').next())
590605
}
591606

@@ -599,17 +614,17 @@ fn no_helper_deadlock() {
599614
#[test]
600615
fn test_find_jobserver_auth() {
601616
let cases = [
602-
("--jobserver-auth=auth-a --jobserver-auth=auth-b", "auth-a"),
603-
("--jobserver-auth=auth-b --jobserver-auth=auth-a", "auth-b"),
604-
("--jobserver-fds=fds-a --jobserver-fds=fds-b", "fds-a"),
605-
("--jobserver-fds=fds-b --jobserver-fds=fds-a", "fds-b"),
617+
("--jobserver-auth=auth-a --jobserver-auth=auth-b", "auth-b"),
618+
("--jobserver-auth=auth-b --jobserver-auth=auth-a", "auth-a"),
619+
("--jobserver-fds=fds-a --jobserver-fds=fds-b", "fds-b"),
620+
("--jobserver-fds=fds-b --jobserver-fds=fds-a", "fds-a"),
606621
(
607622
"--jobserver-auth=auth-a --jobserver-fds=fds-a --jobserver-auth=auth-b",
608-
"fds-a",
623+
"auth-b",
609624
),
610625
(
611626
"--jobserver-fds=fds-a --jobserver-auth=auth-a --jobserver-fds=fds-b",
612-
"fds-a",
627+
"auth-a",
613628
),
614629
];
615630
for (var, expected) in cases {

0 commit comments

Comments
 (0)