From 2a0f572119c262550094a39edfb7b145cf666b46 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 17 Dec 2024 13:36:40 -0500 Subject: [PATCH] fix: variant issue with `__unix` (#1272) --- src/render/resolved_dependencies.rs | 15 ++++++- test-data/recipes/recipe_variant/recipe.yaml | 3 ++ .../test_recipe_variant_render.1.json | 40 +++++++++++++++++++ .../test_recipe_variant_render.json | 20 ++++++++++ test/end-to-end/test_simple.py | 17 ++++++++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json create mode 100644 test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json diff --git a/src/render/resolved_dependencies.rs b/src/render/resolved_dependencies.rs index b801e824e..ffb934859 100644 --- a/src/render/resolved_dependencies.rs +++ b/src/render/resolved_dependencies.rs @@ -454,6 +454,7 @@ pub fn apply_variant( raw_specs: &[Dependency], build_configuration: &BuildConfiguration, compatibility_specs: &HashMap, + build_time: bool, ) -> Result, ResolveError> { let variant = &build_configuration.variant; let subpackages = &build_configuration.subpackages; @@ -464,7 +465,7 @@ pub fn apply_variant( match s { Dependency::Spec(m) => { let m = m.clone(); - if m.version.is_none() && m.build.is_none() { + if build_time && m.version.is_none() && m.build.is_none() { if let Some(name) = &m.name { if let Some(version) = variant.get(&name.into()) { // if the variant starts with an alphanumeric character, @@ -633,7 +634,12 @@ fn render_run_exports( compatibility_specs: &HashMap, ) -> Result { let render_run_exports = |run_export: &[Dependency]| -> Result, ResolveError> { - let rendered = apply_variant(run_export, &output.build_configuration, compatibility_specs)?; + let rendered = apply_variant( + run_export, + &output.build_configuration, + compatibility_specs, + false, + )?; Ok(rendered .iter() .map(|dep| dep.spec().to_string()) @@ -680,6 +686,7 @@ pub(crate) async fn resolve_dependencies( requirements.build(), &output.build_configuration, &compatibility_specs, + true, )?; let match_specs = build_env_specs @@ -737,6 +744,7 @@ pub(crate) async fn resolve_dependencies( requirements.host(), &output.build_configuration, &compatibility_specs, + true, )?; // Apply the strong run exports from the build environment to the host @@ -776,6 +784,7 @@ pub(crate) async fn resolve_dependencies( requirements.build(), &output.build_configuration, &compatibility_specs, + true, )?; match_specs.extend(specs.iter().map(|s| s.spec().clone())); } @@ -830,12 +839,14 @@ pub(crate) async fn resolve_dependencies( &requirements.run, &output.build_configuration, &compatibility_specs, + false, )?; let mut constraints = apply_variant( &requirements.run_constraints, &output.build_configuration, &compatibility_specs, + false, )?; // add in dependencies from the finalized cache diff --git a/test-data/recipes/recipe_variant/recipe.yaml b/test-data/recipes/recipe_variant/recipe.yaml index 7826bddb0..e7162b962 100644 --- a/test-data/recipes/recipe_variant/recipe.yaml +++ b/test-data/recipes/recipe_variant/recipe.yaml @@ -8,3 +8,6 @@ build: requirements: build: - python + run: + - python + - __unix diff --git a/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json new file mode 100644 index 000000000..9f070ede1 --- /dev/null +++ b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json @@ -0,0 +1,40 @@ +[ + [ + [ + { + "spec": "python 3.8.*", + "variant": "python" + } + ], + { + "constraints": [], + "depends": [ + { + "source": "python" + }, + { + "source": "__unix" + } + ] + } + ], + [ + [ + { + "spec": "python 3.9.*", + "variant": "python" + } + ], + { + "constraints": [], + "depends": [ + { + "source": "python" + }, + { + "source": "__unix" + } + ] + } + ] +] diff --git a/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json new file mode 100644 index 000000000..1e4bac2b5 --- /dev/null +++ b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json @@ -0,0 +1,20 @@ +[ + { + "build": [ + "python" + ], + "run": [ + "python", + "__unix" + ] + }, + { + "build": [ + "python" + ], + "run": [ + "python", + "__unix" + ] + } +] diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 5dedd6d27..cfae8ce81 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -1160,3 +1160,20 @@ def test_python_min_render( ) assert snapshot_json == rendered[0]["recipe"]["requirements"] + + +def test_recipe_variant_render( + rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, snapshot_json +): + rendered = rattler_build.render( + recipes / "recipe_variant" / "recipe.yaml", tmp_path, "--with-solve" + ) + + assert snapshot_json == [output["recipe"]["requirements"] for output in rendered] + assert snapshot_json == [ + ( + output["finalized_dependencies"]["build"]["specs"], + output["finalized_dependencies"]["run"], + ) + for output in rendered + ]