Example #1
0
 protected function buildOptions(Package $package, InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelperSet()->get('question');
     $force_opts = $input->getOption('with-configure-options');
     if ($force_opts) {
         if (!file_exists($force_opts) || !is_file($force_opts) || !is_readable($force_opts)) {
             throw new \Exception("File '{$force_opts}' is unusable");
         }
         $force_opts = preg_replace(",\\s+,", ' ', file_get_contents($force_opts));
         return [null, $force_opts];
     }
     $options = $package->getConfigureOptions();
     $optionsValue = [];
     foreach ($options as $name => $opt) {
         /* enable/with-<extname> */
         if ($name == $package->getName() || str_replace('-', '_', $name) == $package->getName()) {
             $optionsValue[$name] = (object) ['type' => $opt->type, 'input' => true];
             continue;
         }
         if ($input->getOption('defaults')) {
             $value = $opt->default;
         } else {
             if ($opt->type == 'enable') {
                 $prompt = new ConfirmationQuestion($opt->prompt . ' (default: ' . ($opt->default ? 'yes' : 'no') . '): ', $opt->default);
             } else {
                 $prompt = new Question($opt->prompt . ' (default: ' . ($opt->default ? $opt->default : '') . '): ', $opt->default);
             }
             $value = $helper->ask($input, $output, $prompt);
         }
         $optionsValue[$name] = (object) ['type' => $opt->type, 'input' => $value];
     }
     return [$optionsValue, null];
 }
Example #2
0
 /**
  * @param \Pickle\Base\Interfaces\Package $package
  *
  * @return array
  */
 public function dump(Interfaces\Package $package)
 {
     $data = [];
     $data['name'] = $package->getPrettyName();
     $stability = $package->getStability();
     /* not appending stable is ok */
     $version_tail = $stability && 'stable' != $stability ? "-{$stability}" : '';
     $data['version'] = $package->getPrettyVersion() . $version_tail;
     $data['type'] = $package->getType();
     if ($license = $package->getLicense()) {
         $data['license'] = $license;
     }
     if ($authors = $package->getAuthors()) {
         $data['authors'] = $authors;
     }
     if ($description = $package->getDescription()) {
         $data['description'] = $description;
     }
     if ($support = $package->getSupport()) {
         $data['support'] = $support;
     }
     if ($extra = $package->getExtra()) {
         $data['extra'] = $extra;
     }
     return $data;
 }
Example #3
0
 public function __construct(Interfaces\Package $package)
 {
     $dir = $package->getSourceDir();
     $path = $package->getSourceDir() . '/.gitignore';
     $this->excluded = glob("{$dir}/.git/*");
     $this->excluded = ["{$dir}/.git/", "{$dir}/.gitignore", "{$dir}/.gitmodules"];
     if (is_file($path) === false) {
         throw new \InvalidArgumentException('File not found: ' . $path);
     }
     foreach (file($path) as $line) {
         $line = trim($line);
         // empty line or comment
         if ('' === $line || '#' === $line[0]) {
             continue;
         }
         // negated glob
         if ('!' === $line[0]) {
             $line = substr($line, 1);
             $files = array_diff(glob("{$dir}/*"), glob("{$dir}/{$line}"));
             // normal glob
         } else {
             $files = [];
             if (substr($line, -1) !== '/') {
                 $files = glob("{$dir}/{$line}");
                 $line .= '/';
             }
             $files = array_merge(glob("{$dir}/{$line}*"), $files);
         }
         $this->excluded = array_merge($this->excluded, $files);
     }
 }
Example #4
0
 /**
  * Create package.
  */
 public function create(array $args = array())
 {
     $archBasename = $this->pkg->getSimpleName() . '-' . $this->pkg->getPrettyVersion();
     /* Work around bug  #67417 [NEW]: ::compress modifies archive basename
        creates temp file and rename it */
     $tempName = getcwd() . '/pkl-tmp.tar';
     if (file_exists($tempName)) {
         unlink($tempName);
     }
     $arch = new \PharData($tempName);
     $pkgDir = $this->pkg->getRootDir();
     foreach ($this->pkg->getFiles() as $file) {
         if (is_file($file)) {
             $name = str_replace($pkgDir, '', $file);
             $arch->addFile($file, $name);
         }
     }
     if (file_exists($tempName)) {
         @unlink($tempName . '.gz');
     }
     $arch->compress(\Phar::GZ);
     unset($arch);
     rename($tempName . '.gz', $archBasename . '.tgz');
     unlink($tempName);
     if ($this->cb) {
         $cb = $this->cb;
         $cb($this->pkg);
     }
 }
