Skip to content

Commit

Permalink
test variant rendering some more, fix __unix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 17, 2024
1 parent 7cf1b3b commit 8df3397
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/render/resolved_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ pub fn apply_variant(
raw_specs: &[Dependency],
build_configuration: &BuildConfiguration,
compatibility_specs: &HashMap<PackageName, PackageRecord>,
build_time: bool,
) -> Result<Vec<DependencyInfo>, ResolveError> {
let variant = &build_configuration.variant;
let subpackages = &build_configuration.subpackages;
Expand All @@ -464,7 +465,7 @@ pub fn apply_variant(
match s {
Dependency::Spec(m) => {
let m = m.clone();
if m.version.is_none() && m.build.is_none() {
if build_time && m.version.is_none() && m.build.is_none() {
if let Some(name) = &m.name {
if let Some(version) = variant.get(&name.into()) {
// if the variant starts with an alphanumeric character,
Expand Down Expand Up @@ -633,7 +634,12 @@ fn render_run_exports(
compatibility_specs: &HashMap<PackageName, PackageRecord>,
) -> Result<RunExportsJson, ResolveError> {
let render_run_exports = |run_export: &[Dependency]| -> Result<Vec<String>, ResolveError> {
let rendered = apply_variant(run_export, &output.build_configuration, compatibility_specs)?;
let rendered = apply_variant(
run_export,
&output.build_configuration,
compatibility_specs,
false,
)?;
Ok(rendered
.iter()
.map(|dep| dep.spec().to_string())
Expand Down Expand Up @@ -680,6 +686,7 @@ pub(crate) async fn resolve_dependencies(
requirements.build(),
&output.build_configuration,
&compatibility_specs,
true,
)?;

let match_specs = build_env_specs
Expand Down Expand Up @@ -737,6 +744,7 @@ pub(crate) async fn resolve_dependencies(
requirements.host(),
&output.build_configuration,
&compatibility_specs,
true,
)?;

// Apply the strong run exports from the build environment to the host
Expand Down Expand Up @@ -776,6 +784,7 @@ pub(crate) async fn resolve_dependencies(
requirements.build(),
&output.build_configuration,
&compatibility_specs,
true,
)?;
match_specs.extend(specs.iter().map(|s| s.spec().clone()));
}
Expand Down Expand Up @@ -830,12 +839,14 @@ pub(crate) async fn resolve_dependencies(
&requirements.run,
&output.build_configuration,
&compatibility_specs,
false,
)?;

let mut constraints = apply_variant(
&requirements.run_constraints,
&output.build_configuration,
&compatibility_specs,
false,
)?;

// add in dependencies from the finalized cache
Expand Down
3 changes: 3 additions & 0 deletions test-data/recipes/recipe_variant/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ build:
requirements:
build:
- python
run:
- python
- __unix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
[
{
"spec": "python 3.8.*",
"variant": "python"
}
],
[
{
"spec": "python 3.9.*",
"variant": "python"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"build": [
"python"
],
"run": [
"python",
"__unix"
]
},
{
"build": [
"python"
],
"run": [
"python",
"__unix"
]
}
]
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 @@ -1160,3 +1160,14 @@ def test_python_min_render(
)

assert snapshot_json == rendered[0]["recipe"]["requirements"]


def test_recipe_variant_render(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, snapshot_json
):
rendered = rattler_build.render(
recipes / "recipe_variant" / "recipe.yaml", tmp_path, "--with-solve"
)

assert snapshot_json == [output["recipe"]["requirements"] for output in rendered]
assert snapshot_json == [output["finalized_dependencies"]["build"]["specs"] for output in rendered]

0 comments on commit 8df3397

Please sign in to comment.