Skip to content

Commit

Permalink
fix: order of builds and recipe key schema (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Feb 12, 2024
1 parent 146d045 commit 866b671
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 12 deletions.
38 changes: 27 additions & 11 deletions src/recipe/parser/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,32 @@ pub fn find_outputs_from_src(src: &str) -> Result<Vec<Node>, ParsingError> {
return Ok(vec![recipe]);
};

// TODO: Schema
let mut recipe_version: Option<marked_yaml::Node> = None;
// If `recipe` exists in root we will use the version as default for all outputs
// We otherwise ignore the `recipe.name` value.
if let Some(recipe_mapping) = root_map
.get("recipe")
.and_then(|recipe| recipe.as_mapping())
{
// make sure that mapping only contains name and version
for (k, v) in recipe_mapping.iter() {
match k.as_str() {
"name" => {}
"version" => recipe_version = Some(v.clone()),
_ => {
return Err(ParsingError::from_partial(
src,
_partialerror!(
*k.span(),
ErrorKind::InvalidField(k.as_str().to_string().into()),
help = "recipe can only contain `name` and `version` fields"
),
));
}
}
}
}

let outputs = outputs.as_sequence().ok_or_else(|| {
ParsingError::from_partial(
src,
Expand All @@ -107,18 +132,9 @@ pub fn find_outputs_from_src(src: &str) -> Result<Vec<Node>, ParsingError> {
// 4. merge skip values (make sure to preserve the spans)
// Note: Make sure to preserve the spans of the original root span so the error
// messages remain accurate and point the correct part of the original recipe src

let mut root = root_map.clone();
root.remove("outputs");

// recipe.version, if exists in root, and package.version doesn't exist in output, we will
// use that instead
// ignore recipe.name
let version = root
.get("recipe")
.and_then(|recipe| recipe.as_mapping())
.and_then(|recipe| recipe.get("version"));

let mut output_node = output.clone();

let output_map = output_node.as_mapping_mut().ok_or_else(|| {
Expand Down Expand Up @@ -173,7 +189,7 @@ pub fn find_outputs_from_src(src: &str) -> Result<Vec<Node>, ParsingError> {
}
}

if let Some(version) = version {
if let Some(version) = recipe_version.as_ref() {
let Some(package_map) = output_map
.get_mut("package")
.and_then(|node| node.as_mapping_mut())
Expand Down
38 changes: 37 additions & 1 deletion src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,15 @@ impl VariantConfig {
let noarch_type = parsed_recipe.build().noarch();

// add in any host and build dependencies
used_vars.extend(parsed_recipe.requirements().build_time().filter_map(|dep| {
used_vars.extend(parsed_recipe.requirements().all().filter_map(|dep| {
match dep {
Dependency::Spec(spec) => spec
.name
.as_ref()
.and_then(|name| name.as_normalized().to_string().into()),
Dependency::PinSubpackage(pin) => {
Some(pin.pin_value().name.as_normalized().to_string())
}
_ => None,
}
}));
Expand Down Expand Up @@ -525,6 +528,9 @@ impl VariantConfig {
None
}
}
Dependency::PinSubpackage(pin_sub) => {
Some(pin_sub.pin_value().name.as_normalized().to_string())
}
_ => None,
})
.collect::<HashSet<_>>();
Expand Down Expand Up @@ -986,4 +992,34 @@ mod tests {
let combinations = config.combinations(&used_vars).unwrap();
assert_eq!(combinations.len(), 2 * 2 * 3);
}

#[test]
fn test_order() {
let test_data_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("test-data");
let selector_config = SelectorConfig {
target_platform: Platform::Linux64,
build_platform: Platform::Linux64,
..Default::default()
};

for _ in 1..3 {
// First find all outputs from the recipe
let recipe_text =
std::fs::read_to_string(test_data_dir.join("recipes/output_order/order_1.yaml"))
.unwrap();
let outputs = crate::recipe::parser::find_outputs_from_src(&recipe_text).unwrap();
let variant_config = VariantConfig::from_files(&vec![], &selector_config).unwrap();
let outputs_and_variants = variant_config
.find_variants(&outputs, &recipe_text, &selector_config)
.unwrap();

// assert output order
let order = vec!["some-pkg-a", "some-pkg", "some_pkg"];
let outputs: Vec<_> = outputs_and_variants
.iter()
.map(|o| o.name.clone())
.collect();
assert_eq!(outputs, order);
}
}
}
47 changes: 47 additions & 0 deletions test-data/recipes/output_order/order_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
context:
name: some-pkg
name_a: ${{ name }}-a
version: 1.0.0
build_number: 0

recipe:
name: ${{ name }}
version: ${{ version }}

source:
path: ../

outputs:
- package:
name: ${{ name }}
version: ${{ version }}
build:
noarch: python
number: ${{ build_number }}
requirements:
host:
- python >=3.10
- pip
run:
- ${{ pin_subpackage(name_a, min_pin="x.x.x") }}
- python >=3.10
- package:
name: ${{ name_a }}
version: ${{ version }}
build:
noarch: python
number: ${{ build_number }}
requirements:
host:
- python >=3.10
- pip
run:
- python >=3.10
- package:
name: ${{ name | replace('-', '_') }}
version: ${{ version }}
build:
noarch: generic
requirements:
run:
- ${{ pin_subpackage(name, exact=true) }}

0 comments on commit 866b671

Please sign in to comment.