Skip to content

Commit fbca34e

Browse files
committed
Merge #40 fix/gap-bump-source
The rebased #40, "fix(gap): choose the bump source by toolchain family and generation", on top of #31 and #34.
2 parents 9eb4ab0 + c7c785d commit fbca34e

5 files changed

Lines changed: 158 additions & 17 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`stack gap` picks the bump source of a `no-recipe` row among builds of the newest version by toolchain family and generation instead of file name: a build on a toolchain family of the generation comes first, then the newest toolchain generation, so QuantumESPRESSO 7.5 is bumped from `foss-2025b` rather than `NVHPC-25.3-CUDA-12.8.0`, and a recipe on `GCCcore-14.3.0` is preferred to one on `GCCcore-11.3.0`.

‎docs/orgmode/howto/module-gap.org‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ A toolchain whose version is the generation counts as on it, so
2020
generation in ~data/eessi-generations.toml~, such as
2121
~llvm-compilers-21.1.8~.
2222

23+
When the newest version has several builds, the bump source is one on a
24+
toolchain family the generation uses, ~foss~ for ~foss-2026.1~, and of
25+
those the one on the newest toolchain generation. QuantumESPRESSO 7.5 is
26+
bumped from ~foss-2025b~, not from ~NVHPC-25.3-CUDA-12.8.0~ or
27+
~foss-2025a~.
28+
2329
* Capture the live inventories
2430

2531
The helper uses the shell's ~module~ function.

