Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix used vars with run dependencies #1037

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/recipe_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ In the following example you can see the implicitly added runtime dependencies.
# - libzlib <-- implicitly added by libzlib
```


### Ignore run exports

There maybe cases where an upstream package has a problematic `run_exports` constraint.
Expand Down
44 changes: 28 additions & 16 deletions src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl VariantConfig {

let noarch_type = parsed_recipe.build().noarch();
// add in any host and build dependencies
used_vars.extend(parsed_recipe.requirements().all().filter_map(|dep| {
used_vars.extend(parsed_recipe.requirements().build_time().filter_map(|dep| {
match dep {
Dependency::Spec(spec) => {
// here we filter python as a variant and don't take it's passed variants
Expand All @@ -418,13 +418,22 @@ impl VariantConfig {
normalized_name.to_string().into()
})
}
Dependency::PinSubpackage(pin) => {
Some(pin.pin_value().name.as_normalized().to_string())
}
_ => None,
}
}));

used_vars.extend(
parsed_recipe
.requirements()
.all()
.filter_map(|dep| match dep {
Dependency::PinSubpackage(pin) => {
Some(pin.pin_value().name.as_normalized().to_string())
}
_ => None,
}),
);

let use_keys = &parsed_recipe.build().variant().use_keys;
used_vars.extend(use_keys.iter().cloned());

Expand Down Expand Up @@ -519,10 +528,8 @@ impl VariantConfig {
errs
})?;
let noarch_type = parsed_recipe.build().noarch();
let build_time_requirements = parsed_recipe
.build_time_requirements()
.cloned()
.filter_map(|dep| {
let build_time_requirements =
parsed_recipe.build_time_requirements().filter_map(|dep| {
// here we filter python as a variant and don't take it's passed variants
// when noarch is python
if let Dependency::Spec(spec) = &dep {
Expand All @@ -532,7 +539,7 @@ impl VariantConfig {
}
}
}
Some(dep)
Some(dep.clone())
});
all_build_dependencies.extend(build_time_requirements);
}
Expand Down Expand Up @@ -620,15 +627,19 @@ impl VariantConfig {
})?;

// find the variables that were actually used in the recipe and that count towards the hash
parsed_recipe.build_time_requirements().for_each(|dep| {
if let Dependency::Spec(spec) = dep {
if let Some(name) = &spec.name {
let val = name.as_normalized().to_owned();
used_variables.insert(val);
}
}
});

parsed_recipe
.build_time_requirements()
.requirements()
.all()
.for_each(|dep| match dep {
Dependency::Spec(spec) => {
if let Some(name) = &spec.name {
let val = name.as_normalized().to_owned();
used_variables.insert(val);
}
}
Dependency::PinSubpackage(pin_sub) => {
let pin = pin_sub.pin_value();
let val = pin.name.as_normalized().to_owned();
Expand All @@ -643,6 +654,7 @@ impl VariantConfig {
exact_pins.insert(val);
}
}
_ => {}
});

// actually used vars
Expand Down
2 changes: 1 addition & 1 deletion test-data/recipes/cache_run_exports/recipe_test_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ outputs:
requirements:
ignore_run_exports:
by_name:
- normal-run-exports
- normal-run-exports
2 changes: 1 addition & 1 deletion test-data/recipes/cache_run_exports/recipe_test_3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cache:
outputs:
- package:
name: cache-ignore-run-exports-by-name
version: "1.0.0"
version: "1.0.0"
12 changes: 12 additions & 0 deletions test-data/recipes/used-vars/recipe_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package:
name: used-vars-1
version: "0.1.0"

build:
noarch: python

requirements:
build:
- python
run:
- numpy
3 changes: 3 additions & 0 deletions test-data/recipes/used-vars/variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy:
- "1.5"
- "2.0"
17 changes: 17 additions & 0 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,3 +939,20 @@ def test_extra_meta_is_recorded_into_about_json(
about_json = json.loads((pkg / "info/about.json").read_text())

assert snapshot_json == about_json


def test_used_vars(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path):
args = rattler_build.build_args(
recipes / "used-vars/recipe_1.yaml",
tmp_path,
)

output = rattler_build(
*args, "--target-platform=linux-64", "--render-only", stderr=DEVNULL
)

rendered = json.loads(output)
assert len(rendered) == 1
assert rendered[0]["build_configuration"]["variant"] == {
"target_platform": "noarch"
}
Loading