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

fix: use project root directory instead of task.working_directory for base dir when hashing #1202

Merged
merged 4 commits into from
Apr 16, 2024
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
10 changes: 8 additions & 2 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ pub async fn execute(args: Args) -> miette::Result<()> {
eprintln!();
}
eprintln!(
"{}{}{}{}{}",
"{}{}{} in {}{}{}",
console::Emoji("✨ ", ""),
console::style("Pixi task (").bold(),
console::style(executable_task.name().unwrap_or("unnamed"))
.green()
.bold(),
executable_task
.run_environment
.name()
Expand All @@ -150,7 +153,10 @@ pub async fn execute(args: Args) -> miette::Result<()> {
{
CanSkip::No(cache) => cache,
CanSkip::Yes => {
eprintln!("Task can be skipped (cache hit) 🚀");
eprintln!(
"Task '{}' can be skipped (cache hit) 🚀",
console::style(executable_task.name().unwrap_or("")).bold()
);
task_idx += 1;
continue;
}
Expand Down
42 changes: 36 additions & 6 deletions src/task/task_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl TaskHash {
lock_file: &LockFile,
) -> Result<Option<Self>, InputHashesError> {
let input_hashes = InputHashes::from_task(task).await?;
let output_hashes = OutputHashes::from_task(task).await?;
let output_hashes = OutputHashes::from_task(task, false).await?;

if input_hashes.is_none() && output_hashes.is_none() {
return Ok(None);
Expand All @@ -104,7 +104,7 @@ impl TaskHash {
&mut self,
task: &ExecutableTask<'_>,
) -> Result<(), InputHashesError> {
self.outputs = OutputHashes::from_task(task).await?;
self.outputs = OutputHashes::from_task(task, true).await?;
Ok(())
}

Expand Down Expand Up @@ -132,7 +132,20 @@ impl InputHashes {
return Ok(None);
};

let files = FileHashes::from_files(&task.working_directory()?, inputs.iter()).await?;
let files = FileHashes::from_files(task.project().root(), inputs.iter()).await?;

// check if any files were matched
if files.files.is_empty() {
tracing::warn!(
"No files matched the input globs for task '{}'",
task.name().unwrap_or_default()
);
tracing::warn!(
"Input globs: {:?}",
inputs.iter().map(|g| g.as_str()).collect::<Vec<_>>()
);
}

Ok(Some(Self { files }))
}
}
Expand All @@ -144,13 +157,30 @@ pub struct OutputHashes {
}

impl OutputHashes {
/// Compute the input hashes from a task.
pub async fn from_task(task: &ExecutableTask<'_>) -> Result<Option<Self>, InputHashesError> {
/// Compute the output hashes from a task.
pub async fn from_task(
task: &ExecutableTask<'_>,
warn: bool,
) -> Result<Option<Self>, InputHashesError> {
let Some(ref outputs) = task.task().as_execute().and_then(|e| e.outputs.clone()) else {
return Ok(None);
};

let files = FileHashes::from_files(&task.working_directory()?, outputs.iter()).await?;
let files = FileHashes::from_files(task.project().root(), outputs.iter()).await?;

// check if any files were matched
if warn && files.files.is_empty() {
tracing::warn!(
"No files matched the output globs for task` '{}'",
task.name().unwrap_or_default()
);
tracing::warn!(
"Output globs: {:?}",
outputs.iter().map(|g| g.as_str()).collect::<Vec<_>>()
);
return Ok(None);
}

Ok(Some(Self { files }))
}
}
Expand Down
Loading