Skip to content

Commit 311d926

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://lists.gnu.org/archive/html/info-gnu/2016-05/msg00013.html
1 parent 09d0d01 commit 311d926

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/lib.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,23 @@ impl HelperState {
584584
}
585585
}
586586

587+
/// Finds the position of `--jobserver-auth=` flag in a given environment variable.
588+
///
589+
/// Precedence rules:
590+
///
591+
/// * The last instance wins [^1].
592+
/// * `--jobserver-fds=` as a fallback when no `--jobserver-auth=` is present [^2].
593+
///
594+
/// [^1]: See ["GNU male manual: Sharing Job Slots with GNU make"](https://www.gnu.org/software/make/manual/make.html#Job-Slots)
595+
/// _"Be aware that the `MAKEFLAGS` variable may contain multiple instances
596+
/// of the `--jobserver-auth=` option. Only the last instance is relevant."_
597+
///
598+
/// [^2]: See [the release announcement](https://lists.gnu.org/archive/html/info-gnu/2016-05/msg00013.html)
599+
/// of GNU Make 4.2.
587600
fn find_jobserver_auth(var: &str) -> Option<(&str, usize)> {
588-
["--jobserver-fds=", "--jobserver-auth="]
601+
["--jobserver-auth=", "--jobserver-fds="]
589602
.iter()
590-
.map(|&arg| var.find(arg).map(|pos| (arg, pos)))
603+
.map(|&arg| var.rfind(arg).map(|pos| (arg, pos)))
591604
.find_map(|pos| pos)
592605
}
593606

@@ -603,19 +616,19 @@ fn test_find_jobserver_auth() {
603616
let cases = [
604617
(
605618
"--jobserver-auth= --jobserver-auth=",
606-
("--jobserver-auth=", 0),
619+
("--jobserver-auth=", 18),
607620
),
608621
(
609622
"--jobserver-fds= --jobserver-fds=",
610-
("--jobserver-fds=", 0usize),
623+
("--jobserver-fds=", 17),
611624
),
612625
(
613626
"--jobserver-auth= --jobserver-fds= --jobserver-auth=",
614-
("--jobserver-fds=", 18),
627+
("--jobserver-auth=", 35),
615628
),
616629
(
617630
"--jobserver-fds= --jobserver-auth= --jobserver-fds=",
618-
("--jobserver-fds=", 0),
631+
("--jobserver-auth=", 17),
619632
),
620633
];
621634
for (var, expected) in cases {

0 commit comments

Comments
 (0)