‎docs/orgmode/reference/cli.org‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,9 @@ toolchain whose version is that generation, or on the system toolchain),
785785
~open-easyconfigs~ (an ~--open-easyconfigs~ pull request adds a recipe at
786786
that generation; the match is the filename, and a toolchain version equal
787787
to ~--generation~ counts), or ~no-recipe~ (the newest easyconfig on any
788-
toolchain is named as the bump source). ~--eessi-version~ keeps
788+
toolchain is named as the bump source; between builds of that version, one
789+
on a toolchain family of the generation comes first, then the one on the
790+
newest toolchain generation). ~--eessi-version~ keeps
789791
~--open-layer~ easystacks of that version; without it every easystack
790792
version counts. The command writes ~gap.tsv~, one TSV per
791793
route (~site-only.tsv~ for ~excluded~, ~bump.tsv~ for ~no-recipe~, and

‎llms-full.txt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,12 @@ A toolchain whose version is the generation counts as on it, so
45884588
generation in `data/eessi-generations.toml`, such as
45894589
`llvm-compilers-21.1.8`.
45904590

4591+
When the newest version has several builds, the bump source is one on a
4592+
toolchain family the generation uses, `foss` for `foss-2026.1`, and of
4593+
those the one on the newest toolchain generation. QuantumESPRESSO 7.5 is
4594+
bumped from `foss-2025b`, not from `NVHPC-25.3-CUDA-12.8.0` or
4595+
`foss-2025a`.
4596+
45914597
# Capture the live inventories
45924598

45934599
The helper uses the shell's `module` function.
@@ -7490,7 +7496,9 @@ toolchain whose version is that generation, or on the system toolchain),
74907496
`open-easyconfigs` (an `--open-easyconfigs` pull request adds a recipe at
74917497
that generation; the match is the filename, and a toolchain version equal
74927498
to `--generation` counts), or `no-recipe` (the newest easyconfig on any
7493-
toolchain is named as the bump source). `--eessi-version` keeps
7499+
toolchain is named as the bump source; between builds of that version, one
7500+
on a toolchain family of the generation comes first, then the one on the
7501+
newest toolchain generation). `--eessi-version` keeps
74947502
`--open-layer` easystacks of that version; without it every easystack
74957503
version counts. The command writes `gap.tsv`, one TSV per
74967504
route (`site-only.tsv` for `excluded`, `bump.tsv` for `no-recipe`, and

‎src/gap.rs‎

Lines changed: 139 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ pub struct GapRow {
3434
#[serde(skip_serializing_if = "Option::is_none")]
3535
pub recipe: Option<String>,
3636
/// The newest easyconfig of the name on any toolchain, for `no-recipe`:
37-
/// the source a bump starts from.
37+
/// the source a bump starts from. Between builds of one version, one on
38+
/// a toolchain family of the generation, then on the newest toolchain
39+
/// generation, is named.
3840
#[serde(skip_serializing_if = "Option::is_none")]
3941
pub newest_elsewhere: Option<String>,
4042
/// Why a name is `excluded` or `filtered`, or the pull requests that
@@ -198,17 +200,62 @@ fn on_generation(candidate: &Candidate, generation: &str, members: &[String]) ->
198200
/// Order candidates newest first: version, then a recipe without a
199201
/// versionsuffix before one with, then by file name.
200202
fn newest_first(a: &&Candidate, b: &&Candidate) -> Ordering {
201-
cmp_version(&b.version, &a.version)
202-
.then_with(|| {
203-
a.versionsuffix
204-
.as_deref()
205-
.unwrap_or("")
206-
.len()
207-
.cmp(&b.versionsuffix.as_deref().unwrap_or("").len())
203+
newer_build(a, b).then_with(|| file_of(a).cmp(&file_of(b)))
204+
}
205+
206+
/// Order bump sources as [`newest_first`], except that between builds of
207+
/// one version a toolchain of a family the generation uses comes first,
208+
/// then the newer toolchain generation, then the newer toolchain of one
209+
/// name. Versions of two toolchain names are not compared: GCC 14.3.0 and
210+
/// foss 2025b do not count the same way.
211+
fn bump_source_first(
212+
a: &Candidate,
213+
b: &Candidate,
214+
members: &[String],
215+
generations: &BTreeMap<String, Option<String>>,
216+
) -> Ordering {
217+
let generation = |candidate: &Candidate| {
218+
generations
219+
.get(&toolchain_label(candidate))
220+
.cloned()
221+
.flatten()
222+
};
223+
newer_build(a, b)
224+
.then_with(|| in_member_family(b, members).cmp(&in_member_family(a, members)))
225+
.then_with(|| match (generation(a), generation(b)) {
226+
(Some(left), Some(right)) => cmp_version(&right, &left),
227+
(Some(_), None) => Ordering::Less,
228+
(None, Some(_)) => Ordering::Greater,
229+
(None, None) => Ordering::Equal,
208230
})
231+
.then_with(|| a.toolchain.name.cmp(&b.toolchain.name))
232+
.then_with(|| cmp_version(&b.toolchain.version, &a.toolchain.version))
209233
.then_with(|| file_of(a).cmp(&file_of(b)))
210234
}
211235

236+
fn newer_build(a: &Candidate, b: &Candidate) -> Ordering {
237+
cmp_version(&b.version, &a.version).then_with(|| {
238+
a.versionsuffix
239+
.as_deref()
240+
.unwrap_or("")
241+
.len()
242+
.cmp(&b.versionsuffix.as_deref().unwrap_or("").len())
243+
})
244+
}
245+
246+
/// Whether the candidate's toolchain name is the name of a member label,
247+
/// `foss` for `foss-2026.1`.
248+
fn in_member_family(candidate: &Candidate, members: &[String]) -> bool {
249+
let name = candidate.toolchain.name.as_str();
250+
members.iter().any(|label| {
251+
label == name
252+
|| label
253+
.strip_prefix(name)
254+
.and_then(|rest| rest.strip_prefix('-'))
255+
.is_some_and(|version| version.starts_with(|c: char| c.is_ascii_digit()))
256+
})
257+
}
258+
212259
fn reason_for<'a>(map: &'a BTreeMap<String, String>, name: &str) -> Option<&'a str> {
213260
if let Some(reason) = map.get(name) {
214261
return Some(reason.as_str());
@@ -267,6 +314,8 @@ pub fn gap(input: &GapInput<'_>) -> Vec<GapRow> {
267314
.or_default()
268315
.push(candidate);
269316
}
317+
let table = crate::generation_lint::GenerationTable::bundled().ok();
318+
let mut generations: BTreeMap<String, Option<String>> = BTreeMap::new();
270319
let mut rows = Vec::new();
271320
for name in input.site {
272321
if stack_lower.contains(&name.to_lowercase()) {
@@ -316,13 +365,18 @@ pub fn gap(input: &GapInput<'_>) -> Vec<GapRow> {
316365
));
317366
continue;
318367
}
319-
rows.push(row(
320-
name,
321-
"no-recipe",
322-
None,
323-
all.first().map(|candidate| file_of(candidate)),
324-
None,
325-
));
368+
for candidate in &all {
369+
generations
370+
.entry(toolchain_label(candidate))
371+
.or_insert_with_key(|label| {
372+
table.as_ref().and_then(|table| table.generation_of(label))
373+
});
374+
}
375+
let source = all
376+
.iter()
377+
.copied()
378+
.min_by(|a, b| bump_source_first(a, b, input.members, &generations));
379+
rows.push(row(name, "no-recipe", None, source.map(file_of), None));
326380
}
327381
rows
328382
}
@@ -791,6 +845,76 @@ mod tests {
791845
);
792846
}
793847

848+
#[test]
849+
fn an_equal_version_prefers_the_generation_toolchain_family() {
850+
let site = names_from_listing("QuantumESPRESSO\n");
851+
let candidates = vec![
852+
cand(
853+
"QuantumESPRESSO",
854+
"7.5",
855+
("NVHPC", "25.3-CUDA-12.8.0"),
856+
None,
857+
),
858+
cand("QuantumESPRESSO", "7.5", ("foss", "2025a"), None),
859+
cand("QuantumESPRESSO", "7.5", ("lfoss", "2025b"), None),
860+
cand("QuantumESPRESSO", "7.5", ("foss", "2025b"), None),
861+
cand("QuantumESPRESSO", "7.4.1", ("foss", "2025a"), None),
862+
];
863+
let rows = classify(
864+
&site,
865+
&BTreeSet::new(),
866+
&candidates,
867+
&BTreeMap::new(),
868+
&BTreeSet::new(),
869+
&BTreeMap::new(),
870+
&BTreeMap::new(),
871+
);
872+
assert_eq!(rows[0].route, "no-recipe");
873+
assert_eq!(
874+
rows[0].newest_elsewhere.as_deref(),
875+
Some("QuantumESPRESSO-7.5-foss-2025b.eb")
876+
);
877+
}
878+
879+
#[test]
880+
fn an_equal_version_prefers_the_newest_toolchain_generation() {
881+
let site = names_from_listing("X\n");
882+
let candidates = vec![
883+
cand("X", "1.0", ("foss", "2023a"), None),
884+
cand("X", "1.0", ("GCCcore", "11.3.0"), None),
885+
cand("X", "1.0", ("GCC", "14.3.0"), None),
886+
cand("X", "1.0", ("GCC", "13.2.0"), None),
887+
];
888+
let rows = classify(
889+
&site,
890+
&BTreeSet::new(),
891+
&candidates,
892+
&BTreeMap::new(),
893+
&BTreeSet::new(),
894+
&BTreeMap::new(),
895+
&BTreeMap::new(),
896+
);
897+
assert_eq!(
898+
rows[0].newest_elsewhere.as_deref(),
899+
Some("X-1.0-GCC-14.3.0.eb")
900+
);
901+
}
902+
903+
#[test]
904+
fn a_member_family_is_the_toolchain_name_of_a_member() {
905+
let members = ["GCCcore-15.2.0", "foss-2026.1", "llvm-compilers-21.1.8"].map(String::from);
906+
let on = |name: &str| {
907+
in_member_family(&cand("X", "1", (name, "2025b"), None), members.as_slice())
908+
};
909+
assert!(on("foss"));
910+
assert!(on("GCCcore"));
911+
assert!(on("llvm-compilers"));
912+
assert!(!on("GCC"));
913+
assert!(!on("fos"));
914+
assert!(!on("llvm"));
915+
assert!(!on("NVHPC"));
916+
}
917+
794918
#[test]
795919
fn routes_each_site_package() {
796920
let site = names_from_listing("BLAST+/2.16.0-gompi-2024a\nLAMMPS\nJulia/1.10.4\nCP2K/2025.2-foss-2025a\nMATLAB/2025b\nzlib/1.3.1\n");

0 commit comments

Comments
 (0)