Skip to content

Commit

Permalink
fix: dashes / underscores in variants and env variables (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Oct 9, 2024
1 parent e58cee0 commit c472069
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/render/resolved_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BTreeMap<_, _>>();

recipes.insert(DiscoveredOutput {
name: name.to_string(),
version,
Expand Down
9 changes: 9 additions & 0 deletions test-data/recipes/env_vars/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test-data/recipes/env_vars/variants.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
MAKEFLAGS:
- OVERRIDDEN_MAKEFLAGS
pybind11_abi:
- 4
2 changes: 1 addition & 1 deletion test-data/variant_files/variant_config_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ arrow_cpp:
- 8.0.1
assimp:
- 5.2.5
aws-sdk-cpp: "4.5"
aws_sdk_cpp: "4.5"
21 changes: 17 additions & 4 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand All @@ -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",
}

Expand Down Expand Up @@ -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.*",
}

0 comments on commit c472069

Please sign in to comment.