Skip to content

Commit

Permalink
fix: make noarch-unix and noarch-win work (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Apr 15, 2024
1 parent 930435c commit dee02fa
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub async fn get_build_output(
let selector_config = SelectorConfig {
// We ignore noarch here
target_platform: args.target_platform,
host_platform: args.target_platform,
hash: None,
build_platform: args.build_platform,
variant: BTreeMap::new(),
Expand Down Expand Up @@ -213,6 +214,7 @@ pub async fn get_build_output(
variant: discovered_output.used_vars.clone(),
hash: Some(hash.clone()),
target_platform: selector_config.target_platform,
host_platform: selector_config.host_platform,
build_platform: selector_config.build_platform,
experimental: args.common.experimental,
};
Expand Down
6 changes: 6 additions & 0 deletions src/recipe/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ mod tests {
fn eval() {
let options = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};
Expand All @@ -745,6 +746,7 @@ mod tests {
fn eval2() {
let options = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};
Expand All @@ -759,6 +761,7 @@ mod tests {
let variant = BTreeMap::new();
let options = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
variant,
..Default::default()
Expand Down Expand Up @@ -788,6 +791,7 @@ mod tests {
let variant = BTreeMap::new();
let options = SelectorConfig {
target_platform: Platform::Linux32,
host_platform: Platform::Linux32,
build_platform: Platform::Linux32,
variant,
..Default::default()
Expand Down Expand Up @@ -817,6 +821,7 @@ mod tests {
let variant = BTreeMap::new();
let options = SelectorConfig {
target_platform: Platform::LinuxAarch64,
host_platform: Platform::LinuxAarch64,
build_platform: Platform::LinuxAarch64,
variant,
..Default::default()
Expand Down Expand Up @@ -846,6 +851,7 @@ mod tests {
let variant = BTreeMap::new();
let options = SelectorConfig {
target_platform: Platform::LinuxArmV6l,
host_platform: Platform::LinuxArmV6l,
build_platform: Platform::LinuxArmV6l,
variant,
..Default::default()
Expand Down
2 changes: 2 additions & 0 deletions src/recipe/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ mod tests {

let selector_config_unix = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
..SelectorConfig::default()
};

Expand All @@ -328,6 +329,7 @@ mod tests {

let selector_config_win = SelectorConfig {
target_platform: Platform::Win64,
host_platform: Platform::Win64,
..SelectorConfig::default()
};

Expand Down
7 changes: 5 additions & 2 deletions src/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use rattler_conda_types::Platform;
pub struct SelectorConfig {
/// The target platform to render for
pub target_platform: Platform,
/// The host platform (relevant for `noarch`)
pub host_platform: Platform,
/// The build platform to render for
pub build_platform: Platform,
/// The hash, if available
Expand All @@ -32,7 +34,7 @@ impl SelectorConfig {
Value::from_safe_string(self.target_platform.to_string()),
);

if let Some(platform) = self.target_platform.only_platform() {
if let Some(platform) = self.host_platform.only_platform() {
context.insert(
platform.to_string(),
Value::from_safe_string(platform.to_string()),
Expand All @@ -45,7 +47,7 @@ impl SelectorConfig {

context.insert(
"unix".to_string(),
Value::from(self.target_platform.is_unix()),
Value::from(self.host_platform.is_unix()),
);

context.insert(
Expand Down Expand Up @@ -91,6 +93,7 @@ impl Default for SelectorConfig {
fn default() -> Self {
Self {
target_platform: Platform::current(),
host_platform: Platform::current(),
build_platform: Platform::current(),
hash: None,
variant: Default::default(),
Expand Down
6 changes: 6 additions & 0 deletions src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ mod tests {

let selector_config = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
variant: Default::default(),
hash: None,
Expand All @@ -923,6 +924,7 @@ mod tests {

let selector_config = SelectorConfig {
target_platform: Platform::Win64,
host_platform: Platform::Win64,
build_platform: Platform::Win64,
..Default::default()
};
Expand All @@ -939,6 +941,7 @@ mod tests {
let yaml_file = test_data_dir.join("variant_files/variant_config_1.yaml");
let selector_config = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};
Expand All @@ -954,6 +957,7 @@ mod tests {
let yaml_file = test_data_dir.join("recipes/variants/variant_config.yaml");
let selector_config = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};
Expand Down Expand Up @@ -1022,6 +1026,7 @@ mod tests {
let test_data_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("test-data");
let selector_config = SelectorConfig {
target_platform: Platform::Linux64,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};
Expand Down Expand Up @@ -1053,6 +1058,7 @@ mod tests {
let yaml_file = test_data_dir.join("recipes/variants/python_variant.yaml");
let selector_config = SelectorConfig {
target_platform: Platform::NoArch,
host_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};
Expand Down
29 changes: 29 additions & 0 deletions test-data/recipes/noarch_variant/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
context:
name: rattler-build-demo
version: 1
build_variant: ${{ 'unix' if unix else 'win' }}
build_number: 0

outputs:
- package:
name: ${{ name }}
version: ${{ version }}
build:
noarch: generic
number: ${{ build_number }}
string: ${{ build_variant }}_${{ hash }}_${{ build_number }}
requirements:
run:
- ${{ "__unix" if unix }}
- ${{ "__win" if win }}

- package:
name: ${{ name }}-subpackage
version: ${{ version }}
build:
noarch: generic
number: ${{ build_number }}
string: ${{ build_variant }}_${{ hash }}_${{ build_number }}
requirements:
run:
- ${{ pin_subpackage('rattler-build-demo', exact=True) }}
64 changes: 63 additions & 1 deletion test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import platform
from pathlib import Path
from subprocess import STDOUT, CalledProcessError, check_output
from subprocess import DEVNULL, STDOUT, CalledProcessError, check_output
from typing import Any, Optional

import pytest
Expand Down Expand Up @@ -712,3 +712,65 @@ def test_read_only_removal(rattler_build: RattlerBuild, recipes: Path, tmp_path:
pkg = get_extracted_package(tmp_path, "read-only-build-files")

assert (pkg / "info/index.json").exists()


def test_noarch_variants(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path):
path_to_recipe = recipes / "noarch_variant"
args = rattler_build.build_args(
path_to_recipe,
tmp_path,
)

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

# parse as json
rendered = json.loads(output)
assert len(rendered) == 2

assert rendered[0]["recipe"]["requirements"]["run"] == ["__unix"]
assert rendered[0]["recipe"]["requirements"]["run"] == ["__unix"]
assert rendered[0]["recipe"]["build"]["string"] == "unix_4616a5c_0"

pin = {
"pin_subpackage": {
"name": "rattler-build-demo",
"max_pin": None,
"min_pin": None,
"exact": True,
}
}
assert rendered[1]["recipe"]["build"]["string"] == "unix_2233755_0"
assert rendered[1]["recipe"]["build"]["noarch"] == "generic"
assert rendered[1]["recipe"]["requirements"]["run"] == [pin]
assert rendered[1]["build_configuration"]["variant"] == {
"rattler-build-demo": "1 unix_4616a5c_0",
"target_platform": "noarch",
}

output = rattler_build(
*args, "--target-platform=win-64", "--render-only", stderr=DEVNULL
)
rendered = json.loads(output)
assert len(rendered) == 2

assert rendered[0]["recipe"]["requirements"]["run"] == ["__win"]
assert rendered[0]["recipe"]["requirements"]["run"] == ["__win"]
assert rendered[0]["recipe"]["build"]["string"] == "win_4616a5c_0"

pin = {
"pin_subpackage": {
"name": "rattler-build-demo",
"max_pin": None,
"min_pin": None,
"exact": True,
}
}
assert rendered[1]["recipe"]["build"]["string"] == "win_b28fc4d_0"
assert rendered[1]["recipe"]["build"]["noarch"] == "generic"
assert rendered[1]["recipe"]["requirements"]["run"] == [pin]
assert rendered[1]["build_configuration"]["variant"] == {
"rattler-build-demo": "1 win_4616a5c_0",
"target_platform": "noarch",
}

0 comments on commit dee02fa

Please sign in to comment.