Skip to content

Commit 3484c4f

Browse files
authored
feat: pass repodata records to build backend (#4252)
1 parent 08fcfb7 commit 3484c4f

File tree

3 files changed

+86
-45
lines changed

3 files changed

+86
-45
lines changed

crates/pixi_build_types/src/procedures/conda_build_v1.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
path::PathBuf,
1111
};
1212

13-
use rattler_conda_types::{ChannelUrl, PackageName, Platform, VersionWithSource};
13+
use rattler_conda_types::{ChannelUrl, PackageName, Platform, RepoDataRecord, VersionWithSource};
1414
use serde::{Deserialize, Serialize};
1515

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

6060
/// The platform for which the packages were installed.
6161
pub platform: Platform,
62-
// TODO: Add information about matchspecs that were used to install the package.
63-
// TODO: Add information about the packages that were installed.
62+
63+
/// The packages that are installed in the prefix.
64+
#[serde(default)]
65+
pub packages: Vec<CondaBuildV1PrefixPackage>,
66+
}
67+
68+
#[derive(Debug, Serialize, Deserialize, Clone)]
69+
#[serde(rename_all = "camelCase")]
70+
pub struct CondaBuildV1PrefixPackage {
71+
/// The repodata record of the package that was installed in the prefix.
72+
#[serde(flatten)]
73+
pub repodata_record: RepoDataRecord,
74+
// TODO: Add information about how the package was introduced into the prefix. E.g. it was
75+
// directly requested in the spec, or as a run_export, etc.
6476
}
6577

6678
#[derive(Debug, Serialize, Deserialize, Clone)]

crates/pixi_command_dispatcher/src/backend_source_build/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ use pixi_build_types::{
1616
procedures::{
1717
conda_build_v0::{CondaBuildParams, CondaBuiltPackage, CondaOutputIdentifier},
1818
conda_build_v1::{
19-
CondaBuildV1Output, CondaBuildV1Params, CondaBuildV1Prefix, CondaBuildV1Result,
19+
CondaBuildV1Output, CondaBuildV1Params, CondaBuildV1Prefix, CondaBuildV1PrefixPackage,
20+
CondaBuildV1Result,
2021
},
2122
},
2223
};
23-
use pixi_record::{PinnedSourceSpec, PixiRecord};
24-
use rattler_conda_types::{ChannelConfig, ChannelUrl, Platform, Version};
24+
use pixi_record::PinnedSourceSpec;
25+
use rattler_conda_types::{ChannelConfig, ChannelUrl, Platform, RepoDataRecord, Version};
2526
use serde::Serialize;
2627
use thiserror::Error;
2728

@@ -113,7 +114,7 @@ pub struct BackendSourceBuildPrefix {
113114
pub prefix: PathBuf,
114115

115116
/// The records that are installed in the prefix.
116-
pub records: Vec<PixiRecord>,
117+
pub records: Vec<RepoDataRecord>,
117118
}
118119

