Created
August 22, 2016 19:13
-
-
Save Kruithne/2ab70056616481622f5437b515ce61ca to your computer and use it in GitHub Desktop.
BOB for PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* CONFIGURATION */ | |
$projectName = "Rad Project"; | |
$outputDir = "packaged_builds"; | |
$versions = ["x86-win32", "x86-linux", "x86-darwin"]; | |
/* END CONFIGURATION */ | |
function do_match($pattern, $target) { | |
preg_match($pattern, $target, $matches); | |
array_shift($matches); | |
return $matches; | |
} | |
if (!file_exists("bob.jar")) | |
die("ERR: Missing compiler, download bob.jar from http://d.defold.com/stable/"); | |
$projectInfoFile = "workspace/$projectName/.project"; | |
if (!file_exists($projectInfoFile)) | |
die("ERR: Unable to find projejct '$projectName'"); | |
$projectInfo = file_get_contents($projectInfoFile); | |
list($locationURI) = do_match('/<locationURI>([^<]+)<\/locationURI>/', $projectInfo); | |
list($v1, $v2, $branch) = do_match('/projects\/(\d+)\/(\d+)\/branches\/([a-z]+)/', $locationURI); | |
$projectDir = "branches/$v2/$v1/$branch"; | |
if (!file_exists($projectDir)) | |
die("ERR: Unable to locate project directory '$projectDir'"); | |
$buildTag = strrev(uniqid()); | |
foreach ($versions as $version) { | |
$outputFull = "$outputDir/$version"; | |
echo "[$buildTag][$version] Building..." . PHP_EOL; | |
exec("java -jar bob.jar -a -r $projectDir -p $version -bo $outputDir/$version build bundle"); | |
echo "[$buildTag][$version] Archiving..." . PHP_EOL; | |
exec("WinRar a -afzip $outputDir/Build-$version-$buildTag.zip $outputFull"); | |
echo "[$buildTag][$version] Cleaning build files..." . PHP_EOL; | |
if (file_exists($outputFull)) { | |
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($outputFull, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST); | |
foreach ($files as $file) { | |
$func = ($file->isDir() ? "rmdir" : "unlink"); | |
$func($file->getRealPath()); | |
} | |
rmdir($outputFull); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment