Merge branch 'dev'

This commit is contained in:
Filipe Rodrigues 2024-08-10 15:30:33 +01:00
commit 57d9ae427f
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
4 changed files with 328 additions and 265 deletions

View File

@ -1,3 +1,9 @@
# 0.1.7
# Minor
- Removed `npath` dependency.
# 0.1.6
# Minor

493
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,27 +4,26 @@ edition = "2021"
name = "zbuild"
description = "Make-like build system"
license-file = "LICENSE-MIT"
version = "0.1.6"
version = "0.1.7"
repository = "https://github.com/zenithsiz/zbuild"
publish = ["filipejr"]
[dependencies]
anyhow = "1.0.75"
async-broadcast = "0.6.0"
async-recursion = "1.0.5"
clap = { version = "4.4.11", features = ["derive"] }
dashmap = "5.5.3"
futures = "0.3.29"
itertools = "0.12.0"
anyhow = "1.0.86"
async-broadcast = "0.7.1"
async-recursion = "1.1.1"
clap = { version = "4.5.15", features = ["derive"] }
dashmap = "6.0.1"
futures = "0.3.30"
itertools = "0.13.0"
notify = "6.1.1"
notify-debouncer-full = "0.3.1"
npath = { git = "https://github.com/gdzx/npath", rev = "00acdd2974bb1682b6d1dcc6f0ea7cd54da42381" }
pin-project = "1.1.3"
serde = { version = "1.0.193", features = ["derive"] }
serde_yaml = "0.9.27"
tokio = { version = "1.35.0", features = ["full"] }
tokio-stream = "0.1.14"
pin-project = "1.1.5"
serde = { version = "1.0.205", features = ["derive"] }
serde_yaml = "0.9.34"
tokio = { version = "1.39.2", features = ["full"] }
tokio-stream = "0.1.15"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
@ -65,7 +64,6 @@ rust.explicit_outlives_requirements = "warn"
rust.fuzzy_provenance_casts = "deny"
rust.meta_variable_misuse = "warn"
rust.must_not_suspend = "warn"
rust.pointer_structural_match = "warn"
rust.single_use_lifetimes = "warn"
rust.trivial_numeric_casts = "warn"
rust.unused_lifetimes = "warn"

View File

@ -3,12 +3,11 @@
// Imports
use {
futures::Future,
npath::NormPathExt,
pin_project::pin_project,
std::{
borrow::Cow,
io,
path::{self, Path},
path::{self, Path, PathBuf},
pin::Pin,
task,
time::{Duration, Instant},
@ -74,18 +73,63 @@ pub async fn try_measure_async<F: Future<Output = Result<T, E>>, T, E>(fut: F) -
pub fn normalize_path(path: &str) -> String {
let ends_with_sep = path.ends_with(path::MAIN_SEPARATOR_STR);
let mut path = Path::new(&path)
.normalized()
let mut path_cmpts = vec![];
for cmpt in Path::new(path).components() {
match cmpt {
// For "normal" components, just push them
path::Component::Prefix(_) | path::Component::RootDir | path::Component::Normal(_) => path_cmpts.push(cmpt),
// Ignore current directory components unless this is the very first one
path::Component::CurDir =>
if path_cmpts.is_empty() {
path_cmpts.push(path::Component::CurDir);
},
// For each parent directory component, pop the last component unless it's
// also a parent directory
path::Component::ParentDir => match path_cmpts.last() {
Some(path::Component::ParentDir) | None => path_cmpts.push(path::Component::ParentDir),
Some(_) => _ = path_cmpts.pop(),
},
}
}
let mut path = path_cmpts
.into_iter()
.collect::<PathBuf>()
.into_os_string()
.into_string()
.expect("utf-8 path was no longer utf-8 after normalizing");
// Note: `npath` doesn't keep `/` at the end, so we have to do it manually
match ends_with_sep {
true => {
path.push_str(path::MAIN_SEPARATOR_STR);
path
},
false => path,
// If the path is empty, add a `.` to symbolize the current directory
if path.is_empty() {
path.push('.');
}
// If we had a `/` at the end, add it back since `normalize` removes it
if ends_with_sep {
path.push_str(path::MAIN_SEPARATOR_STR);
}
path
}
#[cfg(test)]
mod tests {
#[test]
fn normalize_path() {
let tests = [
("a/", "a/"),
("a/../", "./"),
("a/../b", "b"),
("a/./b", "a/b"),
("a/./b/", "a/b/"),
("../b", "../b"),
("a/b/../../c", "c"),
];
for (orig, norm) in tests {
assert_eq!(super::normalize_path(orig), norm, "Case {orig:?} failed");
}
}
}