Skip to content

Commit

Permalink
inject jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 1, 2024
1 parent 8a6504f commit 874cc86
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ use std::{

use fs_err as fs;
use miette::{Context, IntoDiagnostic};
use minijinja::Value;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

use crate::{
env_vars,
metadata::{build_reindexed_channels, Output},
packaging::Files,
recipe::parser::{Dependency, Requirements, Source},
recipe::{
parser::{Dependency, Requirements, Source},
Jinja,
},
render::resolved_dependencies::{
install_environments, resolve_dependencies, FinalizedDependencies,
},
Expand Down Expand Up @@ -175,8 +179,11 @@ impl Output {
return self.restore_cache(cache, cache_dir).await;
}
Err(e) => {
tracing::error!("Failed to parse cache: {:?} - rebuilding", e);
tracing::info!("JSON: {}", text);
tracing::error!(
"Failed to parse cache at {}: {:?} - rebuilding",
cache_dir.join("cache.json").display(),
e
);
// remove the cache dir and run as normal
fs::remove_dir_all(&cache_dir).into_diagnostic()?;
}
Expand Down Expand Up @@ -213,6 +220,14 @@ impl Output {
.await
.into_diagnostic()?;

let selector_config = self.build_configuration.selector_config();
let mut jinja = Jinja::new(selector_config.clone());
for (k, v) in self.recipe.context.iter() {
jinja
.context_mut()
.insert(k.clone(), Value::from_safe_string(v.clone()));
}

cache
.build
.script()
Expand All @@ -222,7 +237,7 @@ impl Output {
&self.build_configuration.directories.recipe_dir,
&self.build_configuration.directories.host_prefix,
Some(&self.build_configuration.directories.build_prefix),
None, // TODO fix this to be proper Jinja context
Some(jinja),
)
.await
.into_diagnostic()?;
Expand Down

0 comments on commit 874cc86

Please sign in to comment.