Skip to content

Commit

Permalink
Add excludeGlobs option to set exclude glob patterns for autopack (#12
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kylewlacy authored Sep 9, 2024
1 parent 6fdab2a commit 3a0c009
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/brioche-autopack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum AutopackInputs {
Globs {
base_path: PathBuf,
patterns: Vec<String>,
exclude_patterns: Vec<String>,
},
}

Expand Down Expand Up @@ -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?;
Expand All @@ -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 },
Expand Down
9 changes: 9 additions & 0 deletions crates/brioche-packer/src/autopack_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct AutopackConfigTemplate {
#[serde(default)]
globs: Vec<String>,

#[serde(default)]
exclude_globs: Vec<String>,

#[serde(default)]
quiet: bool,

Expand Down Expand Up @@ -55,6 +58,7 @@ impl AutopackConfigTemplate {
let Self {
paths,
globs,
exclude_globs,
quiet,
link_dependencies,
self_dependency,
Expand Down Expand Up @@ -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))
Expand All @@ -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(),
}
};
Expand Down

0 comments on commit 3a0c009

Please sign in to comment.