Colored output for TTYs, props added

This commit is contained in:
2017-01-10 15:13:49 +01:00
parent 631e86aa6f
commit bf12eb7b50
6 changed files with 182 additions and 19 deletions

View File

@ -19,6 +19,10 @@ class Manifest
protected $stub = null;
/** @var bool If true, the archive will be compressed */
protected $compress = false;
/** @var bool If true, the files will be added without minification */
protected $verbatim = false;
/** @var array Properties to be defined in the main stub */
protected $props = [];
/**
* Read manifests from a makephar.sdl file and return all the build targets
@ -51,10 +55,13 @@ class Manifest
foreach ($tag->getChildren() as $child) switch ($child->getTagName()) {
case 'library':
$mf->setIsLibrary($child->getValue());
$mf->setIsLibrary($child->getValue()?:true);
break;
case 'compress':
$mf->setCompression($child->getValue());
$mf->setCompression($child->getValue()?:true);
break;
case 'verbatim':
$mf->setVerbatim($child->getValue()?:true);
break;
case 'stub':
$mf->setStubFile($child->getValue());
@ -67,6 +74,38 @@ class Manifest
break;
}
break;
case 'props':
if ($src = (string)$child->getValue()) {
if (!file_exists($src)) {
log_warn("Property file %s not found", $src);
continue;
}
log_info("Reading props from file %s", $src);
$props = file($src, FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES);
} elseif ($script = (string)$child->getAttribute('exec')) {
log_info("Generating props using %s", $script);
if (fnmatch("*.php",$script)) $script = "php {$script}";
exec($script, $props, $ret);
if ($ret>0) {
log_warn("Script exited with code %d", $ret);
continue;
}
} else {
log_warn("Props specified without either script or src. Properties will not be added.");
continue;
}
foreach ($props as $prop) {
$prop = trim($prop);
// skip comments and empty lines
if ($prop && $prop[0]=='#') continue;
if (strpos($prop,'=')===false) continue;
// extract key/value
list ($k,$v) = explode("=",$prop,2);
log_debug(" prop[%s] = %s", strtoupper($k),$v);
$mf->props[strtoupper($k)] = $v;
}
break;
}
return $mf;
@ -117,6 +156,17 @@ class Manifest
return $this->compress;
}
public function setVerbatim($value)
{
$this->verbatim = $value;
return $this;
}
public function getVerbatim()
{
return $this->verbatim;
}
public function addSource($type, $path, array $opts)
{
$this->sources[] = (object)[
@ -151,4 +201,9 @@ class Manifest
return $items;
}
public function getProps()
{
return (array)$this->props;
}
}