@@ -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.
200202fn 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+
212259fn 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\n LAMMPS\n Julia/1.10.4\n CP2K/2025.2-foss-2025a\n MATLAB/2025b\n zlib/1.3.1\n " ) ;
0 commit comments