Skip to content

Commit 0567350

Browse files
committed
use a default backend when recipe.yaml is discovered
1 parent 0718147 commit 0567350

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

crates/pixi_build_frontend/src/protocol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum DiscoveryError {
3434
NotADirectory,
3535
#[error("failed to discover a valid project manifest, the source path '{}' could not be found", .0.display())]
3636
NotFound(PathBuf),
37+
3738
#[error("unable to discover communication protocol, the source directory does not contain a supported manifest")]
3839
#[diagnostic(help(
3940
"Ensure that the source directory contains a valid pixi.toml or meta.yaml file."

crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs

+43-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use miette::Diagnostic;
44
use pixi_manifest::Manifest;
55

66
// pub use protocol::Protocol;
7-
use rattler_conda_types::ChannelConfig;
7+
use rattler_conda_types::{ChannelConfig, MatchSpec};
88
use thiserror::Error;
99

1010
use super::pixi::{self, ProtocolBuildError as PixiProtocolBuildError};
@@ -19,9 +19,11 @@ use crate::{
1919
pub enum FinishError {
2020
#[error(transparent)]
2121
Tool(#[from] ToolCacheError),
22+
2223
#[error(transparent)]
2324
#[diagnostic(transparent)]
2425
Init(#[from] InitializeError),
26+
2527
#[error("failed to setup a build backend, the project manifest at {0} does not contain a [build] section")]
2628
NoBuildSection(PathBuf),
2729
}
@@ -45,7 +47,7 @@ pub struct ProtocolBuilder {
4547
recipe_dir: PathBuf,
4648

4749
/// The path to the manifest file.
48-
manifest_path: PathBuf,
50+
manifest_path: Option<PathBuf>,
4951

5052
/// The backend tool to install.
5153
backend_spec: Option<ToolSpec>,
@@ -63,25 +65,27 @@ impl ProtocolBuilder {
6365
// first we need to discover that pixi protocol also can be built.
6466
// it is used to get the manifest
6567

66-
// Ignore the error if we cannot find the pixi protocol.
67-
let pixi_protocol = match pixi::ProtocolBuilder::discover(source_dir) {
68-
Ok(inner_value) => inner_value,
69-
Err(_) => return Ok(None), // Handle the case where the Option is None
70-
};
68+
// // Ignore the error if we cannot find the pixi protocol.
69+
// let pixi_protocol = match pixi::ProtocolBuilder::discover(source_dir) {
70+
// Ok(inner_value) => inner_value,
71+
// Err(_) => return Ok(None), // Handle the case where the Option is None
72+
// };
7173

72-
// we cannot find pixi protocol, so we cannot build rattler-build protocol.
73-
let manifest = if let Some(pixi_protocol) = pixi_protocol {
74-
pixi_protocol.manifest().clone()
75-
} else {
76-
return Ok(None);
77-
};
74+
// // we cannot find pixi protocol, so we cannot build rattler-build protocol.
75+
// let manifest = if let Some(pixi_protocol) = pixi_protocol {
76+
// pixi_protocol.manifest().clone()
77+
// } else {
78+
// return Ok(None);
79+
// };
80+
81+
let manifest = None;
7882

7983
let recipe_dir = source_dir.join("recipe");
8084

8185
let protocol = if source_dir.join("recipe.yaml").is_file() {
82-
Self::new(source_dir, source_dir, &manifest)
86+
Self::new(source_dir, source_dir, manifest)
8387
} else if recipe_dir.join("recipe.yaml").is_file() {
84-
Self::new(source_dir, &recipe_dir, &manifest)
88+
Self::new(source_dir, &recipe_dir, manifest)
8589
} else {
8690
return Ok(None);
8791
};
@@ -90,15 +94,19 @@ impl ProtocolBuilder {
9094
}
9195

9296
/// Constructs a new instance from a manifest.
93-
pub fn new(source_dir: &Path, recipe_dir: &Path, manifest: &Manifest) -> Self {
94-
let backend_spec = manifest
95-
.build_section()
96-
.map(IsolatedToolSpec::from_build_section);
97+
pub fn new(source_dir: &Path, recipe_dir: &Path, manifest: Option<Manifest>) -> Self {
98+
let backend_spec = if let Some(manifest) = &manifest {
99+
manifest
100+
.build_section()
101+
.map(IsolatedToolSpec::from_build_section)
102+
} else {
103+
None
104+
};
97105

98106
Self {
99107
source_dir: source_dir.to_path_buf(),
100108
recipe_dir: recipe_dir.to_path_buf(),
101-
manifest_path: manifest.path.clone(),
109+
manifest_path: manifest.map(|m| m.path.clone()),
102110
backend_spec: backend_spec.map(Into::into),
103111
_channel_config: ChannelConfig::default_with_root_dir(PathBuf::new()),
104112
cache_dir: None,
@@ -134,15 +142,27 @@ impl ProtocolBuilder {
134142
tool: &ToolCache,
135143
build_id: usize,
136144
) -> Result<JsonRPCBuildProtocol, FinishError> {
137-
let tool_spec = self
138-
.backend_spec
139-
.ok_or(FinishError::NoBuildSection(self.manifest_path.clone()))?;
145+
let tool_spec = self.backend_spec.unwrap_or_else(|| {
146+
ToolSpec::Isolated(IsolatedToolSpec::from_specs(["pixi-build-rattler-build"
147+
.parse()
148+
.unwrap()]).with_command("pixi-build-rattler-build"))
149+
});
140150

141151
let tool = tool
142152
.instantiate(tool_spec)
143153
.await
144154
.map_err(FinishError::Tool)?;
145155

156+
tracing::warn!("Tool instantiated .... {:?}", tool);
157+
158+
tracing::warn!("Cache dir / build id: {:?} / {:?}", self.cache_dir, build_id);
159+
if let Some(cache_dir) = self.cache_dir.as_ref() {
160+
let _ = std::fs::create_dir_all(cache_dir).map_err(|e| {
161+
tracing::warn!("Failed to create cache dir: {:?}", e);
162+
e
163+
});
164+
}
165+
146166
Ok(JsonRPCBuildProtocol::setup(
147167
self.source_dir,
148168
self.recipe_dir.join("recipe.yaml"),

0 commit comments

Comments
 (0)