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

This commit is contained in:
zoe slattery
2012-10-09 13:34:11 +01:00
parent 2a000e34b9
commit 5bfcd27d56
8 changed files with 57 additions and 7 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
build_output/*
.project

8
build.xml → build/build.xml Executable file → Normal file
View File

@@ -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>

14
build/buildPhar.php Normal file
View File

@@ -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$/');
?>

View File

@@ -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

View File

@@ -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)) {

View 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") {

View File

@@ -64,6 +64,7 @@ class rtPhpTestRun
//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 @@ class rtPhpTestRun
//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 @@ class rtPhpTestRun
}
public function buildSubDirectoryList($testDirectories){
$subDirectories = array();
foreach ($testDirectories as $testDirectory) {
$subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory));

View File

@@ -5,8 +5,8 @@ require_once __DIR__ . '/../src/rtAutoload.php';
/**
* 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 @@ if(file_exists(__DIR__ . '/../phpdefinitions.txt')) {
}
}
} else {
echo "You must provide PHP versions in phpdefinitions.txt\n";
echo "You must provide PHP versions in build/phpdefinitions.txt\n";
}
?>