Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add input hash/glob to lock file #868

Merged
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
16 changes: 16 additions & 0 deletions crates/rattler_lock/src/conda.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{cmp::Ordering, hash::Hash};

use rattler_conda_types::{PackageRecord, RepoDataRecord};
use rattler_digest::Sha256Hash;
use url::Url;

use crate::UrlOrPath;
Expand All @@ -21,6 +22,20 @@ pub struct CondaPackageData {

/// The channel of the package if this cannot be derived from the url.
pub channel: Option<Url>,

/// The input hash of the package (only valid for source packages)
pub input: Option<InputHash>,
}

/// A record of input files that were used to define the metadata of the
/// package.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct InputHash {
/// The hash of all input files combined.
pub hash: Sha256Hash,

/// The globs that were used to define the input files.
pub globs: Vec<String>,
}

impl AsRef<PackageRecord> for CondaPackageData {
Expand Down Expand Up @@ -58,6 +73,7 @@ impl From<RepoDataRecord> for CondaPackageData {
file_name: Some(value.file_name),
channel: Url::parse(&value.channel).ok(),
location,
input: None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod utils;

pub use builder::LockFileBuilder;
pub use channel::Channel;
pub use conda::{CondaPackageData, ConversionError};
pub use conda::{CondaPackageData, ConversionError, InputHash};
pub use file_format_version::FileFormatVersion;
pub use hash::PackageHashes;
pub use parse::ParseCondaLockError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl<'a> From<CondaPackageDataModel<'a>> for CondaPackageData {
let (derived_arch, derived_platform) = derive_arch_and_platform(&subdir);

Self {
input: None,
package_record: PackageRecord {
build: value.build.into_owned(),
build_number: value.build_number,
Expand Down
19 changes: 19 additions & 0 deletions crates/rattler_lock/src/parse/models/v6/conda_package_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde_with::serde_as;
use url::Url;

use crate::{
conda::InputHash,
utils::{derived_fields, derived_fields::LocationDerivedFields},
CondaPackageData, ConversionError, UrlOrPath,
};
Expand Down Expand Up @@ -62,6 +63,9 @@ pub(crate) struct CondaPackageDataModel<'a> {
#[serde_as(as = "Option<SerializableHash::<rattler_digest::Md5>>")]
pub md5: Option<Md5Hash>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<SerializableHash::<rattler_digest::Sha256>>")]
pub hash: Option<Sha256Hash>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<SerializableHash::<rattler_digest::Md5>>")]
pub legacy_bz2_md5: Option<Md5Hash>,

Expand Down Expand Up @@ -103,6 +107,9 @@ pub(crate) struct CondaPackageDataModel<'a> {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<crate::utils::serde::Timestamp>")]
pub timestamp: Option<chrono::DateTime<chrono::Utc>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub input: Option<Cow<'a, Vec<String>>>,
}

impl<'a> TryFrom<CondaPackageDataModel<'a>> for CondaPackageData {
Expand Down Expand Up @@ -135,7 +142,17 @@ impl<'a> TryFrom<CondaPackageDataModel<'a>> for CondaPackageData {
);
let (derived_arch, derived_platform) = derived_fields::derive_arch_and_platform(&subdir);

let input_hash = if value.hash.is_some() || value.input.is_some() {
Some(InputHash {
hash: value.hash.unwrap_or_default(),
globs: value.input.map_or_else(Vec::new, Cow::into_owned),
})
} else {
None
};

Ok(Self {
input: input_hash,
package_record: PackageRecord {
build,
build_number,
Expand Down Expand Up @@ -234,6 +251,8 @@ impl<'a> From<&'a CondaPackageData> for CondaPackageDataModel<'a> {
track_features: Cow::Borrowed(&value.package_record.track_features),
license: Cow::Borrowed(&value.package_record.license),
license_family: Cow::Borrowed(&value.package_record.license_family),
hash: value.input.as_ref().map(|r| r.hash),
input: value.input.as_ref().map(|r| Cow::Borrowed(&r.globs)),
}
}
}
1 change: 1 addition & 0 deletions crates/rattler_lock/src/parse/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub fn parse_v3_or_lower(

let deduplicated_idx = conda_packages
.insert_full(CondaPackageData {
input: None,
package_record: PackageRecord {
arch: value.arch.or(derived_arch),
build,
Expand Down
Loading