diff --git a/docs/reference/recipe_file.md b/docs/reference/recipe_file.md index 7860b676..35d8e7b0 100644 --- a/docs/reference/recipe_file.md +++ b/docs/reference/recipe_file.md @@ -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. diff --git a/src/variant_config.rs b/src/variant_config.rs index 7931f4ba..20ed0eaf 100644 --- a/src/variant_config.rs +++ b/src/variant_config.rs @@ -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 @@ -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()); @@ -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 { @@ -532,7 +539,7 @@ impl VariantConfig { } } } - Some(dep) + Some(dep.clone()) }); all_build_dependencies.extend(build_time_requirements); } @@ -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(); @@ -643,6 +654,7 @@ impl VariantConfig { exact_pins.insert(val); } } + _ => {} }); // actually used vars diff --git a/test-data/recipes/cache_run_exports/recipe_test_1.yaml b/test-data/recipes/cache_run_exports/recipe_test_1.yaml index 838af63f..3cb7acb2 100644 --- a/test-data/recipes/cache_run_exports/recipe_test_1.yaml +++ b/test-data/recipes/cache_run_exports/recipe_test_1.yaml @@ -20,4 +20,4 @@ outputs: requirements: ignore_run_exports: by_name: - - normal-run-exports \ No newline at end of file + - normal-run-exports diff --git a/test-data/recipes/cache_run_exports/recipe_test_3.yaml b/test-data/recipes/cache_run_exports/recipe_test_3.yaml index fb1da21a..9d15058b 100644 --- a/test-data/recipes/cache_run_exports/recipe_test_3.yaml +++ b/test-data/recipes/cache_run_exports/recipe_test_3.yaml @@ -9,4 +9,4 @@ cache: outputs: - package: name: cache-ignore-run-exports-by-name - version: "1.0.0" \ No newline at end of file + version: "1.0.0" diff --git a/test-data/recipes/used-vars/recipe_1.yaml b/test-data/recipes/used-vars/recipe_1.yaml new file mode 100644 index 00000000..4edba1e6 --- /dev/null +++ b/test-data/recipes/used-vars/recipe_1.yaml @@ -0,0 +1,12 @@ +package: + name: used-vars-1 + version: "0.1.0" + +build: + noarch: python + +requirements: + build: + - python + run: + - numpy diff --git a/test-data/recipes/used-vars/variants.yaml b/test-data/recipes/used-vars/variants.yaml new file mode 100644 index 00000000..77e5f6c1 --- /dev/null +++ b/test-data/recipes/used-vars/variants.yaml @@ -0,0 +1,3 @@ +numpy: + - "1.5" + - "2.0" diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index adf1cea3..d3b3a5df 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -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" + }