Permalink
Browse files

Code to generate phar and mods deal with phar relative path issues

  • Loading branch information...
1 parent 2a000e3 commit 5bfcd27d56f557e23760435c4fd0ca83f6d077ba zoe slattery committed Oct 9, 2012
View
@@ -0,0 +1,3 @@
+build_output/*
+.project
+
View
8 build.xml → build/build.xml 100755 → 100644
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
-<project name="runtests" default="qa" basedir=".">
-<property file="phpdefinitions.txt" />
+<project name="runtests" default="qa" basedir="..">
+<property file="build/phpdefinitions.txt" />
<target name="clean">
<delete dir="_compare" />
@@ -92,4 +92,8 @@
<exec command="phpcs -n --extensions=php --report=full src > ${project.basedir}/_sniff/sniff.out" passthru="true"/>
</target>
+ <target name="phar" description="Build run-tests.phar file">
+ <exec command="${phpphar} ${project.basedir}/build/buildPhar.php ${project.basedir}/src ${project.basedir}/build_output" passthru="true" />
+ </target>
+
</project>
View
@@ -0,0 +1,14 @@
+<?php
+
+$srcRoot = $argv[1];
+$targetRoot = $argv[2];
+
+$targetname = $targetRoot . "/run-tests.phar";
+
+if(file_exists($targetname)) {
+ unlink($targetname);
+}
+$phar = new Phar($targetname, FilesystemIterator::CURRENT_AS_FILEINFO| FilesystemIterator::KEY_AS_FILENAME, "run-tests.phar");
+$phar->setStub($phar->createDefaultStub("run-tests.php"));
+$phar->buildFromDirectory($srcRoot,'/\.php$|\.txt$/');
+?>
@@ -13,6 +13,9 @@ php_to_test=/usr/local/php5xx/bin/php
#The version of PHP CGI that you intend to test
php_cgi_to_test=/usr/local/php5xx/bin/php-cgi
#
+#The version of PHP that you are using to build the phar file. NB php.ini must have phar.readonly = 0;
+phpphar=/usr/bin/php
+#
#If the versions of PHP that you intent to test have NOT been
#built --with-zlib, put zlib=0 on the next line.
zlib=1
@@ -29,6 +29,17 @@ class rtTestDirectorySetting extends rtSetting
public function init(rtRuntestsConfiguration $configuration)
{
$fileArray = $configuration->getTestFilename();
+
+ //phar does not understand relative paths, so if we have just given a relative path from the
+ //currrent working directory phar will not find the file. Here, if the file does not exist
+ //but a file with cwd prepended does, we reset the name with the cwd prepend.
+ for ($i=0; $i<count($fileArray); $i++) {
+ if(!file_exists($fileArray[$i])) {
+ if(file_exists($configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i]))
+ $fileArray[$i] = $configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i];
+ }
+ }
+
foreach ($fileArray as $file) {
if (is_dir($file)) {
@@ -29,6 +29,18 @@ class rtTestFileSetting extends rtSetting
public function init(rtRuntestsConfiguration $configuration)
{
$fileArray = $configuration->getTestFilename();
+
+ //phar does not understand relative paths, so if we have just given a relative path from the
+ //currrent working directory phar will not find the file. Here, if the file does not exist
+ //but a file with cwd prepended does, we reset the name with the cwd prepend.
+ //TODO: If this only applies to phar is there a better way?
+
+ for ($i=0; $i<count($fileArray); $i++) {
+ if(!file_exists($fileArray[$i])) {
+ if(file_exists($configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i]))
+ $fileArray[$i] = $configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i];
+ }
+ }
foreach ($fileArray as $fn) {
if (!is_dir($fn) && substr($fn, -5) == ".phpt") {
@@ -64,6 +64,7 @@ public function run()
//Set reporting option
$this->setReportStatus();
+
/*
* Main decision point. Either we start this with a directory (or set of directories, in which case tests are
@@ -194,8 +195,8 @@ public function run_tests($testNames) {
//This section deals with running single test cases, or lists of test cases.
foreach ($testNames as $testName) {
-
- if (!file_exists($testName)) {
+
+ if (!file_exists($testName)) {
echo rtText::get('invalidTestFileName', array($testName));
exit();
}
@@ -240,6 +241,8 @@ public function run_tests($testNames) {
}
public function buildSubDirectoryList($testDirectories){
+
+
$subDirectories = array();
foreach ($testDirectories as $testDirectory) {
$subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory));
@@ -5,8 +5,8 @@
/**
* Check to see if the PHP and CGI executables are in a config file
*/
-if(file_exists(__DIR__ . '/../phpdefinitions.txt')) {
- $phpdefs=file(__DIR__ . '/../phpdefinitions.txt');
+if(file_exists(__DIR__ . '/../build/phpdefinitions.txt')) {
+ $phpdefs=file(__DIR__ . '/../build/phpdefinitions.txt');
foreach($phpdefs as $line) {
if(preg_match('/^php_to_test=(.*)/', $line, $matches)) {
define('RT_PHP_PATH', trim($matches[1]));
@@ -19,6 +19,6 @@
}
}
} else {
- echo "You must provide PHP versions in phpdefinitions.txt\n";
+ echo "You must provide PHP versions in build/phpdefinitions.txt\n";
}
?>

0 comments on commit 5bfcd27

Please sign in to comment.