From db529a2e91d6731e8b5e052e1b7b7092be268918 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Mon, 22 Jul 2024 15:38:43 +0200 Subject: [PATCH] feat: use implicit variants.yaml --- src/consts.rs | 3 +++ src/lib.rs | 75 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 src/consts.rs diff --git a/src/consts.rs b/src/consts.rs new file mode 100644 index 00000000..370a6b6a --- /dev/null +++ b/src/consts.rs @@ -0,0 +1,3 @@ +/// A `recipe.yaml` file might be accompanied by a `variants.toml` file from +/// which we can read variant configuration for that specific recipe.. +pub const VARIANTS_CONFIG_FILE: &str = "variants.toml"; diff --git a/src/lib.rs b/src/lib.rs index f2263f4a..b2e58c57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ pub mod used_variables; pub mod utils; pub mod variant_config; +mod consts; mod env_vars; pub mod hash; mod linux; @@ -33,41 +34,35 @@ mod unix; pub mod upload; mod windows; -use build::skip_existing; +use std::{ + collections::{BTreeMap, HashMap}, + env::current_dir, + path::{Path, PathBuf}, + sync::{Arc, Mutex}, +}; +use build::{run_build, skip_existing}; +use console_utils::LoggingOutputHandler; use dunce::canonicalize; use fs_err as fs; -use metadata::Output; +use hash::HashInfo; +use metadata::{ + BuildConfiguration, BuildSummary, Directories, Output, PackageIdentifier, PackagingSettings, +}; use miette::{IntoDiagnostic, WrapErr}; +use opt::*; +use package_test::TestConfiguration; use petgraph::{algo::toposort, graph::DiGraph, visit::DfsPostOrder}; use rattler_conda_types::{package::ArchiveType, Channel, ChannelConfig, Platform}; use rattler_solve::{ChannelPriority, SolveStrategy}; -use recipe::parser::Dependency; -use std::{ - collections::{BTreeMap, HashMap}, - env::current_dir, - path::{Path, PathBuf}, - sync::{Arc, Mutex}, +use recipe::{ + parser::{find_outputs_from_src, Dependency, Recipe}, + ParsingError, }; +use selectors::SelectorConfig; +use system_tools::SystemTools; use tool_configuration::Configuration; - -use { - build::run_build, - console_utils::LoggingOutputHandler, - hash::HashInfo, - metadata::{ - BuildConfiguration, BuildSummary, Directories, PackageIdentifier, PackagingSettings, - }, - opt::*, - package_test::TestConfiguration, - recipe::{ - parser::{find_outputs_from_src, Recipe}, - ParsingError, - }, - selectors::SelectorConfig, - system_tools::SystemTools, - variant_config::{ParseErrors, VariantConfig}, -}; +use variant_config::{ParseErrors, VariantConfig}; /// Returns the recipe path. pub fn get_recipe_path(path: &Path) -> miette::Result { @@ -177,13 +172,31 @@ pub async fn get_build_output( }; let span = tracing::info_span!("Finding outputs from recipe"); - let enter = span.enter(); + // First find all outputs from the recipe let outputs = find_outputs_from_src(&recipe_text)?; + // Check if there is a `variants.yaml` file next to the recipe that we should + // potentially use. + let mut variant_configs; + let variant_configs = if let Some(variant_path) = recipe_path + .parent() + .map(|parent| parent.join(consts::VARIANTS_CONFIG_FILE)) + { + if variant_path.is_file() { + variant_configs = args.variant_config.clone(); + variant_configs.push(variant_path); + &variant_configs + } else { + &args.variant_config + } + } else { + &args.variant_config + }; + let variant_config = - VariantConfig::from_files(&args.variant_config, &selector_config).into_diagnostic()?; + VariantConfig::from_files(variant_configs, &selector_config).into_diagnostic()?; let outputs_and_variants = variant_config.find_variants(&outputs, &recipe_text, &selector_config)?; @@ -416,7 +429,8 @@ pub async fn rebuild_from_args( ) -> miette::Result<()> { tracing::info!("Rebuilding {}", args.package_file.to_string_lossy()); // we extract the recipe folder from the package file (info/recipe/*) - // and then run the rendered recipe with the same arguments as the original build + // and then run the rendered recipe with the same arguments as the original + // build let temp_folder = tempfile::tempdir().into_diagnostic()?; rebuild::extract_recipe(&args.package_file, temp_folder.path()).into_diagnostic()?; @@ -586,7 +600,8 @@ pub fn sort_build_outputs_topologically( miette::miette!("The package '{}' was not found in the outputs", up_to) })?; - // Perform a DFS post-order traversal from the "up-to" node to find all dependencies + // Perform a DFS post-order traversal from the "up-to" node to find all + // dependencies let mut dfs = DfsPostOrder::new(&graph, up_to_index); let mut sorted_indices = Vec::new(); while let Some(nx) = dfs.next(&graph) {