upgrade to pharext v4
authorMichael Wallner <mike@php.net>
Wed, 20 May 2015 07:11:35 +0000 (09:11 +0200)
committerMichael Wallner <mike@php.net>
Wed, 20 May 2015 07:11:35 +0000 (09:11 +0200)
bin/extract [deleted file]
bin/fetch [deleted file]
bin/package [deleted file]
bin/pecl
composer.json
composer.lock

diff --git a/bin/extract b/bin/extract
deleted file mode 100755 (executable)
index 21a08b1..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/php
-<?php
-
-ini_set("display_errors", 0);
-ini_set("log_errors", 1);
-
-$procs = [];
-
-function check(&$procs) {
-       foreach ($procs as $dir => list($prc, $fds, $pkg)) {
-               $status = proc_get_status($prc);
-               if (!$status["running"]) {
-                       array_map("fclose", $fds);
-                       proc_close($prc);
-                       if (!$status["exitcode"]) {
-                               printf("%s\t%s\n", $pkg, $dir);
-                       }
-                       unset($procs[$dir]);
-               }
-       }
-       return count($procs);
-}
-
-while (!feof(STDIN)) {
-       if (strlen($line = rtrim(fgets(STDIN)))) {
-               if (list($pkg, $ver, $tgz) = explode("\t", $line)) {
-                       $dir = basename($tgz, ".tgz");
-                       $ext = sprintf("%s/../public/phars/%s/%s-%s.ext.phar", __DIR__, $pkg, $pkg, $ver);
-
-                       if (!is_file($ext)) {
-                               $prc = proc_open("tar -xf $tgz --transform='s#^package\\(2\\)\\{0,1\\}\\.xml$#$dir/package.xml#' 2>&1", [
-                                       ["pipe","r"],STDERR
-                               ], $fds, __DIR__."/../build");
-                               $procs[$dir] = [$prc, $fds, $pkg];
-                       }
-                       check($procs);
-               }
-       }
-}
-
-while (check($procs)) {
-       usleep(1000);
-}
diff --git a/bin/fetch b/bin/fetch
deleted file mode 100755 (executable)
index c55e785..0000000
--- a/bin/fetch
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/php
-<?php
-
-ini_set("display_errors", 0);
-ini_set("log_errors", 1);
-
-use http\Url;
-use http\Client;
-use http\Client\Request;
-
-$procs = [];
-$client = new Client;
-$client->setOptions([
-       "timetout" => 60,
-       "redirect" => 1,
-       "connecttimeout" => 6
-]);
-
-while (!feof(STDIN)) {
-   if (strlen($line = rtrim(fgets(STDIN)))) {
-        if (list($pkg, $ver, $url) = explode("\t", $line)) {
-                       $url = new Url($url, null, 0);
-                       $skp = sprintf("%s/../build/%s-%s.skip", __DIR__, $pkg, $ver);
-                       $tgz = sprintf("%s/../build/%s-%s.tgz", __DIR__, $pkg, $ver);
-                       $ext = sprintf("%s/../public/phars/%s/%s-%s.ext.phar", __DIR__, $pkg, $pkg, $ver);
-
-                       if (is_file($skp)) {
-                               // skip
-                       } elseif (is_file($tgz) || is_file($ext)) {
-                               printf("%s\t%s\t%s\n", $pkg, $ver, $tgz);
-                       } else {
-                               $client->enqueue(new Request("GET", $url), function($res) use($tgz, $pkg, $ver) {
-                                       $res->getBody()->toStream(fopen($tgz, "w"));
-                                       printf("%s\t%s\t%s\n", $pkg, $ver, $tgz);
-                                       return true;
-                               });
-                       }
-               }
-       }
-}
-
-while (count($client)) {
-       try {
-               $client->send();
-       } catch (Exception $e) {
-               error_log($e->getMessage());
-       }
-}
diff --git a/bin/package b/bin/package
deleted file mode 100755 (executable)
index ca90de2..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/php
-<?php
-
-ini_set("display_errors", 0);
-ini_set("log_errors", 1);
-
-$procs = [];
-
-function check(&$procs) {
-       foreach ($procs as $dir => list($prc, $fds, $pkg, $src, $dst)) {
-               $status = proc_get_status($prc);
-               if (!$status["running"]) {
-                       array_map("fclose", $fds);
-                       proc_close($prc);
-                       if ($status["exitcode"] || !is_file("$dst/$dir.ext.phar")) {
-                               touch("$src.skip");
-                       } else {
-                               printf("%s\t%s.ext.phar\n", $pkg, $dir);
-                       }
-                       system("rm -r $src.tgz $src");
-                       unset($procs[$dir]);
-               }
-       }
-       return count($procs);
-}
-
-while (!feof(STDIN)) {
-       if (strlen($line = rtrim(fgets(STDIN)))) {
-               if (list($pkg, $dir) = explode("\t", $line)) {
-                       $src = __DIR__."/../build/$dir";
-                       $dst = __DIR__."/../public/phars/$pkg";
-
-                       if (!is_dir($dst) && !mkdir($dst, 0777, true)) {
-                               continue;
-                       }
-
-                       $prc = proc_open(__DIR__."/../vendor/bin/pharext -qps $src -zZd $dst 2>&1", [
-                                       ["pipe","r"],STDERR
-                               ], $fds
-                       );
-                       $procs[$dir] = [$prc, $fds, $pkg, $src, $dst];
-                       check($procs);
-               }
-       }
-}
-
-while (check($procs)) {
-       usleep(1000);
-}
index d6d5e9e9f33564bbb2ac84c67dafc6b961a0628d..ef215add671c24c72e7486423bb10ff559f1c64e 100755 (executable)
--- a/bin/pecl
+++ b/bin/pecl
@@ -1,14 +1,81 @@
-#!/usr/bin/php
+#!/usr/bin/php -dphar.readonly=0
 <?php
 
 ini_set("display_errors", 0);
 ini_set("log_errors", 1);
 
 $what = !empty($argv[1]) ? $argv[1] : "latest";
