Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
55 changes: 4 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ uv-platform-tags = { git = "https://github.com/astral-sh/uv", tag = "0.8.5" }
uv-pypi-types = { git = "https://github.com/astral-sh/uv", tag = "0.8.5" }
uv-requirements-txt = { git = "https://github.com/astral-sh/uv", tag = "0.8.5" }

wax = "0.6.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gone with ye, for now!

which = "8.0.0"

# Rattler crates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ use crate::{
},
};

/// A list of globs that should be ignored when calculating any input hash.
/// These are typically used for build artifacts that should not be included in
/// the input hash.
pub const DEFAULT_BUILD_IGNORE_GLOBS: &[&str] = &["!.pixi/**"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dont need this we now exclude hidden by default

Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of feels wrong to me, but I can't articulate why.

We for sure should document this though 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a switch I can flip. But I feel you also don't want to hover something like the .git folder by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I couldn't think of any case where you'd want a folder or file starting with . to be included.
Let's just document this for now :)


/// A query to retrieve information from the source build cache. This is
/// memoized to allow querying information from the cache while it is also
/// overwritten at the same time by a build.
Expand Down Expand Up @@ -322,11 +317,7 @@ impl SourceBuildCacheStatusSpec {
// Compute the modification time of the files that match the source input globs.
let glob_time = match GlobModificationTime::from_patterns(
&source_checkout.path,
source_info
.globs
.iter()
.map(String::as_str)
.chain(DEFAULT_BUILD_IGNORE_GLOBS.iter().copied()),
source_info.globs.iter().map(String::as_str), // .chain(DEFAULT_BUILD_IGNORE_GLOBS.iter().copied()),
) {
Ok(glob_time) => glob_time,
Err(e) => {
Expand Down
7 changes: 5 additions & 2 deletions crates/pixi_glob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ version = "0.1.0"
[dependencies]
dashmap = { workspace = true }
fs-err = { workspace = true }
ignore = "0.4"
itertools = { workspace = true }
memchr = { workspace = true }
parking_lot = { workspace = true }
rattler_digest = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync", "rt"] }
wax = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
insta = { workspace = true, features = ["yaml", "redactions"] }
rstest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
tempfile = { workspace = true }
31 changes: 15 additions & 16 deletions crates/pixi_glob/src/glob_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use std::{
path::{Path, PathBuf},
};

use itertools::Itertools;
use rattler_digest::{Sha256, Sha256Hash, digest::Digest};
use thiserror::Error;

use crate::glob_set::{self, GlobSet};
use crate::{GlobSet, GlobSetError};

/// Contains a hash of the files that match the given glob patterns.
#[derive(Debug, Clone, Default)]
Expand All @@ -25,14 +24,14 @@ pub struct GlobHash {
#[derive(Error, Debug)]
#[allow(missing_docs)]
pub enum GlobHashError {
#[error(transparent)]
FilterGlobError(#[from] glob_set::GlobSetError),

#[error("during line normalization, failed to access {}", .0.display())]
NormalizeLineEnds(PathBuf, #[source] io::Error),

#[error("the operation was cancelled")]
Cancelled,

#[error(transparent)]
GlobSetIgnore(#[from] GlobSetError),
}

impl GlobHash {
Expand All @@ -47,14 +46,12 @@ impl GlobHash {
return Ok(Self::default());
}

let glob_set = GlobSet::create(globs)?;
let mut entries = glob_set
.filter_directory(root_dir)
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|entry| entry.path().to_path_buf())
.collect_vec();
entries.sort();
let glob_set = GlobSet::create(globs);
// Collect matching entries and convert to concrete DirEntry list, propagating errors.
let mut entries: Vec<ignore::DirEntry> = glob_set.collect_matching(root_dir)?;

// Sort deterministically by path
entries.sort_by_key(|e| e.path().to_path_buf());

#[cfg(test)]
let mut matching_files = Vec::new();
Expand All @@ -63,17 +60,19 @@ impl GlobHash {
for entry in entries {
// Construct a normalized file path to ensure consistent hashing across
// platforms. And add it to the hash.
let relative_path = entry.strip_prefix(root_dir).unwrap_or(&entry);
let relative_path = entry.path().strip_prefix(root_dir).unwrap_or(entry.path());
let normalized_file_path = relative_path.to_string_lossy().replace("\\", "/");
rattler_digest::digest::Update::update(&mut hasher, normalized_file_path.as_bytes());

#[cfg(test)]
matching_files.push(normalized_file_path);

// Concatenate the contents of the file to the hash.
File::open(&entry)
File::open(entry.path())
.and_then(|mut file| normalize_line_endings(&mut file, &mut hasher))
.map_err(move |e| GlobHashError::NormalizeLineEnds(entry, e))?;
.map_err(move |e| {
GlobHashError::NormalizeLineEnds(entry.path().to_path_buf(), e)
})?;
}

if let Some(additional_hash) = additional_hash {
Expand Down
47 changes: 29 additions & 18 deletions crates/pixi_glob/src/glob_mtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use thiserror::Error;

use crate::glob_set::{self, GlobSet};
use crate::{GlobSet, GlobSetError};

/// Contains the newest modification time for the files that match the given glob patterns.
#[derive(Debug, Clone)]
Expand All @@ -27,7 +27,7 @@ pub enum GlobModificationTimeError {
#[error("error calculating modification time for {}", .0.display())]
CalculateMTime(PathBuf, #[source] std::io::Error),
#[error(transparent)]
GlobSet(#[from] glob_set::GlobSetError),
GlobSetIgnore(#[from] GlobSetError),
}

impl GlobModificationTime {
Expand All @@ -36,38 +36,49 @@ impl GlobModificationTime {
root_dir: &Path,
globs: impl IntoIterator<Item = &'a str>,
) -> Result<Self, GlobModificationTimeError> {
// If the root is not a directory or does not exist, return NoMatches.
// Delegate to the ignore-based implementation for performance.
Self::from_patterns_ignore(root_dir, globs)
}

/// Same as `from_patterns` but uses the `ignore` crate for walking/matching.
pub fn from_patterns_ignore<'a>(
root_dir: &Path,
globs: impl IntoIterator<Item = &'a str>,
) -> Result<Self, GlobModificationTimeError> {
// Normalize root to a directory if a file was passed.
let mut root = root_dir.to_owned();
if !root.is_dir() {
root.pop();
}

let glob_set = GlobSet::create(globs)?;
let entries: Vec<_> = glob_set
.filter_directory(root_dir)
.collect::<Result<Vec<_>, _>>()?;
let glob_set = GlobSet::create(globs);
let entries = glob_set.collect_matching(root_dir)?;

let mut latest = None;
let mut designated_file = PathBuf::new();

// Find the newest modification time and the designated file
for entry in entries {
let matched_path = entry.path().to_owned();
let metadata = entry.metadata().map_err(|e| {
GlobModificationTimeError::CalculateMTime(matched_path.clone(), e.into())
})?;
let modified_entry = metadata
let matched_path = entry.path().to_path_buf();
let md = match entry.metadata() {
Ok(md) => md,
Err(e) => {
return Err(GlobModificationTimeError::CalculateMTime(
matched_path,
std::io::Error::new(std::io::ErrorKind::Other, e.to_string()),
));
}
};
let modified = md
.modified()
.map_err(|e| GlobModificationTimeError::CalculateMTime(matched_path.clone(), e))?;

if let Some(ref current_latest) = latest {
if *current_latest >= modified_entry {
if let Some(cur) = latest {
if cur >= modified {
continue;
}
}

latest = Some(modified_entry);
designated_file = matched_path.clone();
latest = Some(modified);
designated_file = matched_path;
}

match latest {
Expand Down
Loading
Loading