119120
#[derive(Debug, Serialize)]
@@ -275,10 +276,26 @@ impl BackendSourceBuildSpec {
275276
build_prefix: Some(CondaBuildV1Prefix {
276277
prefix: params.build_prefix.prefix,
277278
platform: params.build_prefix.platform,
279+
packages: params
280+
.build_prefix
281+
.records
282+
.into_iter()
283+
.map(|record| CondaBuildV1PrefixPackage {
284+
repodata_record: record,
285+
})
286+
.collect(),
278287
}),
279288
host_prefix: Some(CondaBuildV1Prefix {
280289
prefix: params.host_prefix.prefix,
281290
platform: params.host_prefix.platform,
291+
packages: params
292+
.host_prefix
293+
.records
294+
.into_iter()
295+
.map(|record| CondaBuildV1PrefixPackage {
296+
repodata_record: record,
297+
})
298+
.collect(),
282299
}),
283300
output: CondaBuildV1Output {
284301
name: record.name.clone(),

crates/pixi_command_dispatcher/src/source_build/mod.rs

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -477,19 +477,29 @@ impl SourceBuildSpec {
477477
CommandDispatcherError::Failed(SourceBuildError::CreateWorkDirectory(err))
478478
})?;
479479

480+
// Extract the repodata records from the build and host environments.
481+
let build_records = Self::extract_prefix_repodata(build_records, build_prefix);
482+
let host_records = Self::extract_prefix_repodata(host_records, host_prefix);
483+
480484
let built_source = command_dispatcher
481485
.backend_source_build(BackendSourceBuildSpec {
482486
method: BackendSourceBuildMethod::BuildV1(BackendSourceBuildV1Method {
483487
editable: self.editable(),
484488
build_prefix: BackendSourceBuildPrefix {
485489
platform: self.build_environment.build_platform,
486490
prefix: directories.build_prefix,
487-
records: build_records.clone(),
491+
records: build_records
492+
.iter()
493+
.map(|p| p.repodata_record.clone())
494+
.collect(),
488495
},
489496
host_prefix: BackendSourceBuildPrefix {
490497
platform: self.build_environment.host_platform,
491498
prefix: directories.host_prefix,
492-
records: host_records.clone(),
499+
records: host_records
500+
.iter()
501+
.map(|p| p.repodata_record.clone())
502+
.collect(),
493503
},
494504
variant: output.metadata.variant,
495505
output_directory: self.output_directory,
@@ -503,50 +513,52 @@ impl SourceBuildSpec {
503513
.await
504514
.map_err_with(SourceBuildError::from)?;
505515

506-
// Little helper function the build a `BuildHostEnvironment` from expected and
507-
// installed records.
508-
let build_host_environment =
509-
|records: Vec<PixiRecord>, prefix: Option<InstallPixiEnvironmentResult>| {
510-
let Some(prefix) = prefix else {
511-
return BuildHostEnvironment { packages: vec![] };
512-
};
513-
514-
BuildHostEnvironment {
515-
packages: records
516-
.into_iter()
517-
.map(|record| match record {
518-
PixiRecord::Binary(repodata_record) => BuildHostPackage {
519-
repodata_record,
520-
source: None,
521-
},
522-
PixiRecord::Source(source) => {
523-
let repodata_record = prefix
524-
.resolved_source_records
525-
.get(&source.package_record.name)
526-
.cloned()
527-
.expect(
528-
"the source record should be present in the result sources",
529-
);
530-
BuildHostPackage {
531-
repodata_record,
532-
source: Some(source.source),
533-
}
534-
}
535-
})
536-
.collect(),
537-
}
538-
};
539-
540516
Ok(BuiltPackage {
541517
output_file: built_source.output_file,
542518
metadata: CachedBuildSourceInfo {
543519
globs: built_source.input_globs,
544-
build: build_host_environment(build_records, build_prefix),
545-
host: build_host_environment(host_records, host_prefix),
520+
build: BuildHostEnvironment {
521+
packages: build_records,
522+
},
523+
host: BuildHostEnvironment {
524+
packages: host_records,
525+
},
546526
},
547527
})
548528
}
549529

530+
/// Little helper function the build a `BuildHostPackage` from expected and
531+
/// installed records.
532+
fn extract_prefix_repodata(
533+
records: Vec<PixiRecord>,
534+
prefix: Option<InstallPixiEnvironmentResult>,
535+
) -> Vec<BuildHostPackage> {
536+
let Some(prefix) = prefix else {
537+
return vec![];
538+
};
539+
540+
records
541+
.into_iter()
542+
.map(|record| match record {
543+
PixiRecord::Binary(repodata_record) => BuildHostPackage {
544+
repodata_record,
545+
source: None,
546+
},
547+
PixiRecord::Source(source) => {
548+
let repodata_record = prefix
549+
.resolved_source_records
550+
.get(&source.package_record.name)
551+
.cloned()
552+
.expect("the source record should be present in the result sources");
553+
BuildHostPackage {
554+
repodata_record,
555+
source: Some(source.source),
556+
}
557+
}
558+
})
559+
.collect()
560+
}
561+
550562
async fn solve_dependencies(
551563
&self,
552564
name: String,

0 commit comments

Comments
 (0)