+$pids = [];
+
+function fail($pkg, $ver, $skp, $fmt) {
+       $msg = call_user_func_array("sprintf", array_slice(func_get_args(), 3));
+       fprintf(STDERR, "FAILURE: %s-%s, %s; skipping next time\n", $pkg, $ver, $msg);
+       touch($skp);
+}
+
+function wait(&$pids) {
+       $status = null;
+       switch ($pid = pcntl_wait($status)) {
+               case -1:
+                       // meh
+                       break;
+               default:
+                       extract($pids[$pid]);
+                       unset($pids[$pid]);
+                       if (pcntl_wifexited($status) && ($rc = pcntl_wexitstatus($status))) {
+                               fail($pkg, $ver, $skp, "exit code: %d", $rc);
+                       } elseif (pcntl_wifsignaled($status) && ($rc = pcntl_wtermsig($status))) {
+                               fail($pkg, $ver, $skp, "signal: %d", $rc);
+                       } else {
+                               printf("SUCCESS: %s-%s\n", $pkg, $ver);
+                       }
+                       break;
+       }
+       return $pid > 0;
+};
+
+function work($url, $dir) {
+       is_dir($dir) || mkdir($dir, 0777, true);
+       require_once __DIR__."/../vendor/autoload.php";
+       $packager = new pharext\Packager;
+       $packager->run(5, [
+               $_SERVER["argv"][0], 
+               "-qps", 
+               $url, 
+               "-Zzd", 
+               $dir
+       ]);
+};
 
 if (($sxe = simplexml_load_file("http://pecl.php.net/feeds/$what.rss"))) {
        foreach ($sxe->item as $item) {
                $url = (string) $item->link;
-               printf("%s\t%s\t%s\n", basename(dirname($url)), basename($url), $url);
+               $pkg = basename(dirname($url));
+               $ver = basename($url);
+               $skp = sprintf("%s/../build/%s-%s.skip", __DIR__, $pkg, $ver);
+               $ext = sprintf("%s/../public/phars/%s/%s-%s.ext.phar", __DIR__, $pkg, $pkg, $ver);
+               $dir = dirname($ext);
+
+               if (!is_file($skp) && !is_file($ext)) {
+                       switch ($pid = pcntl_fork()) {
+                               case -1:
+                                       exit;
+                               case 0:
+                                       work($url, $dir);
+                                       exit;
+                               default:
+                                       $pids[$pid] = compact("url", "pkg", "ver", "skp", "ext", "dir");
+                                       break;
+                       }
+               }
+               
+               if (count($pids) > 5) {
+                       wait($pids);
+               }
        }
+       while (wait($pids))
+               ;
+       
 }
+
+
index 3c234877b572ab4575293bd7d32853e5b2e35c67..334a10517e32988234fb2c9b3b071ede7f12e499 100644 (file)
@@ -1,6 +1,11 @@
 {
     "require": {
-        "m6w6/pharext": "~3.0",
+        "m6w6/pharext": "^4.0",
         "concisecss/concise.css": "~2.1"
-    }
+    },
+       "autoload": {
+               "psr-0": {
+                       "pharext": "vendor/m6w6/pharext/src"
+               }
+       }
 }
index ea9e938d1e8c663e6beebfb69e8cbb52acce471e..5a09ce9d104105eb2918257008785b3dc1fcc954 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "d612932710d4d8912e7fdabc8f15eefc",
+    "hash": "6536f75724f1b6738b441c05cd7d65e5",
     "packages": [
         {
             "name": "concisecss/concise.css",
         },
         {
             "name": "m6w6/pharext",
-            "version": "v3.0.1",
+            "version": "v4.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/m6w6/pharext.git",
-                "reference": "3dcc326aa922ce4b70d07049572c6f15a744869c"
+                "reference": "d017df1dcb270773804bbed4628397a9c7df30c4"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/m6w6/pharext/zipball/3dcc326aa922ce4b70d07049572c6f15a744869c",
-                "reference": "3dcc326aa922ce4b70d07049572c6f15a744869c",
+                "url": "https://api.github.com/repos/m6w6/pharext/zipball/d017df1dcb270773804bbed4628397a9c7df30c4",
+                "reference": "d017df1dcb270773804bbed4628397a9c7df30c4",
                 "shasum": ""
             },
             "bin": [
@@ -80,7 +80,7 @@
                 "package",
                 "phar"
             ],
-            "time": "2015-04-08 10:17:40"
+            "time": "2015-05-20 06:39:24"
         }
     ],
     "packages-dev": [],