From 3a0c009003c16e65f1ad4c71ff2646477dd6e364 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Mon, 9 Sep 2024 03:10:28 -0400 Subject: [PATCH] Add `excludeGlobs` option to set exclude glob patterns for autopack (#12) --- crates/brioche-autopack/src/lib.rs | 13 ++++++++++++- crates/brioche-packer/src/autopack_template.rs | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/brioche-autopack/src/lib.rs b/crates/brioche-autopack/src/lib.rs index cac58f1..009e6c5 100644 --- a/crates/brioche-autopack/src/lib.rs +++ b/crates/brioche-autopack/src/lib.rs @@ -26,6 +26,7 @@ pub enum AutopackInputs { Globs { base_path: PathBuf, patterns: Vec, + exclude_patterns: Vec, }, } @@ -170,13 +171,21 @@ pub fn autopack(config: &AutopackConfig) -> eyre::Result<()> { AutopackInputs::Globs { base_path, patterns, + exclude_patterns, } => { let mut globs = globset::GlobSetBuilder::new(); for pattern in patterns { globs.add(globset::Glob::new(pattern)?); } + let mut exclude_globs = globset::GlobSetBuilder::new(); + for pattern in exclude_patterns { + exclude_globs.add(globset::Glob::new(pattern)?); + } + let globs = globs.build()?; + let exclude_globs = exclude_globs.build()?; + let walkdir = walkdir::WalkDir::new(base_path); for entry in walkdir { let entry = entry?; @@ -193,7 +202,9 @@ pub fn autopack(config: &AutopackConfig) -> eyre::Result<()> { ) })?; - if globs.is_match(&relative_entry_path) { + if globs.is_match(&relative_entry_path) + && !exclude_globs.is_match(&relative_entry_path) + { pending_paths.insert( entry.path().to_owned(), AutopackPathConfig { can_skip: false }, diff --git a/crates/brioche-packer/src/autopack_template.rs b/crates/brioche-packer/src/autopack_template.rs index ed6ae10..51b40de 100644 --- a/crates/brioche-packer/src/autopack_template.rs +++ b/crates/brioche-packer/src/autopack_template.rs @@ -28,6 +28,9 @@ pub struct AutopackConfigTemplate { #[serde(default)] globs: Vec, + #[serde(default)] + exclude_globs: Vec, + #[serde(default)] quiet: bool, @@ -55,6 +58,7 @@ impl AutopackConfigTemplate { let Self { paths, globs, + exclude_globs, quiet, link_dependencies, self_dependency, @@ -86,6 +90,10 @@ impl AutopackConfigTemplate { } let inputs = if globs.is_empty() { + eyre::ensure!( + exclude_globs.is_empty(), + "cannot exclude glob patterns with only paths" + ); let paths = paths .into_iter() .map(|path| recipe_path.join(path)) @@ -95,6 +103,7 @@ impl AutopackConfigTemplate { eyre::ensure!(paths.is_empty(), "cannot include both paths and globs"); brioche_autopack::AutopackInputs::Globs { patterns: globs, + exclude_patterns: exclude_globs, base_path: recipe_path.clone(), } };