Skip to content

Commit

Permalink
fix: dot in variant when exporting to environment (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Oct 16, 2024
1 parent dd23a73 commit c56adc4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/used_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,15 @@ fn extract_variable_from_expression(expr: &Expr, variables: &mut HashSet<String>
variables.insert(format!("{}_stdlib", &constant.value));
variables.insert(format!("{}_stdlib_version", &constant.value));
}
} else if function == "pin_subpackage" {
if let Expr::Const(constant) = &call.args[0] {
variables.insert(format!("{}", &constant.value));
} else if function == "pin_subpackage" || function == "pin_compatible" {
if !call.args.is_empty() {
extract_variable_from_expression(&call.args[0], variables);
}
} else if function == "cdt" {
variables.insert("cdt_name".into());
variables.insert("cdt_arch".into());
} else if function == "cmp" {
if let Expr::Var(var) = &call.args[0] {
variables.insert(var.id.to_string());
}
extract_variable_from_expression(&call.args[0], variables);
}
}
}
Expand Down Expand Up @@ -314,7 +312,10 @@ mod test {
then: osx-clang
- ${{ compiler('c') }}
- ${{ stdlib('c') }}
- ${{ pin_subpackage('abcdef') }}
- ${{ pin_subpackage(abcdef) }}
- ${{ pin_subpackage("foobar") }}
- ${{ pin_compatible(compatible) }}
- ${{ pin_compatible(abc ~ def) }}
"#;

let recipe_node = crate::recipe::custom_yaml::Node::parse_yaml(0, recipe).unwrap();
Expand All @@ -327,6 +328,10 @@ mod test {
assert!(used_vars.contains("c_stdlib"));
assert!(used_vars.contains("c_stdlib_version"));
assert!(used_vars.contains("abcdef"));
assert!(!used_vars.contains("foobar"));
assert!(used_vars.contains("compatible"));
assert!(used_vars.contains("abc"));
assert!(used_vars.contains("def"));
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,11 @@ impl VariantConfig {

// We also replace `-` with `_` in the keys for better compatibility
// with conda-build and because then we can set them directly as env vars
// and the same for `.` because we want to be able to set them as env vars directly
let used_filtered = used_filtered
.into_iter()
.map(|(k, v)| (k.replace("-", "_"), v))
.map(|(k, v)| (k.replace(".", "_"), v))
.collect::<BTreeMap<_, _>>();

recipes.insert(DiscoveredOutput {
Expand Down Expand Up @@ -1066,7 +1068,7 @@ mod tests {
.unwrap();

// assert output order
let order = vec!["some-pkg-a", "some-pkg", "some_pkg"];
let order = vec!["some-pkg.foo-a", "some-pkg.foo", "some_pkg.foo"];
let outputs: Vec<_> = outputs_and_variants
.iter()
.map(|o| o.name.clone())
Expand Down
2 changes: 1 addition & 1 deletion test-data/recipes/output_order/order_1.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context:
name: some-pkg
name: some-pkg.foo
name_a: ${{ name }}-a
version: 1.0.0
build_number: 0
Expand Down
23 changes: 23 additions & 0 deletions test-data/recipes/pin_subpackage/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# regression test that pin subpackage works with `my.package`
context:
name: my.package
version: 0.1.0

recipe:
version: ${{ version }}
build:
number: 0

outputs:
- package:
name: ${{ name }}
build:
noarch: generic

- package:
name: ${{ name }}-a
build:
noarch: generic
requirements:
run:
- ${{ pin_subpackage(name, exact=true) }}
11 changes: 11 additions & 0 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,3 +998,14 @@ def test_env_vars_override(rattler_build: RattlerBuild, recipes: Path, tmp_path:
"variant": "pybind11-abi",
"spec": "pybind11-abi 4.*",
}


def test_pin_subpackage(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, snapshot_json
):
rattler_build.build(
recipes / "pin_subpackage",
tmp_path,
)
pkg = get_extracted_package(tmp_path, "my.package-a")
assert (pkg / "info/index.json").exists()

0 comments on commit c56adc4

Please sign in to comment.