4 require( dirname( __FILE__ ) . '/../Maintenance.php' );
6 class MakeHipHop extends Maintenance {
11 $sourceDir = realpath( dirname( __FILE__ ) );
12 $IP = realpath( "$sourceDir/../.." );
13 $buildDir = "$sourceDir/build";
14 $outDir = "$buildDir/hiphop-output";
15 $persistentDir = "$buildDir/persistent" ;
17 if ( !is_dir( $buildDir ) ) {
18 mkdir( $buildDir, 0777, true );
20 if ( !is_dir( $persistentDir ) ) {
21 mkdir( $persistentDir, 0777, true );
24 # With the CentOS RPMs, you just get g++44, no g++, so we have to
26 if ( isset( $_ENV['CXX'] ) ) {
32 # Create a function that provides the HipHop compiler version, and
33 # doesn't exist when MediaWiki is invoked in interpreter mode.
34 $version = trim( `hphp --version` );
36 "$buildDir/HipHopCompilerVersion.php",
38 "function wfHipHopCompilerVersion() {\n" .
39 "return " . var_export( $version, true ) . ";\n" .
48 ' --input-dir=' . wfEscapeShellArg( $IP ) .
49 ' --input-list=' . wfEscapeShellArg( "$sourceDir/file-list.small" ) .
50 ' --inputs=' . wfEscapeShellArg( "$buildDir/HipHopCompilerVersion.php" ) .
51 ' --config=' . wfEscapeShellArg( "$sourceDir/compiler.conf" ) .
52 ' --parse-on-demand=false' .
53 ' --program=mediawiki-hphp' .
54 ' --output-dir=' . wfEscapeShellArg( $outDir ) .
57 # Copy the generated C++ files into the source directory for cmake
58 $iter = new RecursiveIteratorIterator(
59 new RecursiveDirectoryIterator( $outDir ),
60 RecursiveIteratorIterator::SELF_FIRST );
61 $sourceFiles = array();
62 $regenerateMakefile = false;
65 foreach ( $iter as $sourcePath => $file ) {
66 $name = substr( $sourcePath, strlen( $outDir ) + 1 );
67 $sourceFiles[$name] = true;
68 $destPath = "$persistentDir/$name";
69 if ( $file->isDir() ) {
70 if ( !is_dir( $destPath ) ) {
77 # Remove any files that weren't touched, these may have been removed
78 # from file-list, we should not compile them
79 if ( $file->getMTime() < $startTime ) {
80 if ( file_exists( $destPath ) ) {
82 # Files removed, regenerate the makefile
83 $regenerateMakefile = true;
85 unlink( $sourcePath );
90 if ( file_exists( $destPath ) ) {
91 $sourceHash = md5( file_get_contents( $sourcePath ) );
92 $destHash = md5( file_get_contents( $destPath ) );
93 if ( $sourceHash == $destHash ) {
97 # New files added, regenerate the makefile
98 $regenerateMakefile = true;
101 copy( $sourcePath, $destPath );
104 echo "MediaWiki: $numFilesChanged files changed out of $numFiles\n";
106 if ( !file_exists( "$persistentDir/CMakeLists.txt" ) ) {
107 # Run cmake for the first time
108 $regenerateMakefile = true;
111 # Do our own version of $HPHP_HOME/bin/run.sh, which isn't so broken.
112 # HipHop's RELEASE mode seems to be stuck always on, so symbols get
113 # stripped. Also we will try keeping the generated .o files instead of
114 # throwing away hours of CPU time every time you make a typo.
116 chdir( $persistentDir );
118 if ( $regenerateMakefile ) {
119 copy( $_ENV['HPHP_HOME'] . '/bin/CMakeLists.base.txt',
120 "$persistentDir/CMakeLists.txt" );
122 if ( file_exists( "$persistentDir/CMakeCache.txt" ) ) {
123 unlink( "$persistentDir/CMakeCache.txt" );
127 ' -D CMAKE_BUILD_TYPE:string=Debug' .
128 ' -D PROGRAM_NAME:string=mediawiki-hphp';
130 if ( file_exists( '/usr/bin/ccache' ) ) {
131 $cmd .= ' -D CMAKE_CXX_COMPILER:string=ccache' .
132 ' -D CMAKE_CXX_COMPILER_ARG1:string=' . wfEscapeShellArg( $cxx );
140 # Run make. This is the slow step.
143 $elapsed = time() - $startTime;
145 echo "Completed in ";
146 if ( $elapsed >= 3600 ) {
147 $hours = floor( $elapsed / 3600 );
149 $elapsed -= $hours * 3600;
151 if ( $elapsed >= 60 ) {
152 $minutes = floor( $elapsed / 60 );
153 echo $minutes . 'm ';
154 $elapsed -= $minutes * 60;
156 echo $elapsed . "s\n";
157 echo "The MediaWiki executable is at build/persistent/mediawiki-hphp\n";
161 $maintClass = 'MakeHipHop';
162 require_once( RUN_MAINTENANCE_IF_MAIN );