From 32e8b447a7fc0d11789a6afc16e550de438c1634 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 16 Nov 2026 03:32:36 +0000 Subject: [PATCH] fix(solve): keep a dependency's stated versionsuffix The profile solve built every direct requirement with versionsuffix None, while the missing-dependency check matched the stated suffix. A dependency the check found satisfied could then lock another build of the same version: the provider ranks builds by version and then suffix, so the last suffix in string order won. package bump of a GCCcore-15.2.0 recipe depending on ('HDF5', '1.14.2', '-mpi'), against a tree with the plain, -mpi and -serial HDF5 1.14.2 builds, locked HDF5-1.14.2-GCCcore-15.2.0-serial.eb and rewrote the tuple to '-serial'. ('HDF5', '1.14.2', '') went the same way. The requirement now carries the stated suffix when a candidate the solve can take has it, with the name, version requirement and toolchain the check uses. Otherwise the suffix is left open as before, so across a generation -CUDA-12.9.1 still takes the -CUDA-13.3.0 build when the target carries only that one, and the bump_workflow test for it passes unchanged. A profile_emission test solves the plan directly and a bump_workflow test runs the bump. Both fail without the fix. bump-recipe.org states the rule. --- changelog.d/+solve-versionsuffix.bugfix.md | 1 + docs/orgmode/howto/bump-recipe.org | 7 ++ llms-full.txt | 7 ++ src/package_solve.rs | 25 +++++- tests/bump_workflow.rs | 96 ++++++++++++++++++++++ tests/profile_emission.rs | 43 ++++++++++ 6 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 changelog.d/+solve-versionsuffix.bugfix.md diff --git a/changelog.d/+solve-versionsuffix.bugfix.md b/changelog.d/+solve-versionsuffix.bugfix.md new file mode 100644 index 00000000..647fd759 --- /dev/null +++ b/changelog.d/+solve-versionsuffix.bugfix.md @@ -0,0 +1 @@ +`package bump` and `package plan` keep a dependency's stated versionsuffix when the robot tree has a build with it that the solve can take: `('HDF5', '1.14.2', '-mpi')` and `('HDF5', '1.14.2', '')` no longer become the `-serial` build because that one ranks higher. The solve takes another suffix only when the target has no build with the stated one, as when `-CUDA-12.9.1` moves to `-CUDA-13.3.0` across a generation. diff --git a/docs/orgmode/howto/bump-recipe.org b/docs/orgmode/howto/bump-recipe.org index 6618ee45..d095420e 100644 --- a/docs/orgmode/howto/bump-recipe.org +++ b/docs/orgmode/howto/bump-recipe.org @@ -20,6 +20,13 @@ target toolchain hierarchy from the robot tree, and asks Resolvo for a jointly feasible dependency selection. Existing robot artifacts keep independent build-tool scopes, matching EasyBuild's installed-module model. +A dependency's versionsuffix, as in ~('HDF5', '1.14.2', '-mpi')~, holds +wherever the robot tree has a build with that suffix the solve can take, +so the bump does not trade ~-mpi~ for ~-serial~. Only when the target has +no such build does the solve take another suffix: a library's +~-CUDA-12.9.1~ build becomes its ~-CUDA-13.3.0~ build when the target +generation carries only that one. + The output is: #+begin_src text diff --git a/llms-full.txt b/llms-full.txt index 5591be69..5f226274 100644 --- a/llms-full.txt +++ b/llms-full.txt @@ -2439,6 +2439,13 @@ target toolchain hierarchy from the robot tree, and asks Resolvo for a jointly feasible dependency selection. Existing robot artifacts keep independent build-tool scopes, matching EasyBuild's installed-module model. +A dependency's versionsuffix, as in `('HDF5', '1.14.2', '-mpi')`, holds +wherever the robot tree has a build with that suffix the solve can take, +so the bump does not trade `-mpi` for `-serial`. Only when the target has +no such build does the solve take another suffix: a library's +`-CUDA-12.9.1` build becomes its `-CUDA-13.3.0` build when the target +generation carries only that one. + The output is: ```text diff --git a/src/package_solve.rs b/src/package_solve.rs index fa3990f2..b4e6492c 100644 --- a/src/package_solve.rs +++ b/src/package_solve.rs @@ -260,7 +260,7 @@ pub fn solve_package_profile_with_hierarchy( let requirement = DepReq { name: name.clone(), version_req: normalize_requirement(dependency.constraint.as_deref()), - versionsuffix: None, + versionsuffix: dependency.versionsuffix.clone(), toolchain: dependency.toolchain.clone(), }; if build_only { @@ -338,6 +338,29 @@ pub fn solve_package_profile_with_hierarchy( } } scope_cross_generation_pin_closures(&mut universe, stack_policy, &hierarchy); + // A stated versionsuffix holds wherever a build the solve can take + // carries it: `-mpi` is not traded for `-serial`. Across a generation it + // may name a version that moved instead, and `-CUDA-12.9.1` then takes + // the `-CUDA-13.3.0` build when the target carries only that one. + for requirement in runtime_dependencies + .iter_mut() + .chain(build_dependencies.iter_mut()) + { + let carried = requirement.versionsuffix.as_deref().is_some_and(|wanted| { + universe.iter().any(|candidate| { + package_identities_match(&candidate.name, &requirement.name) + && candidate.versionsuffix.as_deref().unwrap_or("") == wanted + && candidate_matches_any_spelling(candidate, &requirement.version_req) + && requirement + .toolchain + .as_ref() + .is_none_or(|toolchain| toolchains_match(&candidate.toolchain, toolchain)) + }) + }); + if !carried { + requirement.versionsuffix = None; + } + } universe.push(Candidate { easyblock: None, name: synthetic_name.clone(), diff --git a/tests/bump_workflow.rs b/tests/bump_workflow.rs index 95d662a7..506ea3f4 100644 --- a/tests/bump_workflow.rs +++ b/tests/bump_workflow.rs @@ -1151,6 +1151,102 @@ fn a_system_dependency_named_by_the_versionsuffix_moves_with_the_generation() { ); } +/// `-serial` ranks above the plain build and `-mpi`, so a solve that drops +/// the stated suffix takes it. +#[test] +fn a_bump_keeps_the_stated_versionsuffix_variant() { + let temp = tempfile::tempdir().expect("tempdir"); + let robot = temp.path().join("robot"); + fs::create_dir_all(&robot).expect("robot directory"); + fs::write( + robot.join("GCCcore-15.2.0.eb"), + "easyblock = 'Toolchain'\nname = 'GCCcore'\nversion = '15.2.0'\n\ + homepage = 'https://example.invalid/'\ndescription = 'compiler'\n\ + toolchain = SYSTEM\nsources = []\nchecksums = []\nmoduleclass = 'compiler'\n", + ) + .expect("GCCcore candidate"); + for suffix in ["", "-mpi", "-serial"] { + fs::write( + robot.join(format!("HDF5-1.14.2-GCCcore-15.2.0{suffix}.eb")), + format!( + "easyblock = 'ConfigureMake'\nname = 'HDF5'\nversion = '1.14.2'\n\ + versionsuffix = '{suffix}'\n\ + homepage = 'https://example.invalid/'\ndescription = 'HDF5'\n\ + toolchain = {{'name': 'GCCcore', 'version': '15.2.0'}}\n\ + sources = []\nchecksums = []\nmoduleclass = 'data'\n" + ), + ) + .expect("HDF5 candidate"); + } + let toolchain = Toolchain { + name: "GCCcore".into(), + version: "15.2.0".into(), + }; + for (stated, selected) in [("-mpi", "-mpi"), ("", "")] { + let source = temp + .path() + .join(format!("Alpha-1.0-GCCcore-15.2.0{stated}.eb")); + fs::write( + &source, + format!( + "easyblock = 'ConfigureMake'\nname = 'Alpha'\nversion = '1.0'\n\ + versionsuffix = '{stated}'\n\ + homepage = 'https://example.invalid/'\ndescription = 'Synthetic package'\n\ + toolchain = {{'name': 'GCCcore', 'version': '15.2.0'}}\n\ + sources = ['alpha-1.0.tar.gz']\n\ + checksums = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']\n\ + dependencies = [('HDF5', '1.14.2', '{stated}')]\n\ + moduleclass = 'tools'\n" + ), + ) + .expect("source recipe"); + let bundle = plan_package_bump(&BumpPackageRequest { + source, + toolchain: toolchain.clone(), + version: None, + source_checksum: None, + easyconfig_roots: vec![robot.clone()], + hierarchy_fixture: None, + overrides: HashMap::new(), + stack_policy: StackPolicy { + schema_version: STACK_POLICY_SCHEMA_VERSION, + name: "default".into(), + toolchain: toolchain.clone(), + pins: Vec::new(), + exclusions: Vec::new(), + }, + strict_patches: false, + package_layers: Vec::new(), + foreign_sources: Vec::new(), + }) + .expect("the bump solves"); + let hdf5 = bundle.locks[0] + .dependencies + .iter() + .find(|dependency| dependency.name == "HDF5") + .expect("HDF5 is locked"); + assert_eq!( + hdf5.easyconfig_path, + robot + .join(format!("HDF5-1.14.2-GCCcore-15.2.0{selected}.eb")) + .display() + .to_string(), + "stated suffix {stated:?}" + ); + let recipe = + resolve_easyconfig_str(&bundle.easyconfigs[0].text).expect("parse bumped recipe"); + assert_eq!( + recipe.dependencies[0] + .versionsuffix + .as_deref() + .unwrap_or(""), + selected, + "{}", + bundle.easyconfigs[0].text + ); + } +} + #[test] fn a_patch_an_extension_names_travels_with_the_bundle() { let temp = tempfile::tempdir().expect("tempdir"); diff --git a/tests/profile_emission.rs b/tests/profile_emission.rs index a018a7e7..9dc47f84 100644 --- a/tests/profile_emission.rs +++ b/tests/profile_emission.rs @@ -690,6 +690,49 @@ fn profile_solver_matches_unmapped_foreign_names_to_robot_candidates() { assert_eq!(lock.dependencies[0].name, "SomeLib"); } +/// The suffix asked for ranks between the other two, so the lock holds it +/// only when the solve requires it. +#[test] +fn a_dependency_versionsuffix_selects_that_variant() { + let recipe = parse_foreign_path(&fixture(), Some(ForeignFormat::Spack)).expect("parse"); + let mut plan = package_plan_from_foreign(&recipe, &toolchain()); + plan.profiles = qmcpack_profiles(); + plan.dependencies + .retain(|dependency| dependency.name == "hdf5"); + plan.dependencies[0].versionsuffix = Some("-mpi".into()); + let variant = |suffix: &str| Candidate { + versionsuffix: Some(suffix.into()), + easyconfig_path: format!("HDF5-1.14.2-foss-2026.1{suffix}.eb"), + ..hdf5_candidate("1.14.2") + }; + let stack = StackPolicy { + schema_version: STACK_POLICY_SCHEMA_VERSION, + name: "test".into(), + toolchain: toolchain(), + pins: Vec::new(), + exclusions: Vec::new(), + }; + + let lock = solve_package_profile( + &plan, + "default", + &ProfileEnvironment::default(), + &[ + hdf5_candidate("1.14.2"), + variant("-mpi"), + variant("-serial"), + ], + &stack, + ) + .expect("profile solve"); + assert_eq!(lock.dependencies.len(), 1); + assert_eq!(lock.dependencies[0].versionsuffix.as_deref(), Some("-mpi")); + assert_eq!( + lock.dependencies[0].easyconfig_path, + "HDF5-1.14.2-foss-2026.1-mpi.eb" + ); +} + #[test] fn foreign_build_roles_create_easybuild_builddependencies() { let recipe = parse_foreign_path(&fixture(), Some(ForeignFormat::Spack)).expect("parse");