Skip to content

Commit

Permalink
Merge branch 'feature/pixi-build' into feat/source-satisfiability
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager committed Sep 20, 2024
2 parents a9c2785 + deaa027 commit 3e77599
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
3 changes: 3 additions & 0 deletions crates/pixi_build_frontend/src/protocols/pixi/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl ProtocolError {
Error::Call(err) if err.code() == ErrorCode::MethodNotFound.code() => {
Self::MethodNotImplemented(method.to_string())
}
Error::ParseError(err) => Self::ParseError(method.to_string(), err),
e => Self::JsonRpc(e),
}
}
Expand All @@ -52,6 +53,8 @@ impl ProtocolError {
pub enum ProtocolError {
#[error(transparent)]
JsonRpc(ClientError),
#[error("received invalid response from backend when calling '{0}'")]
ParseError(String, #[source] serde_json::Error),
#[error(transparent)]
#[diagnostic(transparent)]
BackendError(#[from] BackendError),
Expand Down
5 changes: 4 additions & 1 deletion crates/pixi_build_types/src/procedures/conda_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ pub struct CondaOutputIdentifier {
#[derive(Debug, Serialize, Deserialize)]
pub struct CondaBuildResult {
// TODO: Should this be a UTF8 encoded type
pub path: PathBuf,
pub output_file: PathBuf,
/// The globs that were used as input to the build.
/// use these for re-verifying the build.
pub input_globs: Vec<String>,
}
3 changes: 3 additions & 0 deletions examples/flask-hello-world-pyproject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ start = "python -m flask --app flask_hello_world_pyproject.app:app run --port=50

[tool.pixi.feature.test.tasks]
test = "pytest -v tests/*"

[tool.pixi.host-dependencies]
hatchling = "*"
35 changes: 29 additions & 6 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use pixi_build_types::{
use pixi_record::{InputHash, InputHashError, PinnedPathSpec, PinnedSourceSpec, SourceRecord};
use pixi_spec::SourceSpec;
use rattler_conda_types::{ChannelConfig, PackageRecord, Platform, RepoDataRecord};
use rattler_digest::Sha256;
use thiserror::Error;
use typed_path::{Utf8TypedPath, Utf8TypedPathBuf};
use url::Url;
Expand All @@ -34,6 +35,9 @@ pub enum BuildError {
#[error("failed to resolve source path {}", &.0)]
ResolveSourcePath(Utf8TypedPathBuf, #[source] std::io::Error),

#[error("error calculating sha for {}", &.0.display())]
CalculateSha(PathBuf, #[source] std::io::Error),

#[error(transparent)]
BuildFrontendSetup(pixi_build_frontend::BuildFrontendError),

Expand Down Expand Up @@ -69,6 +73,15 @@ pub struct SourceMetadata {
pub records: Vec<SourceRecord>,
}

/// The result of a conda-build operation.
pub struct CondaBuildOutput {
/// The repodata record that was created.
pub repodata_record: RepoDataRecord,

/// The input file globs that were used to build the package.
pub input_globs: Vec<String>,
}

impl BuildContext {
pub fn new(channel_config: ChannelConfig) -> Self {
Self {
Expand Down Expand Up @@ -109,7 +122,7 @@ impl BuildContext {
source_spec: &SourceRecord,
channels: &[Url],
target_platform: Platform,
) -> Result<RepoDataRecord, BuildError> {
) -> Result<CondaBuildOutput, BuildError> {
let source = self.fetch_pinned_source(&source_spec.source).await?;

// TODO: Add caching of this information based on the source.
Expand Down Expand Up @@ -145,25 +158,35 @@ impl BuildContext {
.await
.map_err(|e| BuildError::BackendError(e.into()))?;

// Add the sha256 to the package record.
let sha = rattler_digest::compute_file_digest::<Sha256>(&build_result.output_file)
.map_err(|e| BuildError::CalculateSha(source, e))?;
let mut package_record = source_spec.package_record.clone();
package_record.sha256 = Some(sha);
// Construct a repodata record that represents the package
Ok(RepoDataRecord {
package_record: source_spec.package_record.clone(),
url: Url::from_file_path(&build_result.path).map_err(|_| {
let record = RepoDataRecord {
package_record,
url: Url::from_file_path(&build_result.output_file).map_err(|_| {
BuildError::FrontendError(
miette::miette!(
"failed to convert returned path to URL: {}",
build_result.path.display()
build_result.output_file.display()
)
.into(),
)
})?,
channel: String::new(),
file_name: build_result
.path
.output_file
.file_name()
.and_then(OsStr::to_str)
.map(ToString::to_string)
.unwrap_or_default(),
};

Ok(CondaBuildOutput {
repodata_record: record,
input_globs: build_result.input_globs,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub async fn update_prefix_conda(
&source_record.package_record.version
)
})?;
repodata_records.push(built_source_record);
repodata_records.push(built_source_record.repodata_record);
}

// Execute the operations that are returned by the solver.
Expand Down

0 comments on commit 3e77599

Please sign in to comment.