Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions crates/pixi_build_backend_passthrough/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use pixi_build_frontend::{
json_rpc::CommunicationError,
};
use pixi_build_types::{
BackendCapabilities, NamedSpecV1, PackageSpecV1, ProjectModelV1, SourcePackageName,
TargetSelectorV1, TargetV1, TargetsV1, VersionedProjectModel,
BackendCapabilities, NamedSpecV1, PackageModelV1, PackageSpecV1, SourcePackageName,
TargetSelectorV1, TargetV1, TargetsV1, VersionedPackageModel,
procedures::{
conda_build_v1::{CondaBuildV1Params, CondaBuildV1Result},
conda_outputs::{
Expand All @@ -36,7 +36,7 @@ const BACKEND_NAME: &str = "passthrough";
/// backend is useful for testing and debugging purposes, as it does not perform
/// any actual building or processing of the project model.
pub struct PassthroughBackend {
project_model: ProjectModelV1,
project_model: PackageModelV1,
config: PassthroughBackendConfig,
source_dir: PathBuf,
index_json: Option<IndexJson>,
Expand Down Expand Up @@ -233,7 +233,7 @@ impl InMemoryBackendInstantiator for PassthroughBackendInstantiator {
params: InitializeParams,
) -> Result<Self::Backend, Box<CommunicationError>> {
let project_model = match params.project_model {
Some(VersionedProjectModel::V1(project_model)) => project_model,
Some(VersionedPackageModel::V1(project_model)) => project_model,
_ => {
return Err(Box::new(CommunicationError::BackendError(
BackendError::new("Passthrough backend only supports project model v1"),
Expand Down
6 changes: 3 additions & 3 deletions crates/pixi_build_discovery/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use itertools::Itertools;
use miette::Diagnostic;
use ordermap::OrderMap;
use pixi_build_type_conversions::{to_project_model_v1, to_target_selector_v1};
use pixi_build_types::{ProjectModelV1, TargetSelectorV1};
use pixi_build_types::{PackageModelV1, TargetSelectorV1};
use pixi_config::Config;
use pixi_manifest::{
DiscoveryStart, ExplicitManifestError, PackageManifest, PrioritizedChannel, WithProvenance,
Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct BackendInitializationParams {
pub manifest_path: PathBuf,

/// Optionally, the manifest of the discovered package.
pub project_model: Option<ProjectModelV1>,
pub project_model: Option<PackageModelV1>,

/// Additional configuration that applies to the backend.
pub configuration: Option<serde_json::Value>,
Expand Down Expand Up @@ -377,7 +377,7 @@ impl DiscoveredBackend {
source: None,
source_anchor: source_dir,
manifest_path: package_xml_absolute_path,
project_model: Some(ProjectModelV1::default()),
project_model: Some(PackageModelV1::default()),
configuration: None,
target_configuration: None,
},
Expand Down
10 changes: 5 additions & 5 deletions crates/pixi_build_frontend/src/backend/json_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use jsonrpsee::{
use miette::Diagnostic;
use ordermap::OrderMap;
use pixi_build_types::{
BackendCapabilities, FrontendCapabilities, ProjectModelV1, TargetSelectorV1,
VersionedProjectModel,
BackendCapabilities, FrontendCapabilities, PackageModelV1, TargetSelectorV1,
VersionedPackageModel,
procedures::{
self,
conda_build_v1::{CondaBuildV1Params, CondaBuildV1Result},
Expand Down Expand Up @@ -146,7 +146,7 @@ impl JsonRpcBackend {
source_dir: PathBuf,
manifest_path: PathBuf,
workspace_root: PathBuf,
package_manifest: Option<ProjectModelV1>,
package_manifest: Option<PackageModelV1>,
configuration: Option<serde_json::Value>,
target_configuration: Option<OrderMap<TargetSelectorV1, serde_json::Value>>,
cache_dir: Option<PathBuf>,
Expand Down Expand Up @@ -215,7 +215,7 @@ impl JsonRpcBackend {
source_dir: PathBuf,
manifest_path: PathBuf,
workspace_root: PathBuf,
project_model: Option<ProjectModelV1>,
project_model: Option<PackageModelV1>,
configuration: Option<serde_json::Value>,
target_configuration: Option<OrderMap<TargetSelectorV1, serde_json::Value>>,
cache_dir: Option<PathBuf>,
Expand Down Expand Up @@ -252,7 +252,7 @@ impl JsonRpcBackend {
.request(
procedures::initialize::METHOD_NAME,
RpcParams::from(InitializeParams {
project_model: project_model.map(VersionedProjectModel::V1),
project_model: project_model.map(VersionedPackageModel::V1),
configuration,
target_configuration,
manifest_path: manifest_path.clone(),
Expand Down
10 changes: 5 additions & 5 deletions crates/pixi_build_type_conversions/src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ fn to_targets_v1(
})
}

/// Converts a [`PackageManifest`] to a [`pbt::ProjectModelV1`].
/// Converts a [`PackageManifest`] to a [`pbt::PackageModelV1`].
pub fn to_project_model_v1(
manifest: &PackageManifest,
channel_config: &ChannelConfig,
) -> Result<pbt::ProjectModelV1, SpecConversionError> {
let project = pbt::ProjectModelV1 {
) -> Result<pbt::PackageModelV1, SpecConversionError> {
let project = pbt::PackageModelV1 {
name: manifest.package.name.clone(),
version: manifest.package.version.clone(),
description: manifest.package.description.clone(),
Expand All @@ -188,7 +188,7 @@ pub fn to_project_model_v1(
mod tests {
use std::path::PathBuf;

use pixi_build_types::VersionedProjectModel;
use pixi_build_types::VersionedPackageModel;
use rattler_conda_types::ChannelConfig;
use rstest::rstest;

Expand Down Expand Up @@ -221,7 +221,7 @@ mod tests {
.unwrap();

// Convert the manifest to the project model
let project_model: VersionedProjectModel =
let project_model: VersionedPackageModel =
super::to_project_model_v1(&package_manifest.value, &some_channel_config())
.unwrap()
.into();
Expand Down
6 changes: 3 additions & 3 deletions crates/pixi_build_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub use capabilities::{BackendCapabilities, FrontendCapabilities};
pub use channel_configuration::ChannelConfiguration;
pub use conda_package_metadata::CondaPackageMetadata;
pub use project_model::{
BinaryPackageSpecV1, GitReferenceV1, GitSpecV1, NamedSpecV1, PackageSpecV1, PathSpecV1,
ProjectModelV1, SourcePackageName, SourcePackageSpecV1, TargetSelectorV1, TargetV1, TargetsV1,
UrlSpecV1, VersionedProjectModel,
BinaryPackageSpecV1, GitReferenceV1, GitSpecV1, NamedSpecV1, PackageModelV1, PackageSpecV1,
PathSpecV1, SourcePackageName, SourcePackageSpecV1, TargetSelectorV1, TargetV1, TargetsV1,
UrlSpecV1, VersionedPackageModel,
};
use rattler_conda_types::{
GenericVirtualPackage, PackageName, Platform, Version, VersionSpec,
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 @@ -5,7 +5,7 @@ use std::path::PathBuf;
use ordermap::OrderMap;
use serde::{Deserialize, Serialize};

use crate::{TargetSelectorV1, VersionedProjectModel};
use crate::{TargetSelectorV1, VersionedPackageModel};

pub const METHOD_NAME: &str = "initialize";

Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct InitializeParams {
/// Project model that the backend should use even though it is an option
/// it is highly recommended to use this field. Otherwise, it will be very
/// easy to break backwards compatibility.
pub project_model: Option<VersionedProjectModel>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use #[serde(rename = ...)]?
Or how is this breaking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use #[serde(rename = ...)]? Or how is this breaking?

Yeah, that's an easy way around for the field name.

The other breaking thing is that VersionedProjectModel serializes to something like 1 { ...content_of_project_model }. Adapting this to be the same is described as option 3 above

pub project_model: Option<VersionedPackageModel>,

/// Backend specific configuration passed from the frontend to the backend.
pub configuration: Option<serde_json::Value>,
Expand Down
52 changes: 26 additions & 26 deletions crates/pixi_build_types/src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,34 @@ use url::Url;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version", content = "data")]
#[serde(rename_all = "camelCase")]
pub enum VersionedProjectModel {
pub enum VersionedPackageModel {
/// Version 1 of the project model.
#[serde(rename = "1")]
V1(ProjectModelV1),
V1(PackageModelV1),
// When adding don't forget to update the highest_version function
}

impl VersionedProjectModel {
impl VersionedPackageModel {
/// Highest version of the project model.
pub fn highest_version() -> u32 {
// increase this when adding a new version
1
}

/// Move into the v1 type, returns None if the version is not v1.
pub fn into_v1(self) -> Option<ProjectModelV1> {
pub fn into_v1(self) -> Option<PackageModelV1> {
match self {
VersionedProjectModel::V1(v) => Some(v),
VersionedPackageModel::V1(v) => Some(v),
// Add this once we have more versions
//_ => None,
}
}

/// Returns a reference to the v1 type, returns None if the version is not
/// v1.
pub fn as_v1(&self) -> Option<&ProjectModelV1> {
pub fn as_v1(&self) -> Option<&PackageModelV1> {
match self {
VersionedProjectModel::V1(v) => Some(v),
VersionedPackageModel::V1(v) => Some(v),
// Add this once we have more versions
//_ => None,
}
Expand All @@ -71,7 +71,7 @@ pub type SourcePackageName = String;

#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ProjectModelV1 {
pub struct PackageModelV1 {
/// The name of the project
pub name: Option<String>,

Expand Down Expand Up @@ -102,22 +102,22 @@ pub struct ProjectModelV1 {
/// URL of the project documentation
pub documentation: Option<Url>,

/// The target of the project, this may contain
/// The target of the package, this may contain
/// platform specific configurations.
pub targets: Option<TargetsV1>,
}

impl IsDefault for ProjectModelV1 {
impl IsDefault for PackageModelV1 {
type Item = Self;

fn is_non_default(&self) -> Option<&Self::Item> {
Some(self)
}
}

impl From<ProjectModelV1> for VersionedProjectModel {
fn from(value: ProjectModelV1) -> Self {
VersionedProjectModel::V1(value)
impl From<PackageModelV1> for VersionedPackageModel {
fn from(value: PackageModelV1) -> Self {
VersionedPackageModel::V1(value)
}
}

Expand Down Expand Up @@ -193,13 +193,13 @@ impl IsDefault for TargetsV1 {
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TargetV1 {
/// Host dependencies of the project
/// Host dependencies of the package
pub host_dependencies: Option<OrderMap<SourcePackageName, PackageSpecV1>>,

/// Build dependencies of the project
/// Build dependencies of the package
pub build_dependencies: Option<OrderMap<SourcePackageName, PackageSpecV1>>,

/// Run dependencies of the project
/// Run dependencies of the package
pub run_dependencies: Option<OrderMap<SourcePackageName, PackageSpecV1>>,
}

Expand Down Expand Up @@ -415,12 +415,12 @@ impl std::fmt::Debug for BinaryPackageSpecV1 {
}

// Custom Hash implementations that skip default values for stability
impl Hash for ProjectModelV1 {
impl Hash for PackageModelV1 {
/// Custom hash implementation using StableHashBuilder to ensure different
/// field configurations produce different hashes while maintaining
/// forward/backward compatibility.
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
let ProjectModelV1 {
let PackageModelV1 {
name,
version,
description,
Expand Down Expand Up @@ -644,8 +644,8 @@ mod tests {

#[test]
fn test_hash_stability_with_default_values() {
// Create a minimal ProjectModelV1 instance
let mut project_model = ProjectModelV1 {
// Create a minimal PackageModelV1 instance
let mut project_model = PackageModelV1 {
name: Some("test-project".to_string()),
version: None,
description: None,
Expand Down Expand Up @@ -700,8 +700,8 @@ mod tests {

#[test]
fn test_hash_changes_with_meaningful_values() {
// Create a minimal ProjectModelV1 instance
let mut project_model = ProjectModelV1 {
// Create a minimal PackageModelV1 instance
let mut project_model = PackageModelV1 {
name: Some("test-project".to_string()),
version: None,
description: None,
Expand Down Expand Up @@ -995,15 +995,15 @@ mod tests {

#[test]
fn test_hash_collision_bug_project_model() {
// Test the same issue in ProjectModelV1
let project1 = ProjectModelV1 {
// Test the same issue in PackageModelV1
let project1 = PackageModelV1 {
name: Some("test".to_string()),
description: Some("test description".to_string()),
license: None,
..Default::default()
};

let project2 = ProjectModelV1 {
let project2 = PackageModelV1 {
name: Some("test".to_string()),
description: None,
license: Some("test description".to_string()),
Expand All @@ -1015,7 +1015,7 @@ mod tests {

assert_ne!(
hash1, hash2,
"Same value in different fields should produce different hashes in ProjectModelV1"
"Same value in different fields should produce different hashes in PackageModelV1"
);
}
}
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 @@ -9,7 +9,7 @@ use async_fd_lock::{LockWrite, RwLockWriteGuard};
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
use ordermap::OrderMap;
use pixi_build_discovery::{BackendInitializationParams, DiscoveredBackend};
use pixi_build_types::{ProjectModelV1, TargetSelectorV1};
use pixi_build_types::{PackageModelV1, TargetSelectorV1};
use pixi_record::PinnedSourceSpec;
use pixi_stable_hash::{StableHashBuilder, json::StableJson, map::StableMap};
use rattler_conda_types::{ChannelUrl, GenericVirtualPackage, Platform, RepoDataRecord};
Expand Down Expand Up @@ -317,7 +317,7 @@ impl BuildCacheEntry {
/// warranted.
pub struct PackageBuildInputHashBuilder<'a> {
/// The project model itself. Contains dependencies and more.
pub project_model: Option<&'a ProjectModelV1>,
pub project_model: Option<&'a PackageModelV1>,

/// The backend specific configuration
pub configuration: Option<&'a serde_json::Value>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use once_cell::sync::Lazy;
use pathdiff::diff_paths;
use pixi_build_discovery::{CommandSpec, EnabledProtocols};
use pixi_build_frontend::Backend;
use pixi_build_types::{ProjectModelV1, procedures::conda_outputs::CondaOutputsParams};
use pixi_build_types::{PackageModelV1, procedures::conda_outputs::CondaOutputsParams};
use pixi_glob::GlobHashKey;
use pixi_record::{InputHash, PinnedSourceSpec};
use pixi_spec::{SourceAnchor, SourceSpec};
Expand Down Expand Up @@ -488,7 +488,7 @@ pub enum BuildBackendMetadataError {

/// Computes an additional hash to be used in glob hash
pub fn calculate_additional_glob_hash(
project_model: &Option<ProjectModelV1>,
project_model: &Option<PackageModelV1>,
variants: &Option<BTreeMap<String, Vec<String>>>,
) -> Vec<u8> {
let mut hasher = Xxh3::new();
Expand Down
Loading