diff --git a/base/PerfOptions.php b/base/PerfOptions.php index 3b26eb8..59b89c0 100644 --- a/base/PerfOptions.php +++ b/base/PerfOptions.php @@ -95,6 +95,7 @@ final class PerfOptions { public bool $daemonOutputToFile = false; public string $tempDir; + public ?string $srcDir; public bool $notBenchmarking = false; @@ -159,6 +160,7 @@ public function __construct(Vector $argv) { 'daemon-files', // daemon output goes to files in the temp directory 'temp-dir:', // temp directory to use; if absent one in /tmp is made + 'src-dir:', // location for source to copy into tmp dir instead of ZIP }; $targets = $this->getTargetDefinitions()->keys(); $def->addAll($targets); @@ -288,6 +290,8 @@ public function __construct(Vector $argv) { $this->tempDir = $argTempDir; } + $this->srcDir = $this->getNullableString('src-dir'); + } public function validate() { diff --git a/base/Utils.php b/base/Utils.php index 7fbd692..f4c317a 100644 --- a/base/Utils.php +++ b/base/Utils.php @@ -10,6 +10,7 @@ */ final class Utils { + public static function ExtractTar( string $tar_file, string $extract_to, @@ -31,9 +32,32 @@ public static function ExtractTar( $tar_file, })); } + + public static function CopyDirContents ( + string $from, + string $to, + ): void { + invariant(is_dir($from), '%s is not a directory', $from); + mkdir($to, 0777, true); + $from_dir = opendir($from); + while (($name = readdir($from_dir)) !== false) { + if ($name != '.' && $name != '..') { + $from_name = $from . DIRECTORY_SEPARATOR . $name; + $to_name = $to . DIRECTORY_SEPARATOR . $name; + if (is_dir($from_name) ) { + Utils::CopyDirContents($from_name, $to_name); + } else { + copy($from_name, $to_name); + } + } + } + closedir($from_dir); + } + public static function EscapeCommand(Vector $command): string { return implode(' ', $command->map($x ==> escapeshellarg($x))); } + public static function RunCommand(Vector $args): string { return shell_exec(self::EscapeCommand($args)); } diff --git a/targets/codeigniter/CodeIgniterTarget.php b/targets/codeigniter/CodeIgniterTarget.php index a8f90bf..70219df 100644 --- a/targets/codeigniter/CodeIgniterTarget.php +++ b/targets/codeigniter/CodeIgniterTarget.php @@ -22,12 +22,20 @@ protected function getSanityCheckString(): string { } public function install(): void { - shell_exec($this->safeCommand(Vector { - 'tar', - '-C', $this->options->tempDir, - '-zxf', - __DIR__.'/CodeIgniter-2.2.0.tar.gz' - })); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + shell_exec($this->safeCommand(Vector { + 'tar', + '-C', $this->options->tempDir, + '-zxf', + __DIR__.'/CodeIgniter-2.2.0.tar.gz' + })); + } $index_path = $this->options->tempDir.'/CodeIgniter-2.2.0/index.php'; $index = file_get_contents($index_path); diff --git a/targets/drupal7/Drupal7Target.php b/targets/drupal7/Drupal7Target.php index 03921e1..7f830d9 100644 --- a/targets/drupal7/Drupal7Target.php +++ b/targets/drupal7/Drupal7Target.php @@ -20,15 +20,22 @@ protected function getSanityCheckString(): string { } public function install(): void { - Utils::ExtractTar( - __DIR__.'/drupal-7.31.tar.gz', - $this->options->tempDir, - ); - - Utils::ExtractTar( - __DIR__.'/demo-static.tar.bz2', - $this->getSourceRoot().'/sites/default', - ); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + Utils::ExtractTar( + __DIR__.'/drupal-7.31.tar.gz', + $this->options->tempDir, + ); + Utils::ExtractTar( + __DIR__.'/demo-static.tar.bz2', + $this->getSourceRoot().'/sites/default', + ); + } copy( 'compress.zlib://'.__DIR__.'/settings.php.gz', diff --git a/targets/laravel/LaravelTarget.php b/targets/laravel/LaravelTarget.php index 5c01fa2..2808c3e 100644 --- a/targets/laravel/LaravelTarget.php +++ b/targets/laravel/LaravelTarget.php @@ -20,18 +20,27 @@ protected function getSanityCheckString(): string { } public function install(): void { - shell_exec($this->safeCommand(Vector { - 'tar', - '-C', $this->options->tempDir, - '-zxf', - __DIR__.'/laravel-4.2.0.tar.gz' - })); - shell_exec($this->safeCommand(Vector { - 'tar', - '-C', $this->options->tempDir.'/laravel-4.2.0', - '-jxf', - __DIR__.'/vendor.tar.bz2' - })); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + shell_exec($this->safeCommand(Vector { + 'tar', + '-C', $this->options->tempDir, + '-zxf', + __DIR__.'/laravel-4.2.0.tar.gz' + })); + shell_exec($this->safeCommand(Vector { + 'tar', + '-C', $this->options->tempDir.'/laravel-4.2.0', + '-jxf', + __DIR__.'/vendor.tar.bz2' + })); + } + } public function getSourceRoot(): string { diff --git a/targets/magento1/Magento1Target.php b/targets/magento1/Magento1Target.php index 598931b..6cef811 100644 --- a/targets/magento1/Magento1Target.php +++ b/targets/magento1/Magento1Target.php @@ -44,7 +44,7 @@ private function setPermissions() : void { 'chmod', '-R', 'o+w', - $this->getSourceRoot().'/'.$dir + $this->getSourceRoot().'/'.$dir })); } } @@ -78,10 +78,19 @@ private function getSampleDataDirectory() : string { } public function install(): void { - Utils::ExtractTar( - __DIR__.'/magento-1.9.0.1.tar.gz', - $this->options->tempDir, - ); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + Utils::ExtractTar( + __DIR__.'/magento-1.9.0.1.tar.gz', + $this->options->tempDir, + ); + } + if ($this->options->skipDatabaseInstall) { copy( __DIR__.'/local.xml', diff --git a/targets/mediawiki/MediaWikiTarget.php b/targets/mediawiki/MediaWikiTarget.php index 6570c4b..aaeb06e 100644 --- a/targets/mediawiki/MediaWikiTarget.php +++ b/targets/mediawiki/MediaWikiTarget.php @@ -20,10 +20,18 @@ protected function getSanityCheckString(): string { } public function install(): void { - Utils::ExtractTar( - __DIR__.'/mediawiki-1.24.0.tar.gz', - $this->options->tempDir, - ); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + Utils::ExtractTar( + __DIR__.'/mediawiki-1.24.0.tar.gz', + $this->options->tempDir, + ); + } (new DatabaseInstaller($this->options)) ->setDatabaseName('mw_bench') diff --git a/targets/sugarcrm/SugarCRMTarget.php b/targets/sugarcrm/SugarCRMTarget.php index 2bd6331..047a533 100644 --- a/targets/sugarcrm/SugarCRMTarget.php +++ b/targets/sugarcrm/SugarCRMTarget.php @@ -16,8 +16,16 @@ public function __construct( } public function install(): void { - $pd = new PharData(__DIR__.'/SugarCE-6.5.20.zip'); - $pd->extractTo($this->options->tempDir); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + $pd = new PharData(__DIR__.'/SugarCE-6.5.20.zip'); + $pd->extractTo($this->options->tempDir); + } copy( __DIR__.'/config.php', diff --git a/targets/wordpress/WordpressTarget.php b/targets/wordpress/WordpressTarget.php index 0750820..4406525 100644 --- a/targets/wordpress/WordpressTarget.php +++ b/targets/wordpress/WordpressTarget.php @@ -21,10 +21,18 @@ public function getSanityCheckString(): string { } public function install(): void { - Utils::ExtractTar( - __DIR__.'/wordpress-3.9.1.tar.gz', - $this->options->tempDir, - ); + $src_dir = $this->options->srcDir; + if ($src_dir) { + Utils::CopyDirContents( + $src_dir, + $this->getSourceRoot(), + ); + } else { + Utils::ExtractTar( + __DIR__.'/wordpress-3.9.1.tar.gz', + $this->options->tempDir, + ); + } copy( __DIR__.'/wp-config.php',