Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions crates/pixi_build_discovery/src/backend_spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pixi_spec::{BinarySpec, PixiSpec, SourceAnchor};
use pixi_spec::{BinarySpec, PixiSpec, SourceAnchor, SourceSpec};
use pixi_spec_containers::DependencyMap;
use rattler_conda_types::ChannelUrl;
/// Describes how a backend should be instantiated.
Expand Down Expand Up @@ -45,8 +45,10 @@ impl JsonRpcBackendSpec {
let maybe_source_spec = env_spec.requirement.1.try_into_source_spec();
let pixi_spec = match maybe_source_spec {
Ok(source_spec) => {
let resolved_spec = source_anchor.resolve(source_spec);
PixiSpec::from(resolved_spec)
let resolved_spec = source_anchor.resolve(source_spec.location);
PixiSpec::from(SourceSpec {
location: resolved_spec,
})
}
Err(pixi_spec) => pixi_spec,
};
Expand Down Expand Up @@ -133,8 +135,10 @@ impl EnvironmentSpec {
let maybe_source_spec = self.requirement.1.try_into_source_spec();
let pixi_spec = match maybe_source_spec {
Ok(source_spec) => {
let resolved_spec = source_anchor.resolve(source_spec);
PixiSpec::from(resolved_spec)
let resolved_spec = source_anchor.resolve(source_spec.location);
PixiSpec::from(SourceSpec {
location: resolved_spec,
})
}
Err(pixi_spec) => pixi_spec,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_build_types/src/procedures/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ pub const METHOD_NAME: &str = "initialize";
pub struct InitializeParams {
/// The manifest that the build backend should use.
///
/// This is an absolute path.
/// This is an absolute path to a manifest file.
pub manifest_path: PathBuf,

/// The root directory of the source code that the build backend should use.
/// If this is `None`, the backend should use the directory of the
/// `manifest_path` as the source directory.
///
/// This is an absolute path.
/// This is an absolute path. This is always a directory.
pub source_dir: Option<PathBuf>,

/// The root directory of the workspace.
Expand Down
6 changes: 3 additions & 3 deletions crates/pixi_cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use indicatif::ProgressBar;
use miette::{Context, IntoDiagnostic};
use pixi_command_dispatcher::{
BuildBackendMetadataSpec, BuildEnvironment, BuildProfile, CacheDirs, SourceBuildSpec,
build::SourceCodeLocation,
};
use pixi_config::ConfigCli;
use pixi_core::WorkspaceLocator;
Expand Down Expand Up @@ -146,13 +147,13 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// Create the build backend metadata specification.
let backend_metadata_spec = BuildBackendMetadataSpec {
manifest_source: manifest_source.clone(),
preferred_build_source: None,
channels: channels.clone(),
channel_config: channel_config.clone(),
build_environment: build_environment.clone(),
variants: Some(variants.clone()),
variant_files: Some(variant_files.clone()),
enabled_protocols: Default::default(),
pin_override: None,
};
let backend_metadata = command_dispatcher
.build_backend_metadata(backend_metadata_spec.clone())
Expand Down Expand Up @@ -183,8 +184,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
package,
// Build into a temporary directory first
output_directory: Some(temp_output_dir.path().to_path_buf()),
manifest_source: manifest_source.clone(),
build_source: None,
source: SourceCodeLocation::new(manifest_source.clone(), None),
channels: channels.clone(),
channel_config: channel_config.clone(),
build_environment: build_environment.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_command_dispatcher/src/build/build_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use thiserror::Error;
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use xxhash_rust::xxh3::Xxh3;

use crate::build::source_checkout_cache_key;
use crate::build::{SourceCodeLocation, source_checkout_cache_key};

/// A cache for caching build artifacts of a source checkout.
#[derive(Clone)]
Expand Down Expand Up @@ -249,7 +249,7 @@ pub struct BuildHostPackage {
pub repodata_record: RepoDataRecord,

/// The source location from which the package was built.
pub source: Option<PinnedSourceSpec>,
pub source: Option<SourceCodeLocation>,
}

/// A cache entry returned by [`BuildCache::entry`] which enables
Expand Down
10 changes: 5 additions & 5 deletions crates/pixi_command_dispatcher/src/build/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pixi_build_types::{
},
};
use pixi_record::PixiRecord;
use pixi_spec::{BinarySpec, DetailedSpec, PixiSpec, SourceAnchor, UrlBinarySpec};
use pixi_spec::{BinarySpec, DetailedSpec, PixiSpec, SourceAnchor, SourceSpec, UrlBinarySpec};
use pixi_spec_containers::DependencyMap;
use rattler_conda_types::{
InvalidPackageNameError, MatchSpec, NamedChannelOrUrl, NamelessMatchSpec, PackageName,
Expand Down Expand Up @@ -95,12 +95,12 @@ impl Dependencies {
})?;
match conversion::from_package_spec_v1(depend.spec.clone()).into_source_or_binary() {
Either::Left(source) => {
let source = if let Some(anchor) = &source_anchor {
anchor.resolve(source)
let location = if let Some(anchor) = &source_anchor {
anchor.resolve(source.location)
} else {
source
source.location
};
dependencies.insert(name, PixiSpec::from(source).into());
dependencies.insert(name, PixiSpec::from(SourceSpec { location }).into());
}
Either::Right(binary) => {
dependencies.insert(name, PixiSpec::from(binary).into());
Expand Down
67 changes: 67 additions & 0 deletions crates/pixi_command_dispatcher/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,79 @@ pub use dependencies::{
};
pub(crate) use move_file::{MoveError, move_file};
use pixi_record::PinnedSourceSpec;
use serde::{Deserialize, Serialize};
use url::Url;
pub use work_dir_key::{SourceRecordOrCheckout, WorkDirKey};
use xxhash_rust::xxh3::Xxh3;

const KNOWN_SUFFIXES: [&str; 3] = [".git", ".tar.gz", ".zip"];

/// Stores the two possible locations for the source code,
/// in the case of an out-of-tree source build.
///
/// Something which looks like:
/// ```toml
/// [package.build]
/// source = { path = "some-path" }
/// ```
///
/// We want to prefer that location for our cache checks
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct SourceCodeLocation {
/// The location of the manifest and the possible source code
manifest_source: PinnedSourceSpec,
/// The location of the source code that should be queried and build
build_source: Option<PinnedSourceSpec>,
}

impl SourceCodeLocation {
pub fn new(manifest_source: PinnedSourceSpec, build_source: Option<PinnedSourceSpec>) -> Self {
Self {
manifest_source,
build_source,
}
}

/// Get the reference to the manifest source
pub fn manifest_source(&self) -> &PinnedSourceSpec {
&self.manifest_source
}

/// Get the pinned source spec to the actual source code
/// This is the normally the path to the manifest_source
/// but when set is the path to the build_source
pub fn source_code(&self) -> &PinnedSourceSpec {
self.build_source.as_ref().unwrap_or(&self.manifest_source)
}

/// Get the optional explicit build source override.
pub fn build_source(&self) -> Option<&PinnedSourceSpec> {
self.build_source.as_ref()
}

pub fn as_source_and_alternative_root(&self) -> (&PinnedSourceSpec, Option<&PinnedSourceSpec>) {
if let Some(build_source) = &self.build_source {
(build_source, Some(&self.manifest_source))
} else {
(&self.manifest_source, None)
}
}
}

impl std::fmt::Display for SourceCodeLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"(manifest-src: {}, build-src: {})",
self.manifest_source(),
self.build_source
.as_ref()
.map(|build| format!("{build}"))
.unwrap_or("undefined".to_string())
)
}
}

/// Try to deduce a name from a url.
fn pretty_url_name(url: &Url) -> String {
if let Some(last_segment) = url
Expand Down
Loading
Loading