summary |
shortlog |
log |
commit | commitdiff |
tree |
github
raw |
patch |
inline | side by side (from parent 1:
0813c3a)
==Packager hook
If not --pecl nor --git are explicitely given, look for a
pharext_install.php in --source. This script will be exectuted by the
Packager. It must return a callable with the following signature:
function(Packager $pkg, $path) : function(Packager $pkg, $path);
So, the callback should return another callable.
The primary callback is meant to set things like --name and --release,
so you don't have to on the command line; build automation FTW.
The secondary callback is meant to create the file iterator of the
source dir, but if you're in a git clone, you might easily just return a
new pharext\GitSourceDir and be done.
==Installer hook
The packager will look for a pharext_install.php file within the root of
the source dir. This script will be executed by the Installer; it must
return a callable with the following signature:
function(Installer $installer) : function(Installer $installer);
So, again, the callback should return another callable.
The primary callback is meant to add your own command line arguments to
the CliArgs parser, and the secnodary callback is meant to proccess
those args.
For --pecl source dirs a pharext_install.php script is automatically
generated from the package.xml.
==Examples for pecl_http
pharext_package.php
---8<---
<?php
namespace pharext;
return function(Packager $packager, $path) {
$args = $packager->getArgs();
$args->name = "pecl_http";
$args->release = current(preg_filter("/^.*PHP_PECL_HTTP_VERSION\s+\"(.*)\".*$/s", "\$1", file("../http.git/php_http.h")));
return function (Packager $packager, $path) {
return new GitSourceDir($packager, $path);
};
};
?>
--->8---
pharext_install.php
---8<---
<?php
namespace pharext;
return function(Installer $installer) {
$installer->getArgs()->compile([
[null, "with-http-zlib-dir", "Where to find zlib",
CliArgs::OPTARG],
[null, "with-http-libcurl-dir", "Where to find libcurl",
CliArgs::OPTARG],
[null, "with-http-libevent-dir", "Where to find libev{,ent{,2}}",
CliArgs::OPTARG],
[null, "with-http-libidn-dir", "Where to find libidn",
CliArgs::OPTARG],
]);
return function(Installer $installer) {
$opts = [
"with-http-zlib-dir",
"with-http-libcurl-dir",
"with-http-libevent-dir",
"with-http-libidn-dir",
];
$args = $installer->getArgs();
foreach ($opts as $opt) {
if (isset($args[$opt])) {
$args->configure = "--$opt=".$args[$opt];
}
}
};
};
?>
--->8---
bin/pharext: src/* src/pharext/*
@echo "Linting changed source files ... "
@for file in $?; do php -l $$file | sed -ne '/^No syntax errors/!p' && exit $${PIPESTATUS[0]}; done
bin/pharext: src/* src/pharext/*
@echo "Linting changed source files ... "
@for file in $?; do php -l $$file | sed -ne '/^No syntax errors/!p' && exit $${PIPESTATUS[0]}; done
- @echo "Running tests ... "
- @phpunit tests
@echo "Creating bin/pharext ... "
php -d phar.readonly=0 build/create-phar.php
chmod +x $@
@echo "Creating bin/pharext ... "
php -d phar.readonly=0 build/create-phar.php
chmod +x $@
* Original option spec
* @var array
*/
* Original option spec
* @var array
*/
* @return pharext\CliArgs self
*/
public function compile(array $spec = null) {
* @return pharext\CliArgs self
*/
public function compile(array $spec = null) {
- $this->orig = $spec;
- $this->spec = [];
+ $this->orig = array_merge($this->orig, $spec);
foreach ((array) $spec as $arg) {
foreach ((array) $spec as $arg) {
- $this->spec["-".$arg[0]] = $arg;
+ if (isset($arg[0])) {
+ $this->spec["-".$arg[0]] = $arg;
+ }
$this->spec["--".$arg[1]] = $arg;
}
return $this;
$this->spec["--".$arg[1]] = $arg;
}
return $this;
return $this->offsetGet($o);
}
function offsetSet($o, $v) {
return $this->offsetGet($o);
}
function offsetSet($o, $v) {
+ $osn = $this->optShortName($o);
+ $oln = $this->optLongName($o);
if ($this->optIsMulti($o)) {
if ($this->optIsMulti($o)) {
- $this->args["-".$this->optShortName($o)][] = $v;
- $this->args["--".$this->optLongName($o)][] = $v;
+ if (isset($osn)) {
+ $this->args["-$osn"][] = $v;
+ }
+ $this->args["--$oln"][] = $v;
- $this->args["-".$this->optShortName($o)] = $v;
- $this->args["--".$this->optLongName($o)] = $v;
+ if (isset($osn)) {
+ $this->args["-$osn"] = $v;
+ }
+ $this->args["--$oln"] = $v;
}
}
function __set($o, $v) {
}
}
function __set($o, $v) {
* Output pharext vX.Y.Z header
*/
function header() {
* Output pharext vX.Y.Z header
*/
function header() {
- printf("pharext v%s (c) Michael Wallner <mike@php.net>\n", VERSION);
+ printf("pharext v%s (c) Michael Wallner <mike@php.net>\n\n", VERSION);
* @param string $prog
*/
public function help($prog) {
* @param string $prog
*/
public function help($prog) {
- printf("\nUsage:\n\n \$ %s", $prog);
+ printf("Usage:\n\n \$ %s", $prog);
$flags = [];
$required = [];
$flags = [];
$required = [];
printf(" [-%s <arg>]", implode("|-", array_column($optional, 0)));
}
printf("\n\n");
printf(" [-%s <arg>]", implode("|-", array_column($optional, 0)));
}
printf("\n\n");
- foreach ($this->args->getSpec() as $spec) {
- printf(" -%s|--%s %s", $spec[0], $spec[1], ($spec[3] & CliArgs::REQARG) ? "<arg> " : (($spec[3] & CliArgs::OPTARG) ? "[<arg>]" : " "));
- printf("%s%s%s", str_repeat(" ", 16-strlen($spec[1])), $spec[2], ($spec[3] & CliArgs::REQUIRED) ? " (REQUIRED)" : "");
+ $spc = $this->args->getSpec();
+ $max = max(array_map("strlen", array_column($spc, 1)));
+ $max += $max % 8 + 2;
+ foreach ($spc as $spec) {
+ if (isset($spec[0])) {
+ printf(" -%s|", $spec[0]);
+ } else {
+ printf(" ");
+ }
+ printf("--%s ", $spec[1]);
+ if ($spec[3] & CliArgs::REQARG) {
+ printf("<arg> ");
+ } elseif ($spec[3] & CliArgs::OPTARG) {
+ printf("[<arg>]");
+ } else {
+ printf(" ");
+ }
+ printf("%s%s", str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0])), $spec[2]);
+ if ($spec[3] & CliArgs::REQUIRED) {
+ printf(" (REQUIRED)");
+ }
if (isset($spec[4])) {
printf(" [%s]", $spec[4]);
}
if (isset($spec[4])) {
printf(" [%s]", $spec[4]);
}
* @see \pharext\Command::run()
*/
public function run($argc, array $argv) {
* @see \pharext\Command::run()
*/
public function run($argc, array $argv) {
+ if (($hook = stream_resolve_include_path("pharext_install.php"))) {
+ $callable = include $hook;
+ if (is_callable($callable)) {
+ $recv = $callable($this);
+ }
+ }
+
$errs = [];
$prog = array_shift($argv);
foreach ($this->args->parse(--$argc, $argv) as $error) {
$errs = [];
$prog = array_shift($argv);
foreach ($this->args->parse(--$argc, $argv) as $error) {
+ if (isset($recv)) {
+ $recv($this);
+ }
+
$this->installPackage();
}
$this->installPackage();
}
$this->source = new PeclSourceDir($this, $this->args["source"]);
} elseif ($this->args["git"]) {
$this->source = new GitSourceDir($this, $this->args["source"]);
$this->source = new PeclSourceDir($this, $this->args["source"]);
} elseif ($this->args["git"]) {
$this->source = new GitSourceDir($this, $this->args["source"]);
+ } elseif (realpath($this->args["source"]."/pharext_package.php")) {
+ $this->source = new PharextSourceDir($this, $this->args["source"]);
} else {
$this->source = new FilteredSourceDir($this, $this->args["source"]);
}
} else {
$this->source = new FilteredSourceDir($this, $this->args["source"]);
}
+ /**
+ * Installer hook
+ * @var string
+ */
+ private $hook;
+
/**
* @inheritdoc
* @see \pharext\SourceDir::__construct()
/**
* @inheritdoc
* @see \pharext\SourceDir::__construct()
+ if (($configure = $sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption"))) {
+ $this->hook = tmpfile();
+ ob_start(function($s) {
+ fwrite($this->hook, $s);
+ return null;
+ });
+ call_user_func(function() use ($configure) {
+ include __DIR__."/../pharext_install.tpl.php";
+ });
+ ob_end_flush();
+ }
+
$this->cmd = $cmd;
$this->sxe = $sxe;
$this->path = $path;
$this->cmd = $cmd;
$this->sxe = $sxe;
$this->path = $path;
* @return Generator
*/
private function generateFiles() {
* @return Generator
*/
private function generateFiles() {
+ if ($this->hook) {
+ rewind($this->hook);
+ yield "pharext_install.php" => $this->hook;
+ }
foreach ($this->sxe->xpath("//pecl:file") as $file) {
$path = $this->path ."/". $this->dirOf($file) ."/". $file["name"];
if ($this->cmd->getArgs()->verbose) {
foreach ($this->sxe->xpath("//pecl:file") as $file) {
$path = $this->path ."/". $this->dirOf($file) ."/". $file["name"];
if ($this->cmd->getArgs()->verbose) {
--- /dev/null
+<?php
+
+namespace pharext;
+
+class PharextSourceDir implements \IteratorAggregate, SourceDir
+{
+ private $cmd;
+ private $path;
+ private $iter;
+
+ public function __construct(Command $cmd, $path) {
+ $this->cmd = $cmd;
+ $this->path = $path;
+
+ $callable = include "$path/pharext_package.php";
+ if (!is_callable($callable)) {
+ throw new \Exception("Package hook did not return a callable");
+ }
+ $this->iter = $callable($cmd, $path);
+ }
+
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ public function getIterator() {
+ if (!is_callable($this->iter)) {
+ throw new \Exception("Package hook callback did not return a callable");
+ }
+ return call_user_func($this->iter, $this->cmd, $this->path);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?='<?php'?>
+
+/**
+ * Generated by pharext v<?=pharext\VERSION?> at <?=date("Y-m-d H:i:i T")?>.
+ */
+namespace pharext;
+
+return function(Installer $installer) {
+ $args = $installer->getArgs();
+ <?php foreach ($configure as $cfg) : ?>
+
+ $args->compile([[
+ null,
+ "<?=$cfg["name"]?>",
+ "<?=ucfirst($cfg["prompt"])?>",
+ CliArgs::OPTARG,
+ <?php if (strlen($cfg["default"])) : ?>
+ "<?=$cfg["default"]?>"
+ <?php else : ?>
+ NULL
+ <?php endif; ?>
+
+ ]]);
+ <?php endforeach; ?>
+
+ return function(Installer $installer) {
+ $args = $installer->getArgs();
+ <?php foreach ($configure as $cfg) : ?>
+
+ if (isset($args["<?=$cfg["name"]?>"])) {
+ $args->configure = "--<?=$cfg["name"]?>=".$args["<?=$cfg["name"]?>"];
+ }
+ <?php endforeach; ?>
+
+ };
+};
public function testHelp() {
$this->expectOutputString(<<<EOF
public function testHelp() {
$this->expectOutputString(<<<EOF
Usage:
$ testprog [-hvqs] [-p|-n|-c <arg>]
Usage:
$ testprog [-hvqs] [-p|-n|-c <arg>]