mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-08 21:17:59 +00:00
Add "ignore_patterns" option to config
This allows explicitly ignoring changes to certain files or directories, even if the changed file ends up matching `watch_patterns`. The default value, `build/**/*` will ensure that changes in the build directory will not trigger a duplicate rebuild. Resolves #143 Resolves #215
This commit is contained in:
@@ -29,6 +29,7 @@ pub fn create_watcher(
|
||||
modified: Arc<AtomicBool>,
|
||||
project_dir: &Path,
|
||||
patterns: GlobSet,
|
||||
ignore_patterns: GlobSet,
|
||||
waker: Waker,
|
||||
) -> notify::Result<Watcher> {
|
||||
let base_dir = fs::canonicalize(project_dir)?;
|
||||
@@ -54,8 +55,8 @@ pub fn create_watcher(
|
||||
let Ok(path) = path.strip_prefix(&base_dir_clone) else {
|
||||
continue;
|
||||
};
|
||||
if patterns.is_match(path) {
|
||||
// log::info!("File modified: {}", path.display());
|
||||
if patterns.is_match(path) && !ignore_patterns.is_match(path) {
|
||||
log::info!("File modified: {}", path.display());
|
||||
any_match = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ pub struct ProjectConfig {
|
||||
pub build_target: Option<bool>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub watch_patterns: Option<Vec<String>>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub ignore_patterns: Option<Vec<String>>,
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(alias = "objects", skip_serializing_if = "Option::is_none")
|
||||
@@ -66,7 +68,18 @@ impl ProjectConfig {
|
||||
.map(|s| Glob::new(s))
|
||||
.collect::<Result<Vec<Glob>, globset::Error>>()?
|
||||
} else {
|
||||
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||
default_watch_patterns()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_ignore_patterns(&self) -> Result<Vec<Glob>, globset::Error> {
|
||||
Ok(if let Some(ignore_patterns) = &self.ignore_patterns {
|
||||
ignore_patterns
|
||||
.iter()
|
||||
.map(|s| Glob::new(s))
|
||||
.collect::<Result<Vec<Glob>, globset::Error>>()?
|
||||
} else {
|
||||
default_ignore_patterns()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -195,10 +208,16 @@ pub const DEFAULT_WATCH_PATTERNS: &[&str] = &[
|
||||
"*.inc", "*.py", "*.yml", "*.txt", "*.json",
|
||||
];
|
||||
|
||||
pub const DEFAULT_IGNORE_PATTERNS: &[&str] = &["build/**/*"];
|
||||
|
||||
pub fn default_watch_patterns() -> Vec<Glob> {
|
||||
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||
}
|
||||
|
||||
pub fn default_ignore_patterns() -> Vec<Glob> {
|
||||
DEFAULT_IGNORE_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct ProjectConfigInfo {
|
||||
|
||||
Reference in New Issue
Block a user