Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #29 from jamesgpearce/master
Browse files Browse the repository at this point in the history
Allow --src-dir arg to specify alternative framework code location
  • Loading branch information
fredemmott committed Apr 23, 2015
2 parents fd330d8 + c171030 commit 6065195
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 42 deletions.
4 changes: 4 additions & 0 deletions base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ final class PerfOptions {

public bool $daemonOutputToFile = false;
public string $tempDir;
public ?string $srcDir;

public bool $notBenchmarking = false;

Expand Down Expand Up @@ -159,6 +160,7 @@ public function __construct(Vector<string> $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);
Expand Down Expand Up @@ -288,6 +290,8 @@ public function __construct(Vector<string> $argv) {
$this->tempDir = $argTempDir;
}

$this->srcDir = $this->getNullableString('src-dir');

}

public function validate() {
Expand Down
24 changes: 24 additions & 0 deletions base/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

final class Utils {

public static function ExtractTar(
string $tar_file,
string $extract_to,
Expand All @@ -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<string> $command): string {
return implode(' ', $command->map($x ==> escapeshellarg($x)));
}

public static function RunCommand(Vector<string> $args): string {
return shell_exec(self::EscapeCommand($args));
}
Expand Down
20 changes: 14 additions & 6 deletions targets/codeigniter/CodeIgniterTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 16 additions & 9 deletions targets/drupal7/Drupal7Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
33 changes: 21 additions & 12 deletions targets/laravel/LaravelTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 14 additions & 5 deletions targets/magento1/Magento1Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function setPermissions() : void {
'chmod',
'-R',
'o+w',
$this->getSourceRoot().'/'.$dir
$this->getSourceRoot().'/'.$dir
}));
}
}
Expand Down Expand Up @@ -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',
Expand Down
16 changes: 12 additions & 4 deletions targets/mediawiki/MediaWikiTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 10 additions & 2 deletions targets/sugarcrm/SugarCRMTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 12 additions & 4 deletions targets/wordpress/WordpressTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6065195

Please sign in to comment.