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: variant issue with __unix #1272

Merged
merged 3 commits into from
Dec 17, 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
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,40 @@
[
[
[
{
"spec": "python 3.8.*",
"variant": "python"
}
],
{
"constraints": [],
"depends": [
{
"source": "python"
},
{
"source": "__unix"
}
]
}
],
[
[
{
"spec": "python 3.9.*",
"variant": "python"
}
],
{
"constraints": [],
"depends": [
{
"source": "python"
},
{
"source": "__unix"
}
]
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"build": [
"python"
],
"run": [
"python",
"__unix"
]
},
{
"build": [
"python"
],
"run": [
"python",
"__unix"
]
}
]
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 @@ -1160,3 +1160,20 @@ 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"],
output["finalized_dependencies"]["run"],
)
for output in rendered
]
Loading