/** * 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); } }
/** * 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(); }