diff --git a/src/recipe/parser/requirements.rs b/src/recipe/parser/requirements.rs index 05849450c..ba2b97cfc 100644 --- a/src/recipe/parser/requirements.rs +++ b/src/recipe/parser/requirements.rs @@ -100,8 +100,13 @@ impl Requirements { } /// Get run exports that are ignored. - pub const fn ignore_run_exports(&self) -> &IgnoreRunExports { - &self.ignore_run_exports + pub fn ignore_run_exports(&self, merge: Option<&IgnoreRunExports>) -> IgnoreRunExports { + let mut ignore = self.ignore_run_exports.clone(); + if let Some(merge) = merge { + ignore.by_name.extend(merge.by_name.iter().cloned()); + ignore.from_package.extend(merge.from_package.iter().cloned()); + } + ignore } /// Get all requirements at build time (combines build and host requirements) diff --git a/src/render/resolved_dependencies.rs b/src/render/resolved_dependencies.rs index 4da025807..ca5fe6fa0 100644 --- a/src/render/resolved_dependencies.rs +++ b/src/render/resolved_dependencies.rs @@ -612,66 +612,6 @@ fn render_run_exports( } } -// fn propagate_run_exports_to_run( -// finalized_dependencies: &mut FinalizedDependencies, -// output: &Output, -// ) { -// // filter out the run exports from the build env -// let build_env = finalized_dependencies.build.as_ref(); - -// // Propagate run exports from host env to run env -// if let Some((_, run_exports)) = &host_env { -// match output.build_configuration.target_platform { -// Platform::NoArch => { -// for (name, rex) in run_exports { -// run_specs -// .depends -// .extend(add_run_export_specs(name, "host", &rex.noarch)?); -// } -// } -// _ => { -// for (name, rex) in run_exports { -// run_specs -// .depends -// .extend(add_run_export_specs(name, "host", &rex.strong)?); -// run_specs -// .depends -// .extend(add_run_export_specs(name, "host", &rex.weak)?); -// run_specs.constraints.extend(add_run_export_specs( -// name, -// "host", -// &rex.strong_constrains, -// )?); -// run_specs.constraints.extend(add_run_export_specs( -// name, -// "host", -// &rex.weak_constrains, -// )?); -// } -// } -// } -// } - -// // We also have to propagate the _strong_ run exports of the build environment to the run environment -// if let Some((_, run_exports)) = &build_env { -// match output.build_configuration.target_platform { -// Platform::NoArch => {} -// _ => { -// for (name, rex) in run_exports { -// run_specs -// .depends -// .extend(add_run_export_specs(name, "build", &rex.strong)?); -// run_specs.constraints.extend(add_run_export_specs( -// name, -// "build", -// &rex.strong_constrains, -// )?); -// } -// } -// } -// } -// } - /// This function resolves the dependencies of a recipe. /// To do this, we have to run a couple of steps: /// @@ -748,8 +688,8 @@ pub(crate) async fn resolve_dependencies( build_run_exports.extend(build_env.run_exports(true)); } - let ignore_run_exports = requirements.ignore_run_exports(); - let mut build_run_exports = ignore_run_exports.filter(&build_run_exports, "build")?; + let output_ignore_run_exports = requirements.ignore_run_exports(None); + let mut build_run_exports = output_ignore_run_exports.filter(&build_run_exports, "build")?; if let Some(cache) = &output.finalized_cache_dependencies { if let Some(cache_build_env) = &cache.build { @@ -760,7 +700,7 @@ pub(crate) async fn resolve_dependencies( .as_ref() .expect("recipe should have cache section") .requirements - .ignore_run_exports() + .ignore_run_exports(Some(&output_ignore_run_exports)) .filter(&cache_build_run_exports, "cache-build")?; build_run_exports.extend(&filtered); } @@ -862,7 +802,7 @@ pub(crate) async fn resolve_dependencies( } // And filter the run exports - let mut host_run_exports = ignore_run_exports.filter(&host_run_exports, "host")?; + let mut host_run_exports = output_ignore_run_exports.filter(&host_run_exports, "host")?; if let Some(cache) = &output.finalized_cache_dependencies { if let Some(cache_host_env) = &cache.host { @@ -873,7 +813,7 @@ pub(crate) async fn resolve_dependencies( .as_ref() .expect("recipe should have cache section") .requirements - .ignore_run_exports() + .ignore_run_exports(Some(&output_ignore_run_exports)) .filter(&cache_host_run_exports, "cache-host")?; host_run_exports.extend(&filtered); } @@ -896,7 +836,7 @@ pub(crate) async fn resolve_dependencies( if let Some(cache) = &output.finalized_cache_dependencies { // add in the run exports from the cache // filter run dependencies that came from run exports - let ignore_run_exports = requirements.ignore_run_exports(); + let ignore_run_exports = requirements.ignore_run_exports(None); // Note: these run exports are already filtered let _cache_run_exports = cache.run.depends.iter().filter(|c| match c { DependencyInfo::RunExport(run_export) => { diff --git a/test-data/recipes/cache_run_exports/helper.yaml b/test-data/recipes/cache_run_exports/helper.yaml new file mode 100644 index 000000000..51e1f791a --- /dev/null +++ b/test-data/recipes/cache_run_exports/helper.yaml @@ -0,0 +1,14 @@ +outputs: + - package: + name: normal-run-exports + version: "1.0.0" + requirements: + run_exports: + - normal-run-exports + - package: + name: strong-run-exports + version: "1.0.0" + requirements: + run_exports: + strong: + - normal-run-exports diff --git a/test-data/recipes/cache_run_exports/recipe_test_1.yaml b/test-data/recipes/cache_run_exports/recipe_test_1.yaml new file mode 100644 index 000000000..838af63f4 --- /dev/null +++ b/test-data/recipes/cache_run_exports/recipe_test_1.yaml @@ -0,0 +1,23 @@ +cache: + requirements: + host: + - normal-run-exports + +outputs: + - package: + name: cache-run-exports + version: "1.0.0" + - package: + name: no-cache-from-package-run-exports + version: "1.0.0" + requirements: + ignore_run_exports: + from_package: + - normal-run-exports + - package: + name: no-cache-by-name-run-exports + version: "1.0.0" + requirements: + ignore_run_exports: + by_name: + - normal-run-exports \ No newline at end of file diff --git a/test-data/recipes/cache_run_exports/recipe_test_2.yaml b/test-data/recipes/cache_run_exports/recipe_test_2.yaml new file mode 100644 index 000000000..30fc17d90 --- /dev/null +++ b/test-data/recipes/cache_run_exports/recipe_test_2.yaml @@ -0,0 +1,12 @@ +cache: + requirements: + host: + - normal-run-exports + ignore_run_exports: + from_package: + - normal-run-exports + +outputs: + - package: + name: cache-ignore-run-exports + version: "1.0.0" diff --git a/test-data/recipes/cache_run_exports/recipe_test_3.yaml b/test-data/recipes/cache_run_exports/recipe_test_3.yaml new file mode 100644 index 000000000..fb1da21a2 --- /dev/null +++ b/test-data/recipes/cache_run_exports/recipe_test_3.yaml @@ -0,0 +1,12 @@ +cache: + requirements: + host: + - normal-run-exports + ignore_run_exports: + by_name: + - normal-run-exports + +outputs: + - package: + name: cache-ignore-run-exports-by-name + version: "1.0.0" \ No newline at end of file diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 7ec9bfa43..22c844b37 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -984,3 +984,40 @@ def test_downstream_test( assert "│ Failing test in downstream package" in e.value.output assert "│ Downstream test failed" in e.value.output + +def test_cache_runexports( + rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, snapshot_json +): + rattler_build.build(recipes / "cache_run_exports/helper.yaml", tmp_path) + rattler_build.build(recipes / "cache_run_exports/recipe_test_1.yaml", tmp_path, extra_args=["--experimental"]) + + pkg = get_extracted_package(tmp_path, "cache-run-exports") + + assert (pkg / "info/index.json").exists() + index = json.loads((pkg / "info/index.json").read_text()) + assert index["depends"] == ["normal-run-exports"] + + pkg = get_extracted_package(tmp_path, "no-cache-by-name-run-exports") + assert (pkg / "info/index.json").exists() + index = json.loads((pkg / "info/index.json").read_text()) + assert index["name"] == "no-cache-by-name-run-exports" + assert index.get("depends", []) == [] + + pkg = get_extracted_package(tmp_path, "no-cache-from-package-run-exports") + assert (pkg / "info/index.json").exists() + index = json.loads((pkg / "info/index.json").read_text()) + assert index["name"] == "no-cache-from-package-run-exports" + print(index) + assert index.get("depends", []) == [] + + rattler_build.build(recipes / "cache_run_exports/recipe_test_2.yaml", tmp_path, extra_args=["--experimental"]) + pkg = get_extracted_package(tmp_path, "cache-ignore-run-exports") + index = json.loads((pkg / "info/index.json").read_text()) + assert index["name"] == "cache-ignore-run-exports" + assert index.get("depends", []) == [] + + rattler_build.build(recipes / "cache_run_exports/recipe_test_3.yaml", tmp_path, extra_args=["--experimental"]) + pkg = get_extracted_package(tmp_path, "cache-ignore-run-exports-by-name") + index = json.loads((pkg / "info/index.json").read_text()) + assert index["name"] == "cache-ignore-run-exports-by-name" + assert index.get("depends", []) == []