Skip to content

Commit 4ca1e5c

Browse files
authored
fix: compute relative path for source dirs (#157)
I misread the code and thought that we pass the recipe dir as relative path. Instead it's the source that can be relative and needs to be turned into an absolute path.
1 parent 5e62280 commit 4ca1e5c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

crates/pixi-build-rattler-build/src/protocol.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,6 @@ fn build_input_globs(
370370
// Always add the current directory of the package to the globs
371371
let mut input_globs = vec!["*/**".to_string()];
372372

373-
// TODO: Remove this condition when working on https://github.com/prefix-dev/pixi/issues/3785
374-
if !source.is_absolute() {
375-
return Ok(input_globs);
376-
}
377-
378373
// Get parent directory path
379374
let parent = if source.is_file() {
380375
// use the parent path as glob
@@ -386,6 +381,11 @@ fn build_input_globs(
386381
// If there are sources add them to the globs as well
387382
if let Some(package_sources) = package_sources {
388383
for source in package_sources {
384+
let source = if source.is_absolute() {
385+
source
386+
} else {
387+
parent.join(source)
388+
};
389389
let source_glob = relative_path_joined(&parent, &source)?;
390390
if source.is_dir() {
391391
input_globs.push(format!("{}/**", source_glob));
@@ -718,4 +718,25 @@ mod tests {
718718
// The relative path from source_dir to package_source_dir should be "../pkgsrc/**"
719719
assert_eq!(globs, vec!["*/**", "../pkgsrc/**"]);
720720
}
721+
722+
#[test]
723+
fn test_build_input_globs_relative_source() {
724+
use std::fs;
725+
use std::path::PathBuf;
726+
use tempfile::tempdir;
727+
728+
// Create a temp directory to act as the base
729+
let base_dir = tempdir().unwrap();
730+
let base_path = base_dir.path();
731+
732+
// Case: source is a directory, package_sources contains a relative path
733+
let rel_dir = PathBuf::from("rel_folder");
734+
let abs_rel_dir = base_path.join(&rel_dir);
735+
fs::create_dir_all(&abs_rel_dir).unwrap();
736+
737+
// Call build_input_globs with base_path as source, and rel_dir as package source (relative)
738+
let globs = super::build_input_globs(base_path, Some(vec![rel_dir.clone()])).unwrap();
739+
// The relative path from base_path to rel_dir should be "rel_folder/**"
740+
assert_eq!(globs, vec!["*/**", "rel_folder/**"]);
741+
}
721742
}

0 commit comments

Comments
 (0)