Skip to content

Commit

Permalink
fix up some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Nov 14, 2024
1 parent ffb2a3d commit 156cef9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
8 changes: 8 additions & 0 deletions src/recipe/parser/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ impl Requirements {
self.build.iter().chain(self.host.iter())
}

/// Get all pin_subpackage expressions from requirements, constraints and run exports
pub fn all_pin_subpackage(&self) -> impl Iterator<Item = &Pin> {
self.all_requirements().filter_map(|dep| match dep {
Dependency::PinSubpackage(pin) => Some(&pin.pin_subpackage),
_ => None,
})
}

/// Return all dependencies including any constraints, run exports
/// This is mainly used to find any pin expressions that need to be resolved or added as requirements
pub fn all_requirements(&self) -> impl Iterator<Item = &Dependency> {
Expand Down
4 changes: 2 additions & 2 deletions src/variant_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl VariantConfig {
None
})
.collect::<Vec<_>>();
println!("Variant keys: {:?}", variant_keys);
// println!("Variant keys: {:?}", variant_keys);
let variant_keys = used_zip_keys
.into_iter()
.chain(variant_keys)
Expand All @@ -398,7 +398,7 @@ impl VariantConfig {
let mut combinations = Vec::new();
let mut current = Vec::new();
find_combinations(&variant_keys, 0, &mut current, &mut combinations);
println!("Found combinations: {:?}", combinations);
// println!("Found combinations: {:?}", combinations);
// zip the combinations
let result: Vec<_> = combinations
.iter()
Expand Down
61 changes: 31 additions & 30 deletions src/variant_render.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, HashMap, HashSet};

use petgraph::graph::DiGraph;
use rattler_conda_types::PackageName;

use crate::{
hash::HashInfo,
Expand Down Expand Up @@ -55,7 +56,7 @@ pub(crate) fn stage_0_render(
selector_config: &SelectorConfig,
variant_config: &VariantConfig,
) -> Result<Vec<Stage0Render>, VariantError> {
println!("Outputs: {:?}", outputs);
// println!("Outputs: {:?}", outputs);
let used_vars = outputs
.iter()
.map(|output| {
Expand Down Expand Up @@ -117,7 +118,7 @@ pub(crate) fn stage_0_render(
});
}

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

Expand Down Expand Up @@ -161,6 +162,15 @@ impl Stage1Render {
}
}

// fix target_platform value here
if !self.stage_0_render.rendered_outputs[idx]
.build()
.noarch()
.is_none()
{
variant.insert("target_platform".into(), "noarch".into());
}

variant
}

Expand All @@ -184,10 +194,7 @@ impl Stage1Render {
pub fn sort_outputs(self) -> Self {
// Create an empty directed graph
let mut graph = DiGraph::<_, ()>::new();

// Create a map from output names to node indices
let mut node_indices = Vec::new();

let mut name_to_idx = HashMap::new();

for output in &self.stage_0_render.rendered_outputs {
Expand All @@ -197,28 +204,34 @@ impl Stage1Render {
}

for (idx, output) in self.stage_0_render.rendered_outputs.iter().enumerate() {
let output_name = output.package().name();
let current_node = node_indices[idx];

// Helper closure to add edges for dependencies
let mut add_edge = |req_name: &PackageName| {
if req_name != output_name {
if let Some(&req_idx) = name_to_idx.get(req_name) {
graph.add_edge(req_idx, current_node, ());
}
}
};

// If we find any keys that reference another output, add an edge
for req in output.build_time_requirements() {
let req_name = match req {
Dependency::Spec(x) => x.name.clone().expect("Dependency should have a name"),
Dependency::PinSubpackage(x) => x.pin_value().name.clone(),
_ => continue,
if let Dependency::Spec(spec) = req {
add_edge(spec.name.as_ref().expect("Dependency should have a name"));
};
}

if req_name != *output.package().name() {
if let Some(&req_idx) = name_to_idx.get(&req_name) {
graph.add_edge(req_idx, node_indices[idx], ());
}
}
for pin in output.requirements().all_pin_subpackage() {
add_edge(&pin.name);
}
}

// Sort the outputs topologically
let sorted_indices =
petgraph::algo::toposort(&graph, None).expect("Could not sort topologically.");

println!("Sorted indices: {:?}", sorted_indices);

let sorted_indices = sorted_indices
.into_iter()
.map(|x| x.index())
Expand All @@ -235,14 +248,9 @@ impl Stage1Render {
&self,
) -> impl Iterator<Item = ((&Node, &Recipe), BTreeMap<NormalizedKey, String>)> {
let outputs = self.stage_0_render.outputs().collect::<Vec<_>>();
for o in &outputs {
println!("Output: {:?}", o.1.package().name());
}
println!("Order: {:?}", self.order);

self.order.iter().map(move |&idx| {
let recipe = outputs[idx];
// WRONG
(0..outputs.len()).map(move |idx| {
let recipe = outputs[self.order[idx]];
let variant = self.variant_for_output(idx);
(recipe, variant)
})
Expand All @@ -256,7 +264,6 @@ pub(crate) fn stage_1_render(
) -> Result<Vec<Stage1Render>, VariantError> {
let mut stage_1_renders = Vec::new();

println!("Stage 0: {:?}", stage0_renders);
// TODO we need to add variables from the cache output here!
for r in stage0_renders {
let mut extra_vars_per_output: Vec<HashSet<NormalizedKey>> = Vec::new();
Expand Down Expand Up @@ -341,17 +348,11 @@ pub(crate) fn stage_1_render(
extra_vars_per_output.push(additional_variables);
}

println!("All vars: {:?}", extra_vars_per_output);
// Create the additional combinations and attach the whole variant x outputs to the 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<NormalizedKey>>()
);
all_vars.extend(r.variables.keys().cloned());

let all_combinations = variant_config.combinations(&all_vars, Some(&r.variables))?;
Expand Down
1 change: 1 addition & 0 deletions test-data/recipes/pin_subpackage/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ context:

recipe:
version: ${{ version }}

build:
number: 0

Expand Down

0 comments on commit 156cef9

Please sign in to comment.