2024-01-31 13:32:14 +00:00
|
|
|
<?php
|
|
|
|
function builderLog(string $message){
|
|
|
|
echo(date("Y-m-d h:m", time())." ".$message."\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
|
|
|
|
echo "[LonaDB Phar compiler]\n";
|
|
|
|
|
|
|
|
$config = json_decode(file_get_contents("build_config.json"));
|
|
|
|
|
|
|
|
$path = $config->{"path"};
|
|
|
|
$filename = $config->{"filename"};
|
|
|
|
$version = $config->{"version"};
|
|
|
|
$branch = "debug";
|
|
|
|
|
2024-02-29 14:47:51 +00:00
|
|
|
if($config->{"debug"}) {
|
|
|
|
$path = $path."/debug";
|
|
|
|
$debug = "True";
|
|
|
|
}
|
2024-01-31 13:32:14 +00:00
|
|
|
else {
|
2024-02-29 14:47:51 +00:00
|
|
|
$debug = "False";
|
2024-01-31 13:32:14 +00:00
|
|
|
$path = $path."/release";
|
|
|
|
$branch = "release";
|
|
|
|
}
|
|
|
|
|
2024-02-29 14:47:51 +00:00
|
|
|
|
|
|
|
echo "[CONF] Debug=".$debug."\n";
|
2024-01-31 13:32:14 +00:00
|
|
|
echo "[CONF] Path=".$path."\n";
|
|
|
|
echo "[CONF] Filename=".$filename."\n";
|
|
|
|
echo "[CONF] Version=".$version."\n";
|
|
|
|
|
|
|
|
echo "\nBuild? (Y/n)\n";
|
|
|
|
$handle = fopen ("php://stdin","r");
|
|
|
|
$line = fgets($handle);
|
|
|
|
if(trim(strtolower($line)) === 'no' || trim(strtolower($line)) === "n"){
|
|
|
|
echo "ABORTING!\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$start = time();
|
|
|
|
|
|
|
|
builderLog("[COMPOSER] Running 'composer install'");
|
2024-02-02 23:59:53 +00:00
|
|
|
exec("cd src ; printf '\n' | ./composer.phar install");
|
2024-01-31 13:32:14 +00:00
|
|
|
|
|
|
|
if(file_exists($path."/".$filename."-".$version.".phar")){
|
|
|
|
unlink($path."/".$filename."-".$version.".phar");
|
|
|
|
builderLog("[CLEANUP] Deleted an old build");
|
|
|
|
}
|
|
|
|
if(file_exists("build/run-phar.sh")){
|
|
|
|
unlink(__DIR__."/run-phar.sh");
|
|
|
|
builderLog("[CLEANUP] Deleted an old runner");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
builderLog("[BUILD] Creating a new Phar object");
|
|
|
|
$phar = new Phar($path."/".$filename."-".$version.".phar", 0, $path."/".$filename."-".$version.".phar");
|
|
|
|
|
|
|
|
builderLog("[BUILD] Adding files to the Phar archive");
|
|
|
|
$phar->buildFromDirectory(__DIR__ . '/../src');
|
|
|
|
|
|
|
|
builderLog("[BUILD] Set the default stub file");
|
|
|
|
$phar->setDefaultStub('LonaDB/LonaDB.php', 'LonaDB/LonaBD.php');
|
|
|
|
|
|
|
|
$phar->setAlias($filename."-".$version.".phar");
|
|
|
|
|
|
|
|
builderLog("[BUILD] Saving the new Phar archive");
|
|
|
|
$phar->stopBuffering();
|
|
|
|
|
|
|
|
builderLog("[INFO] Phar archive created successfully");
|
|
|
|
|
|
|
|
builderLog("[RUN] Generating run script");
|
2024-03-03 21:19:01 +00:00
|
|
|
file_put_contents("./build/run-phar.sh", 'cd '.$path.' ; printf "test\n" | php -dextension=openswoole.so -dphar.readonly=0 '.$filename.'-'.$version.'.phar');
|
2024-01-31 13:32:14 +00:00
|
|
|
|
|
|
|
builderLog("[RUN] Adding Permissions to run script");
|
|
|
|
exec("chmod 777 ./build/run-phar.sh");
|
|
|
|
|
|
|
|
echo "Done!\nBuilt in ".(time() - $start) ." ms!\n";
|
|
|
|
} catch (Exception $e) {
|
|
|
|
builderLog('[ERROR] '.$e->getMessage());
|
|
|
|
}
|