Skip to content
Merged
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
18 changes: 15 additions & 3 deletions crates/pixi_build_types/src/procedures/conda_build_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
path::PathBuf,
};

use rattler_conda_types::{ChannelUrl, PackageName, Platform, VersionWithSource};
use rattler_conda_types::{ChannelUrl, PackageName, Platform, RepoDataRecord, VersionWithSource};
use serde::{Deserialize, Serialize};

pub const METHOD_NAME: &str = "conda/build_v1";
Expand Down Expand Up @@ -59,8 +59,20 @@ pub struct CondaBuildV1Prefix {

/// The platform for which the packages were installed.
pub platform: Platform,
// TODO: Add information about matchspecs that were used to install the package.
// TODO: Add information about the packages that were installed.

/// The packages that are installed in the prefix.
#[serde(default)]
pub packages: Vec<CondaBuildV1PrefixPackage>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CondaBuildV1PrefixPackage {
/// The repodata record of the package that was installed in the prefix.
#[serde(flatten)]
pub repodata_record: RepoDataRecord,
// TODO: Add information about how the package was introduced into the prefix. E.g. it was
// directly requested in the spec, or as a run_export, etc.
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
25 changes: 21 additions & 4 deletions crates/pixi_command_dispatcher/src/backend_source_build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ use pixi_build_types::{
procedures::{
conda_build_v0::{CondaBuildParams, CondaBuiltPackage, CondaOutputIdentifier},
conda_build_v1::{
CondaBuildV1Output, CondaBuildV1Params, CondaBuildV1Prefix, CondaBuildV1Result,
CondaBuildV1Output, CondaBuildV1Params, CondaBuildV1Prefix, CondaBuildV1PrefixPackage,
CondaBuildV1Result,
},
},
};
use pixi_record::{PinnedSourceSpec, PixiRecord};
use rattler_conda_types::{ChannelConfig, ChannelUrl, Platform, Version};
use pixi_record::PinnedSourceSpec;
use rattler_conda_types::{ChannelConfig, ChannelUrl, Platform, RepoDataRecord, Version};
use serde::Serialize;
use thiserror::Error;

Expand Down Expand Up @@ -113,7 +114,7 @@ pub struct BackendSourceBuildPrefix {
pub prefix: PathBuf,

/// The records that are installed in the prefix.
pub records: Vec<PixiRecord>,
pub records: Vec<RepoDataRecord>,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -275,10 +276,26 @@ impl BackendSourceBuildSpec {
build_prefix: Some(CondaBuildV1Prefix {
prefix: params.build_prefix.prefix,
platform: params.build_prefix.platform,
packages: params
.build_prefix
.records
.into_iter()
.map(|record| CondaBuildV1PrefixPackage {
repodata_record: record,
})
.collect(),
}),
host_prefix: Some(CondaBuildV1Prefix {
prefix: params.host_prefix.prefix,
platform: params.host_prefix.platform,
packages: params
.host_prefix
.records
.into_iter()
.map(|record| CondaBuildV1PrefixPackage {
repodata_record: record,
})
.collect(),
}),
output: CondaBuildV1Output {
name: record.name.clone(),
Expand Down
88 changes: 50 additions & 38 deletions crates/pixi_command_dispatcher/src/source_build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,29 @@ impl SourceBuildSpec {
CommandDispatcherError::Failed(SourceBuildError::CreateWorkDirectory(err))
})?;

// Extract the repodata records from the build and host environments.
let build_records = Self::extract_prefix_repodata(build_records, build_prefix);
let host_records = Self::extract_prefix_repodata(host_records, host_prefix);

let built_source = command_dispatcher
.backend_source_build(BackendSourceBuildSpec {
method: BackendSourceBuildMethod::BuildV1(BackendSourceBuildV1Method {
editable: self.editable(),
build_prefix: BackendSourceBuildPrefix {
platform: self.build_environment.build_platform,
prefix: directories.build_prefix,
records: build_records.clone(),
records: build_records
.iter()
.map(|p| p.repodata_record.clone())
.collect(),
},
host_prefix: BackendSourceBuildPrefix {
platform: self.build_environment.host_platform,
prefix: directories.host_prefix,
records: host_records.clone(),
records: host_records
.iter()
.map(|p| p.repodata_record.clone())
.collect(),
},
variant: output.metadata.variant,
output_directory: self.output_directory,
Expand All @@ -503,50 +513,52 @@ impl SourceBuildSpec {
.await
.map_err_with(SourceBuildError::from)?;

// Little helper function the build a `BuildHostEnvironment` from expected and
// installed records.
let build_host_environment =
|records: Vec<PixiRecord>, prefix: Option<InstallPixiEnvironmentResult>| {
let Some(prefix) = prefix else {
return BuildHostEnvironment { packages: vec![] };
};

BuildHostEnvironment {
packages: records
.into_iter()
.map(|record| match record {
PixiRecord::Binary(repodata_record) => BuildHostPackage {
repodata_record,
source: None,
},
PixiRecord::Source(source) => {
let repodata_record = prefix
.resolved_source_records
.get(&source.package_record.name)
.cloned()
.expect(
"the source record should be present in the result sources",
);
BuildHostPackage {
repodata_record,
source: Some(source.source),
}
}
})
.collect(),
}
};

Ok(BuiltPackage {
output_file: built_source.output_file,
metadata: CachedBuildSourceInfo {
globs: built_source.input_globs,
build: build_host_environment(build_records, build_prefix),
host: build_host_environment(host_records, host_prefix),
build: BuildHostEnvironment {
packages: build_records,
},
host: BuildHostEnvironment {
packages: host_records,
},
},
})
}

/// Little helper function the build a `BuildHostPackage` from expected and
/// installed records.
fn extract_prefix_repodata(
records: Vec<PixiRecord>,
prefix: Option<InstallPixiEnvironmentResult>,
) -> Vec<BuildHostPackage> {
let Some(prefix) = prefix else {
return vec![];
};

records
.into_iter()
.map(|record| match record {
PixiRecord::Binary(repodata_record) => BuildHostPackage {
repodata_record,
source: None,
},
PixiRecord::Source(source) => {
let repodata_record = prefix
.resolved_source_records
.get(&source.package_record.name)
.cloned()
.expect("the source record should be present in the result sources");
BuildHostPackage {
repodata_record,
source: Some(source.source),
}
}
})
.collect()
}

async fn solve_dependencies(
&self,
name: String,
Expand Down
Loading