support for zend_extension
authorMichael Wallner <mike@php.net>
Tue, 24 Mar 2015 18:15:57 +0000 (19:15 +0100)
committerMichael Wallner <mike@php.net>
Tue, 24 Mar 2015 18:15:57 +0000 (19:15 +0100)
bin/pharext
src/pharext/ExecCmd.php
src/pharext/Installer.php
src/pharext/Packager.php
src/pharext/SourceDir/Pecl.php
src/pharext/Task/Activate.php

index dbde37d8ae89529d271f2a087833d8c9252d2def..ab09749d7e0a67da7726820110b5d8d721279faf 100755 (executable)
Binary files a/bin/pharext and b/bin/pharext differ
index 3ea63d00438f2887c8f69ce9c5ee1e3e008adf3f..84bb70882cd2fcb24351cdd47888679b30bd79be 100644 (file)
@@ -87,6 +87,7 @@ class ExecCmd
        /**
         * Run the command
         * @param array $args
+        * @return \pharext\ExecCmd self
         * @throws \pharext\Exception
         */
        public function run(array $args = null) {
@@ -110,8 +111,10 @@ class ExecCmd
                }
                
                if ($this->status) {
-                       throw new Exception("Command {$this->command} failed ({$this->status})");
+                       throw new Exception("Command {$exec} failed ({$this->status})");
                }
+
+               return $this;
        }
        
        /**
index 4b90c49a0ae65ea7a133730c17e48242007261ef..10486d2d69ceb0b9293c7abe1b1d8b3e982c2481 100644 (file)
@@ -38,6 +38,16 @@ class Installer implements Command
                                "sudo -S %s"],
                        ["i", "ini", "Activate in this php.ini instead of loaded default php.ini",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG],
+                       [null, "signature", "Dump package signature",
+                               CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
+                       [null, "license", "Show package license",
+                               CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
+                       [null, "name", "Show package name",
+                               CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
+                       [null, "release", "Show package release version",
+                               CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
+                       [null, "version", "Show pharext version",
+                               CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
                ]);
        }
        
@@ -93,6 +103,17 @@ class Installer implements Command
                        $this->help($prog);
                        exit;
                }
+               try {
+                       foreach (["signature", "name", "license", "release", "version"] as $opt) {
+                               if ($this->args[$opt]) {
+                                       printf("%s\n", $this->metadata($opt));
+                                       exit;
+                               }
+                       }
+               } catch (\Exception $e) {
+                       $this->error("%s\n", $e->getMessage());
+                       exit(2);
+               }
 
                foreach ($this->args->validate() as $error) {
                        $errs[] = $error;
@@ -177,16 +198,16 @@ class Installer implements Command
                }
 
                $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
-
+               $type = $this->metadata("type") ?: "php";
+               
                try {
                        $this->info("Running INI activation ...\n");
-                       $activate = new Task\Activate($temp, $files, $sudo);
+                       $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo);
                        if (!$activate->run($this->args->verbose)) {
                                $this->info("Extension already activated ...\n");
                        }
                } catch (\Exception $e) {
                        $this->error("%s\n", $e->getMessage());
-                       $this->error("%s\n", $output);
                        exit(3);
                }
        }
index ba7de89100a9200623db6b8d1912139802d59e2d..5194951dbad5cd3ec28debb5d18f387017af0ad0 100644 (file)
@@ -55,11 +55,13 @@ class Packager implements Command
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG],
                        ["S", "sign", "Sign the PHAR with a private key",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG],
-                       [null, "signature", "Dump signature",
+                       ["E", "zend", "Mark as Zend Extension",
+                               CliArgs::OPTIONAL|CliARgs::SINGLE|CliArgs::NOARG],
+                       [null, "signature", "Dump pharext signature",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
-                       [null, "license", "Show license",
+                       [null, "license", "Show pharext license",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
-                       [null, "version", "Show version",
+                       [null, "version", "Show pharext version",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT],
                ]);
        }
@@ -220,6 +222,7 @@ class Packager implements Command
                                "release" => $this->args->release,
                                "license" => @file_get_contents(current(glob($this->source->getBaseDir()."/LICENSE*"))),
                                "stub" => "pharext_installer.php",
+                               "type" => $this->args->zend ? "zend_extension" : "extension",
                        ]);
                        $file = (new Task\PharBuild($this->source, $meta))->run();
 
index 0b7055a99da64e0afb162490a18944bbeffd030c..9ca97264c480923817c1b5e1f808954888c8cf33 100644 (file)
@@ -57,6 +57,13 @@ class Pecl implements \IteratorAggregate, SourceDir
                                $cmd->warn("%s\n", $error);
                        }
                }
+               if (!isset($args->zend)) {
+                       if ($sxe->xpath("/pecl:package/pecl:zendextsrcrelease")) {
+                               foreach ($args->parse(1, ["--zend"]) as $error) {
+                                       $cmd->warn("%s\n", $error);
+                               }
+                       }
+               }
                
                $this->cmd = $cmd;
                $this->sxe = $sxe;
index 29341cc6f6986bfded151c7f34a73b7339b52b2b..1bbd9a86fc6200a00bd6ac8c2e7fcc542b4049ca 100644 (file)
@@ -22,6 +22,16 @@ class Activate implements Task
         */
        private $inis;
 
+       /**
+        * @var string
+        */
+       private $type;
+
+       /**
+        * @var string
+        */
+       private $php_config;
+       
        /**
         * @var string
         */
@@ -30,15 +40,24 @@ class Activate implements Task
        /**
         * @param string $cwd working directory
         * @param array $inis custom INI or list of loaded/scanned INI files
+        * @param string $type extension or zend_extension
+        * @param string $prefix install prefix, e.g. /usr/local
+        * @param string $common_name PHP programs common name, e.g. php5
         * @param string $sudo sudo command
         * @throws \pharext\Exception
         */
-       public function __construct($cwd, array $inis, $sudo = null) {
+       public function __construct($cwd, array $inis, $type = "extension", $prefix = null, $common_name = "php", $sudo = null) {
                $this->cwd = $cwd;
+               $this->type = $type;
                $this->sudo = $sudo;
                if (!$this->inis = $inis) {
                        throw new Exception("No PHP INIs given");
                }
+               $cmd = $common_name . "-config";
+               if (isset($prefix)) {
+                       $cmd = $prefix . "/bin/" . $cmd;
+               }
+               $this->php_config = $cmd;
        }
 
        /**
@@ -47,12 +66,17 @@ class Activate implements Task
         */
        public function run($verbose = false) {
                $extension = basename(current(glob("{$this->cwd}/modules/*.so")));
-               $pattern = preg_quote($extension);
+
+               if ($this->type === "zend_extension") {
+                       $pattern = preg_quote((new ExecCmd($this->php_config))->run(["--extension-dir"])->getOutput() . "/$extension", "/");
+               } else {
+                       $pattern = preg_quote($extension, "/");
+               }
 
                foreach ($this->inis as $file) {
                        $temp = new Tempfile("phpini");
                        foreach (file($file) as $line) {
-                               if (preg_match("/^\s*extension\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
+                               if (preg_match("/^\s*{$this->type}\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
                                        return false;
                                }
                                fwrite($temp->getStream(), $line);
@@ -60,7 +84,7 @@ class Activate implements Task
                }
 
                /* not found; append to last processed file, which is the main by default */
-               fprintf($temp->getStream(), "extension=%s\n", $extension);
+               fprintf($temp->getStream(), $this->type . "=%s\n", $extension);
                $temp->closeStream();
 
                $path = $temp->getPathname();