diff --git a/src/env_vars.rs b/src/env_vars.rs index 42b70e01..0a70e761 100644 --- a/src/env_vars.rs +++ b/src/env_vars.rs @@ -273,16 +273,7 @@ pub fn vars(output: &Output, build_state: &str) -> HashMap> for BuildString { fn from(value: Option) -> Self { - value.map_or_else(|| BuildString::Derived, BuildString::UserSpecified) + value.map_or_else(|| BuildString::Derived, BuildString::Resolved) } } impl From for Option { fn from(value: BuildString) -> Self { match value { - BuildString::UserSpecified(s) => Some(s), + BuildString::UserSpecified(_) => None, + BuildString::Resolved(s) => Some(s), BuildString::Derived => None, } } @@ -143,7 +151,7 @@ impl From for Option { impl From for BuildString { fn from(value: String) -> Self { - BuildString::UserSpecified(value) + BuildString::Resolved(value) } } @@ -153,18 +161,21 @@ impl BuildString { matches!(self, BuildString::Derived) } - /// Returns the user specified build string. - pub fn as_deref(&self) -> Option<&str> { - match self { - BuildString::UserSpecified(s) => Some(s), - BuildString::Derived => None, - } - } - /// Returns the final build string, either based on the user defined value or by computing the derived value. - pub fn resolve(&self, hash: &HashInfo, build_number: u64) -> Cow<'_, str> { + pub fn resolve( + &self, + hash: &HashInfo, + build_number: u64, + variant: BTreeMap, + ) -> Cow<'_, str> { match self { - BuildString::UserSpecified(s) => s.as_str().into(), + // TODO + BuildString::UserSpecified(template) => { + let jinja = Jinja::new(); + let context = jinja.create_context(variant); + Cow::Owned(jinja.render(template, &context).unwrap()) + } + BuildString::Resolved(s) => s.as_str().into(), BuildString::Derived => Self::compute(hash, build_number).into(), } } @@ -185,7 +196,7 @@ impl TryConvertNode for RenderedNode { impl TryConvertNode for RenderedScalarNode { fn try_convert(&self, _name: &str) -> Result> { - Ok(BuildString::UserSpecified(self.as_str().to_owned())) + Ok(BuildString::UserSpecified(self.source().to_string())) } } diff --git a/src/variant_render.rs b/src/variant_render.rs index c3e1ea84..94b3ae16 100644 --- a/src/variant_render.rs +++ b/src/variant_render.rs @@ -10,7 +10,7 @@ use crate::{ env_vars, hash::HashInfo, normalized_key::NormalizedKey, - recipe::{custom_yaml::Node, parser::Dependency, ParsingError, Recipe}, + recipe::{custom_yaml::Node, parser::Dependency, Jinja, ParsingError, Recipe}, selectors::SelectorConfig, used_variables::used_vars_from_expressions, variant_config::{ParseErrors, VariantConfig, VariantError}, @@ -201,12 +201,23 @@ impl Stage1Render { let variant = self.variant_for_output(idx); let recipe = &self.stage_0_render.rendered_outputs[self.order[idx]]; let hash = HashInfo::from_variant(&variant, recipe.build().noarch()); + let build_string = recipe .build() .string() - .resolve(&hash, recipe.build().number) + .resolve(&hash, recipe.build().number, &variant) .into_owned(); + // original build string + let original_recipe = &self.stage_0_render.raw_outputs.vec[self.order[idx]]; + let original_build_string = original_recipe + .as_mapping() + .unwrap() + .get("build") + .map(|x| x.as_mapping().unwrap().get("string")); + + println!("original build string: {:?}", original_build_string); + build_string }