Skip to content

Commit

Permalink
feat: (simple) build tool override (#2620)
Browse files Browse the repository at this point in the history
This allows us to set a `PIXI_BUILD_BACKEND_OVERRIDE=/foo/bar/...` in order to test more easily.
  • Loading branch information
wolfv authored Dec 3, 2024
1 parent 5ce9827 commit b0a6ad1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
18 changes: 15 additions & 3 deletions crates/pixi_build_frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,28 @@ pub use protocol_builder::EnabledProtocols;

#[derive(Debug)]
pub enum BackendOverride {
/// Overrwide the backend with a specific tool.
/// Override the backend with a specific tool.
Spec(MatchSpec, Option<Vec<NamedChannelOrUrl>>),

/// Overwrite the backend with a specific tool.
/// Overwrite the backend with a executable path.
System(String),

/// Use the given IO for the backend.
/// Override with a specific IPC channel.
Io(InProcessBackend),
}

impl BackendOverride {
pub fn from_env() -> Option<Self> {
match std::env::var("PIXI_BUILD_BACKEND_OVERRIDE") {
Ok(spec) => {
tracing::warn!("overriding build backend with: {}", spec);
Some(Self::System(spec))
}
Err(_) => None,
}
}
}

impl From<InProcessBackend> for BackendOverride {
fn from(value: InProcessBackend) -> Self {
Self::Io(value)
Expand Down
6 changes: 3 additions & 3 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use chrono::Utc;
use itertools::Itertools;
use miette::Diagnostic;
use pixi_build_frontend::{SetupRequest, ToolContext};
use pixi_build_frontend::{BackendOverride, SetupRequest, ToolContext};
use pixi_build_types::{
procedures::{
conda_build::{CondaBuildParams, CondaOutputIdentifier},
Expand Down Expand Up @@ -258,7 +258,7 @@ impl BuildContext {
.with_tool_context(self.tool_context.clone())
.setup_protocol(SetupRequest {
source_dir: source_checkout.path.clone(),
build_tool_override: Default::default(),
build_tool_override: BackendOverride::from_env(),
build_id,
})
.await
Expand Down Expand Up @@ -499,7 +499,7 @@ impl BuildContext {
.with_tool_context(self.tool_context.clone())
.setup_protocol(SetupRequest {
source_dir: source.path.clone(),
build_tool_override: Default::default(),
build_tool_override: BackendOverride::from_env(),
build_id,
})
.await
Expand Down
4 changes: 2 additions & 2 deletions src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{path::PathBuf, sync::Arc, time::Duration};
use clap::{ArgAction, Parser};
use indicatif::ProgressBar;
use miette::{Context, IntoDiagnostic};
use pixi_build_frontend::{CondaBuildReporter, SetupRequest};
use pixi_build_frontend::{BackendOverride, CondaBuildReporter, SetupRequest};
use pixi_build_types::{
procedures::conda_build::CondaBuildParams, ChannelConfiguration, PlatformAndVirtualPackages,
};
Expand Down Expand Up @@ -100,7 +100,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.with_tool_context(Arc::new(tool_context))
.setup_protocol(SetupRequest {
source_dir: project.root().to_path_buf(),
build_tool_override: None,
build_tool_override: BackendOverride::from_env(),
build_id: 0,
})
.await
Expand Down

0 comments on commit b0a6ad1

Please sign in to comment.