X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FPackager.php;h=cd3b4d660fdd62e70bec8e3459946a41c684b34f;hb=c61404bba9e446429740a134deb5cf8f29f1e0f3;hp=9acb5ebc848a229c62a7d0e7c74eec63bcbf13cc;hpb=8bb44cb1907aff0691bf0b40443ef81d2251c29f;p=pharext%2Fpharext diff --git a/src/pharext/Packager.php b/src/pharext/Packager.php index 9acb5eb..cd3b4d6 100644 --- a/src/pharext/Packager.php +++ b/src/pharext/Packager.php @@ -45,6 +45,8 @@ class Packager implements Command CliArgs::REQUIRED|CliArgs::SINGLE|CliArgs::REQARG], ["g", "git", "Use `git ls-tree` to determine file list", CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG], + ["b", "branch", "Checkout this tag/branch", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG], ["p", "pecl", "Use PECL package.xml to determine file list, name and release", CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG], ["d", "dest", "Destination directory", @@ -141,18 +143,23 @@ class Packager implements Command * @return string local source */ private function download($source) { - $this->info("Fetching remote source %s ...\n", $source); - if ($this->args->git) { - $task = new Task\GitClone($source); + $task = new Task\GitClone($source, $this->args->branch); } else { - $task = new Task\StreamFetch($source, function($bytes_pct) { - $this->info(" %3d%% [%s>%s] \r%s", - floor($bytes_pct*100), - str_repeat("=", round(50*$bytes_pct)), - str_repeat(" ", round(50*(1-$bytes_pct))), - $bytes_pct == 1 ? "\n":"" - ); + /* print newline only once */ + $done = false; + $task = new Task\StreamFetch($source, function($bytes_pct) use(&$done) { + if (!$done) { + $this->info(" %3d%% [%s>%s] \r", + floor($bytes_pct*100), + str_repeat("=", round(50*$bytes_pct)), + str_repeat(" ", round(50*(1-$bytes_pct))) + ); + if ($bytes_pct == 1) { + $done = true; + printf("\n"); + } + } }); } $local = $task->run($this->verbosity()); @@ -167,10 +174,15 @@ class Packager implements Command * @return string extracted directory */ private function extract($source) { - $this->debug("Extracting %s ...\n", $source); - - $task = new Task\Extract($source); - $dest = $task->run($this->verbosity()); + try { + $task = new Task\Extract($source); + $dest = $task->run($this->verbosity()); + } catch (\Exception $e) { + if (false === strpos($e->getMessage(), "checksum mismatch")) { + throw $e; + } + $dest = (new Task\PaxFixup($source))->run($this->verbosity()); + } $this->cleanup[] = new Task\Cleanup($dest); return $dest; @@ -182,7 +194,7 @@ class Packager implements Command * @return string local source directory */ private function localize($source) { - if (!stream_is_local($source)) { + if (!stream_is_local($source) || ($this->args->git && isset($this->args->branch))) { $source = $this->download($source); $this->cleanup[] = new Task\Cleanup($source); } @@ -191,8 +203,7 @@ class Packager implements Command $source = $this->extract($source); $this->cleanup[] = new Task\Cleanup($source); - if ($this->args->pecl) { - $this->debug("Sanitizing PECL dir ...\n"); + if (!$this->args->git) { $source = (new Task\PeclFixup($source))->run($this->verbosity()); } } @@ -211,8 +222,10 @@ class Packager implements Command $this->source = new SourceDir\Pecl($source); } elseif ($this->args["git"]) { $this->source = new SourceDir\Git($source); - } elseif (is_file("$source/parext_package.php")) { + } elseif (is_file("$source/pharext_package.php")) { $this->source = include "$source/pharext_package.php"; + } else { + $this->source = new SourceDir\Basic($source); } if (!$this->source instanceof SourceDir) { @@ -230,11 +243,16 @@ class Packager implements Command */ private function createPackage() { try { - $meta = array_merge($this->metadata(), [ - "date" => date("Y-m-d"), + if (($glob = glob($this->source->getBaseDir()."/LICENSE*"))) { + $license = file_get_contents(current($glob)); + } else { + $this->warn("Could not find any LICENSE.* files!\n"); + $license = "UNKNOWN\n"; + } + $meta = array_merge(Metadata::all(), [ "name" => $this->args->name, "release" => $this->args->release, - "license" => @file_get_contents(current(glob($this->source->getBaseDir()."/LICENSE*"))), + "license" => $license, "stub" => "pharext_installer.php", "type" => $this->args->zend ? "zend_extension" : "extension", ]);