From b32eea04846f40b8a6e88ae159f5f32f1610d2a0 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 26 Nov 2024 11:03:18 +0100 Subject: [PATCH 1/4] use a default backend when `recipe.yaml` is discovered --- crates/pixi_build_frontend/src/protocol.rs | 1 + .../src/protocols/builders/rattler_build.rs | 66 ++++++++++++------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/crates/pixi_build_frontend/src/protocol.rs b/crates/pixi_build_frontend/src/protocol.rs index 4530b703e..2dc6d0b01 100644 --- a/crates/pixi_build_frontend/src/protocol.rs +++ b/crates/pixi_build_frontend/src/protocol.rs @@ -34,6 +34,7 @@ pub enum DiscoveryError { NotADirectory, #[error("failed to discover a valid project manifest, the source path '{}' could not be found", .0.display())] NotFound(PathBuf), + #[error("unable to discover communication protocol, the source directory does not contain a supported manifest")] #[diagnostic(help( "Ensure that the source directory contains a valid pixi.toml or meta.yaml file." diff --git a/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs b/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs index dcb4e30ba..f925df2a2 100644 --- a/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs +++ b/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs @@ -4,7 +4,7 @@ use miette::Diagnostic; use pixi_manifest::Manifest; // pub use protocol::Protocol; -use rattler_conda_types::ChannelConfig; +use rattler_conda_types::{ChannelConfig, MatchSpec}; use thiserror::Error; use super::pixi::{self, ProtocolBuildError as PixiProtocolBuildError}; @@ -19,9 +19,11 @@ use crate::{ pub enum FinishError { #[error(transparent)] Tool(#[from] ToolCacheError), + #[error(transparent)] #[diagnostic(transparent)] Init(#[from] InitializeError), + #[error("failed to setup a build backend, the project manifest at {0} does not contain a [build] section")] NoBuildSection(PathBuf), } @@ -45,7 +47,7 @@ pub struct ProtocolBuilder { recipe_dir: PathBuf, /// The path to the manifest file. - manifest_path: PathBuf, + manifest_path: Option, /// The backend tool to install. backend_spec: Option, @@ -63,25 +65,27 @@ impl ProtocolBuilder { // first we need to discover that pixi protocol also can be built. // it is used to get the manifest - // Ignore the error if we cannot find the pixi protocol. - let pixi_protocol = match pixi::ProtocolBuilder::discover(source_dir) { - Ok(inner_value) => inner_value, - Err(_) => return Ok(None), // Handle the case where the Option is None - }; + // // Ignore the error if we cannot find the pixi protocol. + // let pixi_protocol = match pixi::ProtocolBuilder::discover(source_dir) { + // Ok(inner_value) => inner_value, + // Err(_) => return Ok(None), // Handle the case where the Option is None + // }; - // we cannot find pixi protocol, so we cannot build rattler-build protocol. - let manifest = if let Some(pixi_protocol) = pixi_protocol { - pixi_protocol.manifest().clone() - } else { - return Ok(None); - }; + // // we cannot find pixi protocol, so we cannot build rattler-build protocol. + // let manifest = if let Some(pixi_protocol) = pixi_protocol { + // pixi_protocol.manifest().clone() + // } else { + // return Ok(None); + // }; + + let manifest = None; let recipe_dir = source_dir.join("recipe"); let protocol = if source_dir.join("recipe.yaml").is_file() { - Self::new(source_dir, source_dir, &manifest) + Self::new(source_dir, source_dir, manifest) } else if recipe_dir.join("recipe.yaml").is_file() { - Self::new(source_dir, &recipe_dir, &manifest) + Self::new(source_dir, &recipe_dir, manifest) } else { return Ok(None); }; @@ -90,15 +94,19 @@ impl ProtocolBuilder { } /// Constructs a new instance from a manifest. - pub fn new(source_dir: &Path, recipe_dir: &Path, manifest: &Manifest) -> Self { - let backend_spec = manifest - .build_section() - .map(IsolatedToolSpec::from_build_section); + pub fn new(source_dir: &Path, recipe_dir: &Path, manifest: Option) -> Self { + let backend_spec = if let Some(manifest) = &manifest { + manifest + .build_section() + .map(IsolatedToolSpec::from_build_section) + } else { + None + }; Self { source_dir: source_dir.to_path_buf(), recipe_dir: recipe_dir.to_path_buf(), - manifest_path: manifest.path.clone(), + manifest_path: manifest.map(|m| m.path.clone()), backend_spec: backend_spec.map(Into::into), _channel_config: ChannelConfig::default_with_root_dir(PathBuf::new()), cache_dir: None, @@ -134,15 +142,27 @@ impl ProtocolBuilder { tool: &ToolCache, build_id: usize, ) -> Result { - let tool_spec = self - .backend_spec - .ok_or(FinishError::NoBuildSection(self.manifest_path.clone()))?; + let tool_spec = self.backend_spec.unwrap_or_else(|| { + ToolSpec::Isolated(IsolatedToolSpec::from_specs(["pixi-build-rattler-build" + .parse() + .unwrap()]).with_command("pixi-build-rattler-build")) + }); let tool = tool .instantiate(tool_spec) .await .map_err(FinishError::Tool)?; + tracing::warn!("Tool instantiated .... {:?}", tool); + + tracing::warn!("Cache dir / build id: {:?} / {:?}", self.cache_dir, build_id); + if let Some(cache_dir) = self.cache_dir.as_ref() { + let _ = std::fs::create_dir_all(cache_dir).map_err(|e| { + tracing::warn!("Failed to create cache dir: {:?}", e); + e + }); + } + Ok(JsonRPCBuildProtocol::setup( self.source_dir, self.recipe_dir.join("recipe.yaml"), From 42000e1426822a04acefb1057cc440f122aa22ce Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 26 Nov 2024 13:33:44 +0100 Subject: [PATCH 2/4] clean up changes --- .../src/protocols/builders/rattler_build.rs | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs b/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs index f925df2a2..971e05b0a 100644 --- a/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs +++ b/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs @@ -4,7 +4,7 @@ use miette::Diagnostic; use pixi_manifest::Manifest; // pub use protocol::Protocol; -use rattler_conda_types::{ChannelConfig, MatchSpec}; +use rattler_conda_types::ChannelConfig; use thiserror::Error; use super::pixi::{self, ProtocolBuildError as PixiProtocolBuildError}; @@ -61,24 +61,13 @@ pub struct ProtocolBuilder { impl ProtocolBuilder { /// Discovers the protocol for the given source directory. + /// We discover a `pixi.toml` file in the source directory and/or a `recipe.yaml / recipe/recipe.yaml` file. pub fn discover(source_dir: &Path) -> Result, ProtocolBuildError> { - // first we need to discover that pixi protocol also can be built. - // it is used to get the manifest - - // // Ignore the error if we cannot find the pixi protocol. - // let pixi_protocol = match pixi::ProtocolBuilder::discover(source_dir) { - // Ok(inner_value) => inner_value, - // Err(_) => return Ok(None), // Handle the case where the Option is None - // }; - - // // we cannot find pixi protocol, so we cannot build rattler-build protocol. - // let manifest = if let Some(pixi_protocol) = pixi_protocol { - // pixi_protocol.manifest().clone() - // } else { - // return Ok(None); - // }; - - let manifest = None; + // Ignore the error if we cannot find the pixi protocol. + let manifest = match pixi::ProtocolBuilder::discover(source_dir) { + Ok(protocol) => protocol.map(|protocol| protocol.manifest().clone()), + Err(_) => None, + }; let recipe_dir = source_dir.join("recipe"); @@ -142,20 +131,23 @@ impl ProtocolBuilder { tool: &ToolCache, build_id: usize, ) -> Result { - let tool_spec = self.backend_spec.unwrap_or_else(|| { - ToolSpec::Isolated(IsolatedToolSpec::from_specs(["pixi-build-rattler-build" - .parse() - .unwrap()]).with_command("pixi-build-rattler-build")) - }); + // If we have a manifest path, that means we found a `pixi.toml` file. In that case + // we should use the backend spec from the manifest. + let tool_spec = if let Some(manifest_path) = &self.manifest_path { + self.backend_spec + .ok_or(FinishError::NoBuildSection(manifest_path.clone()))? + } else { + ToolSpec::Isolated( + IsolatedToolSpec::from_specs(["pixi-build-rattler-build".parse().unwrap()]) + .with_command("pixi-build-rattler-build"), + ) + }; let tool = tool .instantiate(tool_spec) .await .map_err(FinishError::Tool)?; - tracing::warn!("Tool instantiated .... {:?}", tool); - - tracing::warn!("Cache dir / build id: {:?} / {:?}", self.cache_dir, build_id); if let Some(cache_dir) = self.cache_dir.as_ref() { let _ = std::fs::create_dir_all(cache_dir).map_err(|e| { tracing::warn!("Failed to create cache dir: {:?}", e); From 551a8ac7f2b94f48c99632525c4295a00b8d8228 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 26 Nov 2024 16:30:06 +0100 Subject: [PATCH 3/4] use a constant --- .../src/protocols/builders/rattler_build.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs b/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs index 971e05b0a..fff69478c 100644 --- a/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs +++ b/crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs @@ -15,6 +15,8 @@ use crate::{ BackendOverride, }; +const DEFAULT_BUILD_TOOL: &str = "pixi-build-rattler-build"; + #[derive(Debug, Error, Diagnostic)] pub enum FinishError { #[error(transparent)] @@ -138,8 +140,8 @@ impl ProtocolBuilder { .ok_or(FinishError::NoBuildSection(manifest_path.clone()))? } else { ToolSpec::Isolated( - IsolatedToolSpec::from_specs(["pixi-build-rattler-build".parse().unwrap()]) - .with_command("pixi-build-rattler-build"), + IsolatedToolSpec::from_specs([DEFAULT_BUILD_TOOL.parse().unwrap()]) + .with_command(DEFAULT_BUILD_TOOL), ) }; @@ -148,13 +150,6 @@ impl ProtocolBuilder { .await .map_err(FinishError::Tool)?; - if let Some(cache_dir) = self.cache_dir.as_ref() { - let _ = std::fs::create_dir_all(cache_dir).map_err(|e| { - tracing::warn!("Failed to create cache dir: {:?}", e); - e - }); - } - Ok(JsonRPCBuildProtocol::setup( self.source_dir, self.recipe_dir.join("recipe.yaml"), From d810c007c5055fa487a3643facdac888813f8b91 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 27 Nov 2024 15:41:55 +0100 Subject: [PATCH 4/4] trigger-build