From 0daa1a672b82981906e320ed4c6dcd8e3949ffb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denizhan=20Dak=C4=B1l=C4=B1r?= Date: Sat, 14 Jun 2025 03:43:24 +0300 Subject: [PATCH 01/29] feat: implement cache output parsing and validation for v1 recipes as per CEP specification --- src/recipe/parser.rs | 14 + src/recipe/parser/cache.rs | 13 +- src/recipe/parser/cache_output.rs | 409 ++++++++++++++++++++++ src/recipe/parser/common_output.rs | 302 ++++++++++++++++ src/recipe/parser/output.rs | 49 +-- src/recipe/parser/output_v2.rs | 420 +++++++++++++++++++++++ src/recipe/parser/output_with_inherit.rs | 176 ++++++++++ src/recipe/parser/parsing_utils.rs | 200 +++++++++++ 8 files changed, 1533 insertions(+), 50 deletions(-) create mode 100644 src/recipe/parser/cache_output.rs create mode 100644 src/recipe/parser/common_output.rs create mode 100644 src/recipe/parser/output_v2.rs create mode 100644 src/recipe/parser/output_with_inherit.rs create mode 100644 src/recipe/parser/parsing_utils.rs diff --git a/src/recipe/parser.rs b/src/recipe/parser.rs index 787164db8..a10ae4e41 100644 --- a/src/recipe/parser.rs +++ b/src/recipe/parser.rs @@ -22,10 +22,15 @@ use crate::{ mod about; mod build; mod cache; +mod cache_output; +mod common_output; mod glob_vec; mod helper; mod output; +mod output_v2; +mod output_with_inherit; mod package; +mod parsing_utils; mod regex; mod requirements; mod script; @@ -37,9 +42,18 @@ pub use self::{ about::About, build::{Build, BuildString, DynamicLinking, PrefixDetection, Python}, cache::Cache, + cache_output::{CacheBuild, CacheOutput, CacheRequirements}, + common_output::{ALLOWED_KEYS_MULTI_OUTPUTS, DEEP_MERGE_KEYS, InheritSpec}, glob_vec::{GlobCheckerVec, GlobVec, GlobWithSource}, output::find_outputs_from_src, + output_v2::{find_outputs_v2, resolve_inheritance}, + output_with_inherit::{OutputType, OutputWithInherit}, package::{OutputPackage, Package}, + parsing_utils::{ + StandardTryConvert, invalid_field_error, missing_field_error, parse_bool, + parse_optional_string, parse_required_string, validate_mapping_keys, + validate_multi_output_root_keys, + }, regex::SerializableRegex, requirements::{ Dependency, IgnoreRunExports, Language, PinCompatible, PinSubpackage, Requirements, diff --git a/src/recipe/parser/cache.rs b/src/recipe/parser/cache.rs index 4da1f7c47..9b9eab929 100644 --- a/src/recipe/parser/cache.rs +++ b/src/recipe/parser/cache.rs @@ -9,7 +9,7 @@ use crate::{ }; use serde::{Deserialize, Serialize}; -use super::{Build, Requirements, Source}; +use super::{Build, Requirements, Source, cache_output::CacheOutput}; /// A cache build that can be used to split up a build into multiple outputs #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -21,6 +21,9 @@ pub struct Cache { pub build: Build, /// The requirements for building the cache pub requirements: Requirements, + /// Cache outputs that define intermediate build artifacts + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub outputs: Vec, } impl TryConvertNode for RenderedNode { @@ -35,13 +38,7 @@ impl TryConvertNode for RenderedMappingNode { fn try_convert(&self, _name: &str) -> Result> { let mut cache = Cache::default(); - validate_keys! { - cache, - self.iter(), - source, - build, - requirements - }; + validate_keys!(cache, self.iter(), source, build, requirements, outputs); Ok(cache) } diff --git a/src/recipe/parser/cache_output.rs b/src/recipe/parser/cache_output.rs new file mode 100644 index 000000000..3eee3c5b5 --- /dev/null +++ b/src/recipe/parser/cache_output.rs @@ -0,0 +1,409 @@ +//! Cache output structures for v1 recipes according to the CEP specification +//! +//! This module defines the cache output type which is an intermediate build artifact +//! that can be inherited by regular package outputs. + +use crate::{ + _partialerror, + recipe::{ + custom_yaml::{HasSpan, RenderedMappingNode, RenderedNode, TryConvertNode}, + error::{ErrorKind, PartialParsingError}, + parser::{ + StandardTryConvert, invalid_field_error, missing_field_error, parse_required_string, + validate_mapping_keys, + }, + }, +}; +use serde::{Deserialize, Serialize}; + +use super::{Script, Source}; + +/// A cache output that produces intermediate build artifacts +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CacheOutput { + /// The name of the cache output + pub name: String, + /// Sources for this cache output + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub source: Vec, + /// Build configuration for the cache + pub build: CacheBuild, + /// Requirements for building the cache (only build and host allowed) + pub requirements: CacheRequirements, + /// Run exports to ignore + #[serde(default, skip_serializing_if = "Option::is_none")] + pub ignore_run_exports: Option, +} + +/// Build configuration specific to cache outputs +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +pub struct CacheBuild { + /// The build script - only script key is allowed for cache outputs + #[serde(default, skip_serializing_if = "Option::is_none")] + pub script: Option