r54644 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54643‎ | r54644 | r54645 >
Date:23:13, 8 August 2009
Author:demon
Status:reverted (Comments)
Tags:
Comment:
Use parsekit instead. php -l sucks.
Modified paths:
  • /trunk/phase3/maintenance/syntaxChecker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/syntaxChecker.php
@@ -34,12 +34,20 @@
3535 }
3636
3737 public function execute() {
 38+ if( !function_exists( 'parsekit_compile_file' ) ) {
 39+ $this->error( 'Requires PHP with parsekit', true );
 40+ }
 41+
3842 $this->output( "Building file list..." );
3943 $this->buildFileList();
4044 $this->output( "done.\n" );
4145
4246 $this->output( "Checking syntax (this can take a really long time)...\n\n" );
43 - $res = $this->checkSyntax();
 47+ foreach( $this->mFiles as $f ) {
 48+ $this->checkFile( $f );
 49+ }
 50+ $this->output( "\nDone! " . count( $this->mFiles ) . " files checked, " .
 51+ count( $this->mFailures ) . " failures found" );
4452 }
4553
4654 /**
@@ -76,18 +84,32 @@
7785 }
7886
7987 /**
80 - * Check the files for syntax errors
 88+ * Check a file for syntax errors. Shamelessly stolen
 89+ * from tools/lint.php by TimStarling
 90+ *
 91+ * @param $file String Path to a file to check for syntax errors
8192 */
82 - private function checkSyntax() {
83 - foreach( $this->mFiles as $f ) {
84 - $res = exec( 'php -l ' . $f );
85 - if( strpos( $res, 'No syntax errors detected' ) === false ) {
86 - $this->mFailures[] = $f;
87 - $this->error( $res . "\n" );
 93+ private function checkFile( $file ) {
 94+ static $okErrors = array(
 95+ 'Redefining already defined constructor',
 96+ 'Assigning the return value of new by reference is deprecated',
 97+ );
 98+ $errors = array();
 99+ parsekit_compile_file( $file, $errors, PARSEKIT_SIMPLE );
 100+ $ret = true;
 101+ if ( $errors ) {
 102+ foreach ( $errors as $error ) {
 103+ foreach ( $okErrors as $okError ) {
 104+ if ( substr( $error['errstr'], 0, strlen( $okError ) ) == $okError ) {
 105+ continue 2;
 106+ }
 107+ }
 108+ $ret = false;
 109+ $this->output( "Error in $file line {$error['lineno']}: {$error['errstr']}\n" );
88110 }
 111+ $this->mFailures[ $file ] = $errors;
89112 }
90 - $this->output( count($this->mFiles) . " files checked, "
91 - . count($this->mFailures) . " failures\n" );
 113+ return $ret;
92114 }
93115 }
94116

Follow-up revisions

RevisionCommit summaryAuthorDate
r54737Revert r54644 to syntaxChecker.php "Use parsekit instead. php -l sucks."...brion20:36, 10 August 2009
r55298Redo r54644. php -l still sucks, but some people don't have parsekit. So let'...demon00:46, 19 August 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   20:34, 10 August 2009

ParseKit is an external PECL module which isn't super easy to install. Don't want to rely on something like that for tests we want everyone to be able to run prior to checkin.

Status & tagging log