Now supports excluding files and dirs

This commit is contained in:
2017-01-10 16:02:09 +01:00
parent 41ad908bc6
commit be93645db9
2 changed files with 35 additions and 4 deletions

View File

@ -23,6 +23,8 @@ class Manifest
protected $verbatim = false;
/** @var array Properties to be defined in the main stub */
protected $props = [];
/** @var array Patterns to exclude */
protected $excludes = [];
/**
* Read manifests from a makephar.sdl file and return all the build targets
@ -74,6 +76,18 @@ class Manifest
break;
}
break;
case 'exclude':
foreach ($child->getChildren() as $inc) switch ($inc->getTagName()) {
case 'dir':
$val = (string)$inc->getValue();
$mf->excludes[] = "*/{$val}/*";
break;
case 'file':
$val = (string)$inc->getValue();
$mf->excludes[] = "*/{$val}";
break;
}
break;
case 'props':
$props = [];
if ($src = (string)$child->getValue()) {
@ -199,10 +213,18 @@ class Manifest
log_warn("Unsupported source type: %s", $source->type);
}
}
$items = array_filter($items, function ($item) {
if (fnmatch("*/.git/*", $item->src)) return false;
$rules = $this->excludes;
$before = count($items);
$items = array_filter($items, function ($item) use ($rules) {
foreach ($rules as $rule) {
if (fnmatch($rule, $item->src)) return false;
}
return true;
});
$after = count($items);
if ($after < $before) {
log_debug("Skipped %d files matching exclusion patterns", $before-$after);
}
return $items;
}