Example #5
0
 /**
  * @param \Pickle\Base\Interfaces\Package $package
  *
  * @return array
  */
 public function dump(Interfaces\Package $package, $with_version = true)
 {
     $data = [];
     $data['name'] = $package->getPrettyName();
     if ($with_version) {
         $data['version'] = $package->getPrettyVersion();
     }
     $data['type'] = $package->getType();
     if ($license = $package->getLicense()) {
         $data['license'] = $license;
     }
     if ($authors = $package->getAuthors()) {
         $data['authors'] = $authors;
     }
     if ($description = $package->getDescription()) {
         $data['description'] = $description;
     }
     if ($support = $package->getSupport()) {
         $data['support'] = $support;
     }
     if ($extra = $package->getExtra()) {
         $data['extra'] = $extra;
     }
     return $data;
 }
Example #6
0
 public function showOptions(OutputInterface $output, Interfaces\Package $package)
 {
     $table = new Table($output);
     $table->setHeaders(['Type', 'Description', 'Default']);
     foreach ($package->getConfigureOptions() as $option) {
         $default = $option->default;
         if ($option->type === 'enable') {
             $option->type = '<fg=yellow>' . $option->type . '</fg=yellow>';
             $default = $default ? '<fg=green>yes</fg=green>' : '<fg=red>no</fg=red>';
         }
         $table->addRow([$option->type, wordwrap($option->prompt, 40, PHP_EOL), $default]);
     }
     $table->render();
 }
Example #7
0
 /**
  * Create package.
  */
 public function create(array $args = array())
 {
     if (!isset($args['build']) || !$args['build'] instanceof Interfaces\Package\Build) {
         throw new \Exception("Invalid or NULL object passed as Interfaces\\Package\\Build");
     }
     $this->build = $build = $args['build'];
     $info = $build->getInfo();
     $tmp_dir = $build->getTempDir();
     $tmp = $build->getLog('configure');
     if (preg_match(",Build dir:\\s+([\\:\\-\\.0-9a-zA-Z\\\\_]+),", $tmp, $m)) {
         if (preg_match(",^[a-z]\\:\\\\,i", $m[1]) && is_dir($m[1])) {
             /* Parsed the fully qualified path */
             $build_dir = $m[1];
         } else {
             /* otherwise construct */
             $build_dir = $tmp_dir . DIRECTORY_SEPARATOR . $m[1];
         }
     } else {
         $build_dir = 'x86' == $info['arch'] ? $tmp_dir : $tmp_dir . DIRECTORY_SEPARATOR . 'x64';
         $build_dir .= DIRECTORY_SEPARATOR . ($is_release ? 'Release' : 'Debug');
         $build_dir .= $info['thread_safe'] ? '_TS' : '';
     }
     /* Various file paths to pack. */
     $composer_json = $this->pkg->getRootDir() . DIRECTORY_SEPARATOR . 'composer.json';
     if (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE')) {
         $license = $tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE';
     } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'COPYING')) {
         $license = $tmp_dir . DIRECTORY_SEPARATOR . 'COPYING';
     } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE.md')) {
         $license = $tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE.md';
     } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'COPYING.md')) {
         $license = $tmp_dir . DIRECTORY_SEPARATOR . 'COPYING.md';
     } else {
         throw new \Exception("Couldn't find LICENSE");
     }
     $readme = null;
     if (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'README')) {
         $readme = $tmp_dir . DIRECTORY_SEPARATOR . 'README';
     } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'README.md')) {
         $readme = $tmp_dir . DIRECTORY_SEPARATOR . 'README.md';
     }
     /* pack the outcome */
     $zip_name = $this->getZipBaseName($build) . '.zip';
     $zip = new \ZipArchive();
     if (!$zip->open($zip_name, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
         throw new \Exception("Failed to open '{$zip_name}' for writing");
     }
     $ext_dll_found = false;
     $ext_names = $this->getMultiExtensionNames();
     foreach ($ext_names as $ext_name) {
         $dll_name = 'php_' . $ext_name . '.dll';
         $dll_file = $build_dir . DIRECTORY_SEPARATOR . $dll_name;
         if (!file_exists($dll_file)) {
             continue;
         }
         $ext_dll_found = true;
         $zip->addFile($dll_file, $dll_name);
         $pdb_name = 'php_' . $ext_name . '.pdb';
         $pdb_file = $build_dir . DIRECTORY_SEPARATOR . $pdb_name;
         if (file_exists($pdb_file)) {
             $zip->addFile($pdb_file, $pdb_name);
         }
     }
     if (!$ext_dll_found) {
         throw new \Exception("Couldn't find extension DLL");
     }
     $zip->addFile($composer_json, basename($composer_json));
     $zip->addFile($license, basename($license));
     if ($readme) {
         $zip->addFile($readme, basename($readme));
     }
     $zip->close();
 }
Example #8
0
 protected function setPackageReleaseDate(Interfaces\Package $package, array $config)
 {
     if (empty($config['time'])) {
         return;
     }
     $time = ctype_digit($config['time']) ? '@' . $config['time'] : $config['time'];
     try {
         $date = new \DateTime($time, new \DateTimeZone('UTC'));
         $package->setReleaseDate($date);
     } catch (\Exception $e) {
         // don't crash if time is incorrect
     }
 }