Skip to content

Commit

Permalink
fix: forc build panic when sway package folder contains dot (#5448)
Browse files Browse the repository at this point in the history
## Description
Close #5434

Since `canonical_manifest_dir` is a dir, not a file, to get the
last-level dir name, we should use `file_name()` instead of `file_stem`.
  • Loading branch information
Halimao authored Jan 11, 2024
1 parent e7a592b commit 5dda9a7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion sway-core/src/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl BuildConfig {
true => root_module,
false => {
assert!(
root_module.starts_with(canonical_manifest_dir.file_stem().unwrap()),
root_module.starts_with(canonical_manifest_dir.file_name().unwrap()),
"file_name must be either absolute or relative to manifest directory",
);
canonical_manifest_dir
Expand Down Expand Up @@ -160,3 +160,29 @@ impl BuildConfig {
self.canonical_root_module.clone()
}
}

#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_root_from_file_name_and_manifest_path() {
let root_module = PathBuf::from("mock_path/src/main.sw");
let canonical_manifest_dir = PathBuf::from("/tmp/sway_project/mock_path");
BuildConfig::root_from_file_name_and_manifest_path(
root_module,
canonical_manifest_dir,
BuildTarget::default(),
);
}

#[test]
fn test_root_from_file_name_and_manifest_path_contains_dot() {
let root_module = PathBuf::from("mock_path_contains_._dot/src/main.sw");
let canonical_manifest_dir = PathBuf::from("/tmp/sway_project/mock_path_contains_._dot");
BuildConfig::root_from_file_name_and_manifest_path(
root_module,
canonical_manifest_dir,
BuildTarget::default(),
);
}
}

0 comments on commit 5dda9a7

Please sign in to comment.