> '.$command); exec($command.' 2>&1', $output, $resultCode); if(!$returnOutput) { foreach ($output as $oline) { dumpMessage('# ' . ($resultCode ? 'Error: ' : '') . $oline); } } $success = $resultCode == 0; if(!$success) { dumpMessage('Last command failed, terminating.'); exit(1); } return $returnOutput ? $output : $success; } /** * Return file names from given directory, recursively * @param string $path file path * @param string $filepattern file pattern, e.g. "*.xml" * @return array files */ function globRecursive(string $path, string $filepattern): array { static $filecount=0; $path = rtrim($path, '/\\'); // Find files in path $files = glob($path . DS . $filepattern, GLOB_BRACE); $filecount += count($files); // Find subdirectories in path, and do recursion $dirs = glob($path . DS . '*', GLOB_ONLYDIR); foreach($dirs as $d) { $files = array_merge($files, globRecursive($d, $filepattern)); } return $files; } chdir(BASE_DIR); dumpMessage('Detect Git revision...'); $gitCommits = execCommand('git log --pretty=oneline', true); if(empty($gitCommits)) { die('No commits found.'); } $lastCommitRevision = count($gitCommits) + 671; // The number of earlier Subversion commits which I could not migrate to Git $lastCommitHash = substr($gitCommits[0], 0, strpos($gitCommits[0], ' ')); // start the build process dumpMessage('Compile commit '.$lastCommitHash.' (revision '.$lastCommitRevision.')', true); chdir(BASE_DIR); dumpMessage('Remove unversioned files...'); execCommand('git clean -dfx'); dumpMessage('Download fresh translation files ...', true); execCommand('extra\\internationalization\\tx.exe pull -a'); dumpMessage('Compile .po translation files...'); $po_files = globRecursive('out\\locale\\', '*.po'); foreach($po_files as $po_file) { $mo_file = preg_replace('#\.po$#', '.mo', $po_file); execCommand('"extra\\internationalization\\msgfmt.exe" -o '.$mo_file.' '.$po_file); } $compileBits = ['64']; foreach($compileBits as $bit) { dumpMessage('********* Compile '.$bit.' bit executable', true); chdir(BASE_DIR); compileComponent('synedit', 'SynEdit_R.dpk', $bit); compileComponent('virtualtreeview', 'VirtualTreesR.dpk', $bit); chdir(BASE_DIR); $versionFile = realpath('res\\version.rc'); dumpMessage('Revert version resource file...', true); execCommand('git checkout '.$versionFile); dumpMessage('Modify version resource file...'); $versionOriginal = file_get_contents($versionFile); $versionRevision = preg_replace('#(FILEVERSION\s+\d+,\d+,\d+,)(\d+)(\b)#i', '${1}'.$lastCommitRevision.'$3', $versionOriginal); $versionRevision = str_replace('%APPNAME%', APPNAME, $versionRevision); preg_match('#FILEVERSION\s+(\d+),(\d+),(\d+),(\d+)\b#i', $versionRevision, $matches); $shortVersion = $matches[1].'.'.$matches[2].'.'.$matches[3].'.'.$matches[4]; $fullVersion = $shortVersion.' '.$bit.' Bit'; $versionRevision = str_replace('%APPVER%', $fullVersion, $versionRevision); file_put_contents($versionFile, $versionRevision); dumpMessage('Compile resource files...', true); execCommand('"'.COMPILER_DIR . 'brcc32.exe" '.$versionFile); execCommand('"'.COMPILER_DIR . 'cgrc.exe" res\\icon.rc'); execCommand('"'.COMPILER_DIR . 'brcc32.exe" res\\icon-question.rc'); execCommand('"'.COMPILER_DIR . 'brcc32.exe" res\\manifest.rc'); execCommand('"'.COMPILER_DIR . 'brcc32.exe" res\\updater.rc'); execCommand('"'.COMPILER_DIR . 'cgrc.exe" res\\styles.rc'); execCommand('"'.COMPILER_DIR . 'brcc32.exe" source\\vcl-styles-utils\\AwesomeFont.rc'); execCommand('"'.COMPILER_DIR . 'brcc32.exe" source\\vcl-styles-utils\\AwesomeFont_zip.rc'); dumpMessage('Compile main project...', true); chdir(BASE_DIR.'packages\\'.PACKAGE_DIR); execCommand(compilerCommand($bit, 'exe').' -E"'.BASE_DIR.'out" heidisql.dpr'); dumpMessage('Patch executable with .mo files...', true); // Must be done before madExcept writes a new crc header, otherwise it will complain about a corrupt .exe // See http://tech.dir.groups.yahoo.com/group/dxgettext/message/3623 chdir(BASE_DIR); execCommand('extra\\internationalization\\assemble.exe out\\'.BIN_NAME.'.exe --dxgettext'); dumpMessage('Patch executable with exception handler...', true); chdir(BASE_DIR.'packages\\'.PACKAGE_DIR); execCommand('"'.MAD_DIR.'madExcept\\Tools\\madExceptPatch.exe" "'.BASE_DIR.'out\\'.BIN_NAME.'.exe" heidisql.mes'); chdir(BASE_DIR); $renameTo = sprintf('out\\%s%d.exe', BIN_NAME, $bit); dumpMessage('Rename to '.$renameTo.'...', true); rename('out\\'.BIN_NAME.'.exe', $renameTo); } chdir($start_dir);