Skip to content
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
4 changes: 2 additions & 2 deletions packages/copper-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pistonite-cu-proc-macros"
version = "0.2.8"
version = "0.2.9"
edition = "2024"
description = "Proc-macros for Cu"
repository = "https://github.com/Pistonite/cu"
Expand All @@ -12,7 +12,7 @@ exclude = [

[dependencies.pm]
package = "pistonite-pm"
version = "0.2.6"
version = "0.2.7"
path = "../promethium"
features = ["full"]

Expand Down
21 changes: 10 additions & 11 deletions packages/copper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pistonite-cu"
version = "0.8.4"
version = "0.9.0"
edition = "2024"
description = "Battery-included common utils to speed up development of rust tools"
repository = "https://github.com/Pistonite/cu"
Expand All @@ -11,19 +11,19 @@ exclude = [
]

[dependencies]
pistonite-cu-proc-macros = { version = "0.2.8", path = "../copper-proc-macros" }
pistonite-cu-proc-macros = { version = "0.2.9", path = "../copper-proc-macros" }

# --- Always enabled ---
anyhow = "1.0.102"
log = "0.4.30"
anyhow = "1.0.103"
log = "0.4.33"

# --- Command Line Interface ---
oneshot = { version = "0.2.1", optional = true, features = ["std"] }
env_filter = { version = "1.0.1", optional = true }
env_filter = { version = "2.0.0", optional = true }
terminal_size = { version = "0.4.4", optional = true }
unicode-width = { version = "0.2.2", features = ["cjk"], optional = true }
clap = { version = "4.6.1", features = ["derive"], optional = true }
regex = { version = "1.12.3", optional = true }
regex = { version = "1.13.0", optional = true }
ctrlc = { version = "3.5.2", optional = true }

# --- Coroutine ---
Expand All @@ -34,11 +34,11 @@ tokio = { version = "1.52.3", optional = true, features = [

# --- File System ---
dunce = {version="1.0.5", optional = true}
which = {version = "8.0.2", optional = true }
which = {version = "8.0.4", optional = true }
pathdiff = {version = "0.2.3", optional=true}
filetime = { version = "0.2.29", optional = true}
glob = { version = "0.3.3", optional = true }
spin = {version = "0.12.0", optional = true} # for PIO
ignore = { version = "0.4.28", optional = true }
spin = {version = "0.12.1", optional = true} # for PIO

# serde
serde = { version = "1.0.228", features = ["derive"], optional = true }
Expand Down Expand Up @@ -95,8 +95,7 @@ process = [ # enable spawning child processes
"tokio/process",
]
fs = [ # enable file system and path util
"dep:which", "dep:pathdiff", "dep:dunce", "dep:filetime", "dep:glob",
"tokio?/fs"
"dep:which", "dep:pathdiff", "dep:dunce", "dep:filetime", "tokio?/fs", "dep:ignore",
]

# Enable parsing utils
Expand Down
18 changes: 10 additions & 8 deletions packages/copper/examples/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ use pistonite_cu as cu;

#[cu::cli]
fn main(_: cu::cli::Flags) -> cu::Result<()> {
let mut src = cu::fs::walk("src")?;
let src = cu::fs::walk("src")?;
cu::cli::set_thread_name("walk");
while let Some(entry) = src.next() {
for entry in src {
let entry = entry?;
cu::info!(
"{} {} {}",
entry.depth,
"{} {} {:?}",
entry.depth(),
entry.path().display(),
entry.rel_path().display(),
entry.rel_path()?
)
}

cu::cli::set_thread_name("glob");
let glob = cu::fs::glob_from("..", "./**/*.rs")?;
for entry in glob {
let mut glob = cu::fs::walker("..");
glob.glob_includes(["**/*.rs"])?;

for entry in glob.walk()? {
let entry = entry?;
cu::info!("{}", entry.display());
cu::info!("{entry:?}");
}

Ok(())
Expand Down
9 changes: 8 additions & 1 deletion packages/copper/src/cli/print_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ pub trait LogConfig {
pub struct DefaultLogConfig;
impl LogConfig for DefaultLogConfig {
fn process(&self, record: &lv::LogRecord) -> (lv::Lv, bool) {
// downgrade logs from dependencies to trace
if let Some(m) = record.module_path() {
if m.starts_with("ignore") {
return (lv::T, true);
}
}

let level: lv::Lv = record.level().into();
(record.level().into(), level == lv::T)
(level, level == lv::T)
}
}
40 changes: 28 additions & 12 deletions packages/copper/src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,40 @@ fn rec_copy_inefficiently_impl(from: &Path, to: &Path) -> crate::Result<()> {

// cache paths that are known to be directories in `to`
let mut dir_cache = BTreeSet::new();
let mut walk = crate::fs::walk(from)?;
while let Some(entry) = walk.next() {
let mut walker = crate::fs::walker(from);
walker.include_dir_entries(true);
for entry in walker.walk()? {
let entry = entry?;
let rel_path = cu::check!(entry.rel_path()?, "failed to get relative path for entry")?;
if !entry.is_dir() {
let Some(file_name) = entry.file_name() else {
cu::trace!(
"skipping file with no file name: '{}'",
entry.path().display()
);
continue;
};
let containing = if entry.depth() > 1 {
let parent = cu::check!(
rel_path.parent(),
"failed to get relative path of containing directory for entry"
)?;
to.join(parent)
} else {
to.to_path_buf()
};
let target = containing.join(file_name);
// ensure parent directories exists
if !dir_cache.contains(entry.rel_containing) {
let dir_path = to.join(entry.rel_containing);
make_dir_impl(&dir_path)?;
dir_cache.insert(dir_path);
if !dir_cache.contains(&containing) {
make_dir_impl(&containing)?;
dir_cache.insert(containing);
}
// copy the file
crate::fs::copy(
entry.path(),
to.join(entry.rel_containing).join(&entry.file_name),
)?;
crate::fs::copy(entry.path(), target)?;
} else {
let dir_path = to.join(entry.rel_containing);
make_dir_impl(&dir_path)?;
let target_path = to.join(rel_path);
make_dir_impl(&target_path)?;
dir_cache.insert(target_path);
}
}

Expand Down
62 changes: 0 additions & 62 deletions packages/copper/src/fs/glob.rs

This file was deleted.

6 changes: 2 additions & 4 deletions packages/copper/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ mod read;
pub use read::*;
mod write;
pub use write::*;
mod walk;
pub use walk::*;
mod glob;
pub use glob::*;
mod walk2;
pub use walk2::*;
pub mod bin;

pub use filetime::FileTime as Time;
Loading