diff --git a/src/render/resolved_dependencies.rs b/src/render/resolved_dependencies.rs index 3fa63023..ec110505 100644 --- a/src/render/resolved_dependencies.rs +++ b/src/render/resolved_dependencies.rs @@ -466,7 +466,9 @@ pub fn apply_variant( let m = m.clone(); if m.version.is_none() && m.build.is_none() { if let Some(name) = &m.name { - if let Some(version) = variant.get(name.as_normalized()) { + if let Some(version) = + variant.get(&name.as_normalized().replace('-', "_")) + { // if the variant starts with an alphanumeric character, // we have to add a '=' to the version spec let mut spec = version.clone(); diff --git a/src/script.rs b/src/script.rs index ceae54bf..7efd40c6 100644 --- a/src/script.rs +++ b/src/script.rs @@ -700,7 +700,7 @@ impl Output { .filter_map(|(k, v)| { let key_upper = k.to_uppercase(); if !languages.contains(key_upper.as_str()) { - Some((k.clone(), Some(v.to_string()))) + Some((k.replace('-', "_"), Some(v.to_string()))) } else { None } diff --git a/src/snapshots/rattler_build__variant_config__tests__load_config_and_find_variants.snap b/src/snapshots/rattler_build__variant_config__tests__load_config_and_find_variants.snap index ad5b25a7..81f6bd6d 100644 --- a/src/snapshots/rattler_build__variant_config__tests__load_config_and_find_variants.snap +++ b/src/snapshots/rattler_build__variant_config__tests__load_config_and_find_variants.snap @@ -3,5 +3,5 @@ source: src/variant_config.rs expression: used_variables_all --- - libblas: 3.9 *netlib - r-base: "4.2" + r_base: "4.2" target_platform: linux-64 diff --git a/src/variant_config.rs b/src/variant_config.rs index 1df99074..5f8f715f 100644 --- a/src/variant_config.rs +++ b/src/variant_config.rs @@ -751,6 +751,13 @@ impl VariantConfig { let ignore_keys = &parsed_recipe.build().variant().ignore_keys; used_filtered.retain(|k, _| ignore_keys.is_empty() || !ignore_keys.contains(k)); + // We also replace `-` with `_` in the keys for better compatibility + // with conda-build and because then we can set them directly as env vars + let used_filtered = used_filtered + .into_iter() + .map(|(k, v)| (k.replace("-", "_"), v)) + .collect::>(); + recipes.insert(DiscoveredOutput { name: name.to_string(), version, diff --git a/test-data/recipes/env_vars/recipe.yaml b/test-data/recipes/env_vars/recipe.yaml index ff531e44..6627743c 100644 --- a/test-data/recipes/env_vars/recipe.yaml +++ b/test-data/recipes/env_vars/recipe.yaml @@ -6,6 +6,15 @@ build: script: - if: unix then: + - echo "Value of $pybind11_abi" + - echo "And jinja style: ${{ pybind11_abi }}" - echo $MAKEFLAGS > $PREFIX/makeflags.txt + - echo $pybind11_abi > $PREFIX/pybind_abi.txt else: - echo %MAKEFLAGS% > %PREFIX%\makeflags.txt + - echo %pybind11_abi% > %PREFIX%\pybind_abi.txt + +requirements: + build: + # use to make the variant "used" + - pybind11-abi diff --git a/test-data/recipes/env_vars/variants.yaml b/test-data/recipes/env_vars/variants.yaml index b1c7dbd9..2562a6c0 100644 --- a/test-data/recipes/env_vars/variants.yaml +++ b/test-data/recipes/env_vars/variants.yaml @@ -1,2 +1,4 @@ MAKEFLAGS: - OVERRIDDEN_MAKEFLAGS +pybind11_abi: + - 4 diff --git a/test-data/variant_files/variant_config_1.yaml b/test-data/variant_files/variant_config_1.yaml index e0ba48fc..fac6f420 100644 --- a/test-data/variant_files/variant_config_1.yaml +++ b/test-data/variant_files/variant_config_1.yaml @@ -73,4 +73,4 @@ arrow_cpp: - 8.0.1 assimp: - 5.2.5 -aws-sdk-cpp: "4.5" +aws_sdk_cpp: "4.5" diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index e316bceb..55029f0f 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -617,11 +617,11 @@ def test_noarch_variants(rattler_build: RattlerBuild, recipes: Path, tmp_path: P "exact": True, } } - assert rendered[1]["recipe"]["build"]["string"] == "unix_2233755_0" + assert rendered[1]["recipe"]["build"]["string"] == "unix_259ce3c_0" assert rendered[1]["recipe"]["build"]["noarch"] == "generic" assert rendered[1]["recipe"]["requirements"]["run"] == [pin] assert rendered[1]["build_configuration"]["variant"] == { - "rattler-build-demo": "1 unix_4616a5c_0", + "rattler_build_demo": "1 unix_4616a5c_0", "target_platform": "noarch", } @@ -641,11 +641,11 @@ def test_noarch_variants(rattler_build: RattlerBuild, recipes: Path, tmp_path: P "exact": True, } } - assert rendered[1]["recipe"]["build"]["string"] == "win_b28fc4d_0" + assert rendered[1]["recipe"]["build"]["string"] == "win_c8f1e9f_0" assert rendered[1]["recipe"]["build"]["noarch"] == "generic" assert rendered[1]["recipe"]["requirements"]["run"] == [pin] assert rendered[1]["build_configuration"]["variant"] == { - "rattler-build-demo": "1 win_4616a5c_0", + "rattler_build_demo": "1 win_4616a5c_0", "target_platform": "noarch", } @@ -985,3 +985,16 @@ def test_env_vars_override(rattler_build: RattlerBuild, recipes: Path, tmp_path: variant_config = json.loads((pkg / "info/hash_input.json").read_text()) assert variant_config["MAKEFLAGS"] == "OVERRIDDEN_MAKEFLAGS" + + text = (pkg / "pybind_abi.txt").read_text() + assert text.strip() == "4" + assert variant_config["pybind11_abi"] == "4" + + # Check that we used the variant in the rendered recipe + rendered_recipe = yaml.safe_load( + (pkg / "info/recipe/rendered_recipe.yaml").read_text() + ) + assert rendered_recipe["finalized_dependencies"]["build"]["specs"][0] == { + "variant": "pybind11-abi", + "spec": "pybind11-abi 4.*", + }