Skip to content
Snippets Groups Projects
Commit 5901d640 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update installer + builder

parent 23979ead
No related branches found
No related tags found
No related merge requests found
......@@ -18,14 +18,22 @@ echo "
_chdir($selfdir);
_mkdir($dirPackages);
if(!is_dir($dirBuild)){
mkdir($dirBuild, 0755, true);
}
$OUTFILE="$selfdir/$dirPackages/".str_replace('.php', '', basename($INFILE));
$OUTFILE="$selfdir/$dirBuild/".str_replace('.php', '', basename($INFILE));
_h1("Check target file");
if(file_exists($OUTFILE)){
echo "INFO: output file '$OUTFILE' already exists.\n";
$ts_in=filemtime($INFILE);
$ts_out=filemtime($OUTFILE);
if($ts_in>$ts_out){
echo "INFO: Source file '$INFILE' is newer than '$OUTFILE'. Compiling changes...\n";
} else {
echo "INFO: Source is unchanged since last build..\n";
}
}
_h1("Prepare source");
$in=file_get_contents($INFILE);
......@@ -40,8 +48,11 @@ if(file_put_contents($TMPFILE, $tempcode)){
_h1("Compile");
_chdir("$selfdir/$dirExternal/bin");
_exec("./spc micro:combine '$TMPFILE' -O '$OUTFILE'");
_chdir("$selfdir/$dirBuild");
_exec("$SPC \
micro:combine \
'$TMPFILE' \
-O '$OUTFILE'");
if(unlink($TMPFILE)){
echo "Cleanup: $TMPFILE was deleted\n";
......@@ -50,7 +61,7 @@ if(unlink($TMPFILE)){
_h1("Test generated binary");
_exec("file '$OUTFILE'");
_exec("'$OUTFILE' test=123");
_exec("'$OUTFILE' --verbose --ini=../src/simple.ini");
_h1("Done");
......@@ -3,16 +3,19 @@
// SHARED FUNCTIONS FOR INSTALLER AND BUILDER
// ----------------------------------------------------------------------
function _h1($s){
function _h1($s): void
{
echo "\n>>>>>>>>>> $s\n";
}
function _abort($sMessage, $iExitcode=1){
function _abort($sMessage, $iExitcode = 1): never
{
echo "❌ $sMessage.\n";
exit($iExitcode);
}
function _chdir($sDir){
if (!is_dir($sDir)){
function _chdir($sDir): void
{
if (!is_dir($sDir)) {
_abort("Directory '$sDir' not found.");
}
chdir($sDir);
......@@ -24,16 +27,33 @@ function _chdir($sDir){
* @param mixed $cmd
* @return void
*/
function _exec($cmd){
echo "cmd > $cmd\n";
function _exec($cmd): void
{
echo "cmd > $cmd\n";
exec("$cmd 2>&1", $aOut, $rc);
if(!count($aOut)) {
$aOut=["-- no output --"];
}
echo implode("\n", $aOut)."\n";
if($rc != 0){
if ($rc != 0) {
echo "rc=$rc ";
_abort("Error: Command failed. Aborting.", $rc);
}
echo "✅ OK\n\n";
echo "✅ OK\n";
}
function _mkdir(string $sMyDir): void
{
if (!is_dir($sMyDir)) {
echo "DIR > '$sMyDir' ";
if (!mkdir($sMyDir, 0755, true)) {
_abort("ERROR: mkdir failed.");
}
echo "✅ OK\n\n";
} else {
echo "⏩ SKIP mkdir: already exists: '$sMyDir'\n";
}
}
\ No newline at end of file
......@@ -8,4 +8,7 @@ $myarchitecture="x86_64";
$selfdir=dirname(__FILE__);
$dirExternal="external";
$dirBuild="built_packages";
$dirBuild="build";
$dirPackages="built_packages";
$SPC="$selfdir/$dirExternal/bin/spc";
......@@ -46,18 +46,16 @@ echo "
_chdir($selfdir);
// ----------------------------------------------------------------------
_h1("External data dir");
if(!is_dir($dirExternal)){
mkdir($dirExternal, 0755, true);
}
if(!is_dir("$dirExternal/bin")){
mkdir("$dirExternal/bin", 0755, true);
}
_chdir("$selfdir/$dirExternal");
_h1("Create directories");
_mkdir($dirExternal);
_mkdir("$dirExternal/bin");
_mkdir($dirBuild);
// ----------------------------------------------------------------------
_h1("Get / update Appmonitor repo");
_chdir("$selfdir/$dirExternal");
if(!is_dir("appmonitor")){
_exec("git clone $gitAppmonitor");
} else {
......@@ -94,26 +92,29 @@ if(file_put_contents($incfile, $out)){
// ----------------------------------------------------------------------
_h1("Get / update spc");
_chdir("$selfdir/$dirExternal/bin");
if(!file_exists("spc")){
_exec("wget -O spc '$spcUrl'");
if(!file_exists($SPC)){
_exec("wget -O $SPC '$spcUrl'");
} else {
echo "⏩ SKIP download of spc.\n";
}
if (PHP_OS == "Linux") {
_exec("chmod +x spc");
_exec("chmod +x $SPC");
}
// ----------------------------------------------------------------------
_h1("Spc - prepare environment");
_chdir("$selfdir/$dirBuild");
if(!file_exists("$doneBuild")){
_exec("./spc --no-interaction doctor");
_exec("./spc download --no-interaction --with-php=$php_version --for-extensions '$php_libs'");
_exec("$SPC --no-interaction doctor");
_exec("$SPC download --no-interaction --with-php=$php_version --for-extensions '$php_libs'");
echo "Hint: this can take 2 minutes ...\n";
_exec("./spc build --no-interaction --build-micro '$php_libs'");
echo "💡 Hint: this can take 2 minutes ...\n";
_exec("$SPC build --no-interaction --build-micro '$php_libs'");
touch("$doneBuild");
} else {
echo "Micro already built - php $php_version - extensions '$php_libs'\n";
echo "⏩ SKIP: Micro already built - php $php_version - extensions '$php_libs'\n";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment