Skip to content

Commit

Permalink
more work towards new render
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Nov 6, 2024
1 parent c3e04f7 commit 525c6e4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ finalized_dependencies:
run:
depends: []
constraints: []
finalized_cache_dependencies: ~
finalized_sources: ~
system_tools:
rattler-build: 0.12.1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ finalized_dependencies:
run:
depends: []
constraints: []
finalized_cache_dependencies: ~
finalized_sources:
- git: "https://github.com/prefix-dev/rattler-build"
rev: 4ae7bd207b437c3a5955788e6516339a84358e1c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ finalized_dependencies:
from: host
run_export: python
constraints: []
finalized_cache_dependencies: ~
finalized_sources: ~
system_tools:
rattler-build: 0.12.1
31 changes: 20 additions & 11 deletions src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl VariantConfig {
None
})
.collect::<Vec<_>>();

println!("Variant keys: {:?}", variant_keys);
let variant_keys = used_zip_keys
.into_iter()
.chain(variant_keys)
Expand All @@ -397,7 +397,7 @@ impl VariantConfig {
let mut combinations = Vec::new();
let mut current = Vec::new();
find_combinations(&variant_keys, 0, &mut current, &mut combinations);
println!("CCC {:?}", combinations);
println!("Found combinations: {:?}", combinations);
// zip the combinations
let result: Vec<_> = combinations
.iter()
Expand All @@ -413,9 +413,13 @@ impl VariantConfig {
let result = result
.into_iter()
.filter(|combination| {
already_used_vars
.iter()
.any(|(key, value)| combination.get(key).map_or(false, |v| v == value))
if already_used_vars.is_empty() {
return true;
} else {
already_used_vars
.iter()
.all(|(key, value)| combination.get(key).map_or(false, |v| v == value))
}
})
.collect();
Ok(result)
Expand Down Expand Up @@ -448,16 +452,21 @@ impl VariantConfig {
// Now we need to convert the stage 1 renders to DiscoveredOutputs
let mut recipes = IndexSet::new();
for sx in stage_1 {
for (node, recipe) in sx.stage_0_render.outputs() {
for (idx, (node, recipe)) in sx.stage_0_render.outputs().enumerate() {
let target_platform = if recipe.build().noarch().is_none() {
selector_config.target_platform
} else {
Platform::NoArch
};

recipes.insert(DiscoveredOutput {
name: recipe.package().name.as_normalized().to_string(),
version: recipe.package().version.to_string(),
// TODO!
build_string: "foobar".to_string(),
noarch_type: NoArchType::none(),
target_platform: Platform::current(),
build_string: sx.build_string_for_output(idx),
noarch_type: recipe.build().noarch().clone(),
target_platform,
node: node.clone(),
used_vars: sx.variables().clone(),
used_vars: sx.variant_for_output(idx),
});
}
}
Expand Down
111 changes: 81 additions & 30 deletions src/variant_render.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::{BTreeMap, HashSet};

use rattler_conda_types::NoArchType;

use crate::{
hash::HashInfo,
recipe::{
Expand Down Expand Up @@ -40,7 +42,10 @@ pub(crate) struct Stage0Render {

impl Stage0Render {
pub fn outputs(&self) -> impl Iterator<Item = (&Node, &Recipe)> {
self.raw_outputs.vec.iter().zip(self.rendered_outputs.iter())
self.raw_outputs
.vec
.iter()
.zip(self.rendered_outputs.iter())
}
}

Expand All @@ -50,6 +55,7 @@ pub(crate) fn stage_0_render(
selector_config: &SelectorConfig,
variant_config: &VariantConfig,
) -> Result<Vec<Stage0Render>, VariantError> {
println!("Outputs: {:?}", outputs);
let used_vars = outputs
.iter()
.map(|output| used_vars_from_expressions(output, recipe))
Expand Down Expand Up @@ -103,30 +109,60 @@ pub(crate) fn stage_0_render(
});
}

println!("{:?}", stage0_renders);
println!("Stage 0 renders: {:?}", stage0_renders);
Ok(stage0_renders)
}

struct DiscoveredOutput {
/// The recipe of this output
recipe: Recipe,
/// The variant values of this output
variant: BTreeMap<String, String>,
}

/// Stage 1 render of a single recipe.yaml
#[derive(Debug)]
pub struct Stage1Render {
pub(crate) variables: BTreeMap<String, String>,

// Per recipe output a set of extra used variables
pub(crate) used_variables_from_dependencies: Vec<HashSet<String>>,

pub(crate) stage_0_render: Stage0Render,
}

impl Stage1Render {
pub fn variables(&self) -> &BTreeMap<String, String> {
&self.variables
pub fn variant_for_output(&self, idx: usize) -> BTreeMap<String, String> {
// combine jinja variables and the variables from the dependencies
let used_vars_jinja = self
.stage_0_render
.raw_outputs
.used_vars_jinja
.get(idx)
.unwrap();
let mut all_vars = self
.used_variables_from_dependencies
.get(idx)
.unwrap()
.clone();
all_vars.extend(used_vars_jinja.iter().cloned());

// extract variant
let mut variant = BTreeMap::new();
for var in all_vars {
if let Some(val) = self.variables.get(&var) {
variant.insert(var, val.clone());
}
}

variant
}

pub fn build_string_for_output(&self, idx: usize) -> String {
let variant = self.variant_for_output(idx);
let recipe = &self.stage_0_render.rendered_outputs[idx];
let hash = HashInfo::from_variant(&variant, recipe.build().noarch());

let build_string = recipe
.build()
.string()
.resolve(&hash, recipe.build().number)
.into_owned();

build_string
}
}

Expand All @@ -136,13 +172,11 @@ pub(crate) fn stage_1_render(
variant_config: &VariantConfig,
) -> Result<Vec<Stage1Render>, VariantError> {
let mut stage_1_renders = Vec::new();
// let mut discovered_outputs = Vec::new();

// TODO we need to add variables from the cache here!
// TODO we need to add variables from the cache output here!
for r in stage0_renders {
let mut extra_vars_per_output: Vec<HashSet<String>> = Vec::new();
for output in &r.rendered_outputs {
println!("{:?}", output.build_time_requirements().collect::<Vec<_>>());
for (idx, output) in r.rendered_outputs.iter().enumerate() {
let mut additional_variables = HashSet::<String>::new();
// Add in variants from the dependencies as we find them
for dep in output.build_time_requirements() {
Expand All @@ -157,7 +191,7 @@ pub(crate) fn stage_1_render(
}
}

// We wanna add something to packages that are requiring a subpackage _exactly_ because
// We want to add something to packages that are requiring a subpackage _exactly_ because
// that creates additional variants
for req in output.requirements.all_requirements() {
match req {
Expand All @@ -167,18 +201,36 @@ pub(crate) fn stage_1_render(
additional_variables.insert(name);
}
}
Dependency::Spec(spec) => {
// add in virtual package specs where the name starts with `__`
if let Some(ref name) = spec.name {
if name.as_normalized().starts_with("__") {
additional_variables.insert(name.as_normalized().to_string());
}
}
}
_ => {}
}
}

// TODO
// let hash = HashInfo::from_variant(&used_filtered, parsed_recipe.build().noarch());
// Add in extra `use` keys from the output
let extra_use_keys = output.build().variant().use_keys.clone();
additional_variables.extend(extra_use_keys);

// let build_string = parsed_recipe
// .build()
// .string()
// .resolve(&hash, parsed_recipe.build().number)
// .into_owned();
// If the recipe is `noarch: python` we can remove an empty python key that comes from the dependencies
if output.build().noarch().is_python() {
additional_variables.remove("python");
}

// special handling of CONDA_BUILD_SYSROOT
let jinja_variables = r.raw_outputs.used_vars_jinja.get(idx).unwrap();
if jinja_variables.contains("c_compiler") || jinja_variables.contains("cxx_compiler") {
additional_variables.insert("CONDA_BUILD_SYSROOT".to_string());
}

// also always add `target_platform` and `channel_targets`
additional_variables.insert("target_platform".to_string());
additional_variables.insert("channel_targets".to_string());

extra_vars_per_output.push(additional_variables);
}
Expand All @@ -187,12 +239,15 @@ pub(crate) fn stage_1_render(
let mut all_vars = extra_vars_per_output
.iter()
.fold(HashSet::new(), |acc, x| acc.union(x).cloned().collect());

println!("All vars from deps: {:?}", all_vars);
println!(
"All variables from recipes: {:?}",
r.variables.keys().cloned().collect::<Vec<String>>()
);
all_vars.extend(r.variables.keys().cloned());

println!("All extra vars: {:?}, already: {:?}", all_vars, r.variables);
let all_combinations = variant_config.combinations(&all_vars, Some(&r.variables))?;
println!("Combinazions: {:?}", all_combinations);

for combination in all_combinations {
stage_1_renders.push(Stage1Render {
variables: combination,
Expand All @@ -202,9 +257,5 @@ pub(crate) fn stage_1_render(
}
}

for render in &stage_1_renders {
println!("{:?}\n\n=====\n\n", render);
}

Ok(stage_1_renders)
}
2 changes: 0 additions & 2 deletions test-data/recipes/variants/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

context:
name: llama.cpp
version: b1513
Expand Down

0 comments on commit 525c6e4

Please sign in to comment.