Skip to content

Commit

Permalink
make function work
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed May 30, 2024
1 parent fe26ee0 commit 80ad92b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ pub async fn get_build_output(
build_platform: args.build_platform,
variant: BTreeMap::new(),
experimental: args.common.experimental,
// allow undefined while finding the variants
allow_undefined: true,
};

let span = tracing::info_span!("Finding outputs from recipe");
Expand Down Expand Up @@ -217,6 +219,7 @@ pub async fn get_build_output(
host_platform: selector_config.host_platform,
build_platform: selector_config.build_platform,
experimental: args.common.experimental,
allow_undefined: false,
};

let recipe =
Expand Down
12 changes: 8 additions & 4 deletions src/recipe/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{collections::BTreeMap, str::FromStr};

use minijinja::value::Object;
use minijinja::{Environment, Value};
use rattler_conda_types::{PackageName, ParseStrictness, Platform, Version};
use rattler_conda_types::{PackageName, ParseStrictness, Platform, Version, VersionSpec};

use crate::render::pin::PinArgs;
pub use crate::render::pin::{Pin, PinExpression};
Expand Down Expand Up @@ -216,13 +216,12 @@ fn compiler_stdlib_eval(
}

fn set_jinja(config: &SelectorConfig) -> minijinja::Environment<'static> {
use rattler_conda_types::version_spec::VersionSpec;

let SelectorConfig {
target_platform,
build_platform,
variant,
experimental,
allow_undefined,
..
} = config.clone();

Expand Down Expand Up @@ -315,7 +314,12 @@ fn set_jinja(config: &SelectorConfig) -> minijinja::Environment<'static> {

let variant_clone = variant.clone();
env.add_function("stdlib", move |lang: String| {
compiler_stdlib_eval(&lang, target_platform, &variant_clone, "stdlib")
let res = compiler_stdlib_eval(&lang, target_platform, &variant_clone, "stdlib");
if allow_undefined {
Ok(res.unwrap_or_else(|_| "undefined".to_string()))
} else {
res
}
});

env.add_function("pin_subpackage", |name: String, kwargs: Option<Value>| {
Expand Down
3 changes: 3 additions & 0 deletions src/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct SelectorConfig {
pub variant: BTreeMap<String, String>,
/// Enable experimental features
pub experimental: bool,
/// Allow undefined variables
pub allow_undefined: bool,
}

impl SelectorConfig {
Expand Down Expand Up @@ -98,6 +100,7 @@ impl Default for SelectorConfig {
hash: None,
variant: Default::default(),
experimental: false,
allow_undefined: false,
}
}
}
3 changes: 3 additions & 0 deletions src/used_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ mod test {
- if: osx
then: osx-clang
- ${{ compiler('c') }}
- ${{ stdlib('c') }}
- ${{ pin_subpackage('abcdef') }}
"#;

Expand All @@ -313,6 +314,8 @@ mod test {
assert!(used_vars.contains("osx"));
assert!(used_vars.contains("c_compiler"));
assert!(used_vars.contains("c_compiler_version"));
assert!(used_vars.contains("c_stdlib"));
assert!(used_vars.contains("c_stdlib_version"));
assert!(used_vars.contains("abcdef"));
}

Expand Down

0 comments on commit 80ad92b

Please sign in to comment.