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
Branches
Tags
No related merge requests found
...@@ -18,14 +18,22 @@ echo " ...@@ -18,14 +18,22 @@ echo "
_chdir($selfdir); _chdir($selfdir);
_mkdir($dirPackages);
if(!is_dir($dirBuild)){ $OUTFILE="$selfdir/$dirPackages/".str_replace('.php', '', basename($INFILE));
mkdir($dirBuild, 0755, true);
}
$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"); _h1("Prepare source");
$in=file_get_contents($INFILE); $in=file_get_contents($INFILE);
...@@ -40,8 +48,11 @@ if(file_put_contents($TMPFILE, $tempcode)){ ...@@ -40,8 +48,11 @@ if(file_put_contents($TMPFILE, $tempcode)){
_h1("Compile"); _h1("Compile");
_chdir("$selfdir/$dirExternal/bin"); _chdir("$selfdir/$dirBuild");
_exec("./spc micro:combine '$TMPFILE' -O '$OUTFILE'"); _exec("$SPC \
micro:combine \
'$TMPFILE' \
-O '$OUTFILE'");
if(unlink($TMPFILE)){ if(unlink($TMPFILE)){
echo "Cleanup: $TMPFILE was deleted\n"; echo "Cleanup: $TMPFILE was deleted\n";
...@@ -50,7 +61,7 @@ if(unlink($TMPFILE)){ ...@@ -50,7 +61,7 @@ if(unlink($TMPFILE)){
_h1("Test generated binary"); _h1("Test generated binary");
_exec("file '$OUTFILE'"); _exec("file '$OUTFILE'");
_exec("'$OUTFILE' test=123"); _exec("'$OUTFILE' --verbose --ini=../src/simple.ini");
_h1("Done"); _h1("Done");
...@@ -3,16 +3,19 @@ ...@@ -3,16 +3,19 @@
// SHARED FUNCTIONS FOR INSTALLER AND BUILDER // SHARED FUNCTIONS FOR INSTALLER AND BUILDER
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
function _h1($s){ function _h1($s): void
{
echo "\n>>>>>>>>>> $s\n"; echo "\n>>>>>>>>>> $s\n";
} }
function _abort($sMessage, $iExitcode=1){ function _abort($sMessage, $iExitcode = 1): never
{
echo "❌ $sMessage.\n"; echo "❌ $sMessage.\n";
exit($iExitcode); exit($iExitcode);
} }
function _chdir($sDir){ function _chdir($sDir): void
if (!is_dir($sDir)){ {
if (!is_dir($sDir)) {
_abort("Directory '$sDir' not found."); _abort("Directory '$sDir' not found.");
} }
chdir($sDir); chdir($sDir);
...@@ -24,16 +27,33 @@ function _chdir($sDir){ ...@@ -24,16 +27,33 @@ function _chdir($sDir){
* @param mixed $cmd * @param mixed $cmd
* @return void * @return void
*/ */
function _exec($cmd){ function _exec($cmd): void
echo "cmd > $cmd\n"; {
echo "cmd > $cmd\n";
exec("$cmd 2>&1", $aOut, $rc); exec("$cmd 2>&1", $aOut, $rc);
if(!count($aOut)) {
$aOut=["-- no output --"];
}
echo implode("\n", $aOut)."\n"; echo implode("\n", $aOut)."\n";
if($rc != 0){ if ($rc != 0) {
echo "rc=$rc "; echo "rc=$rc ";
_abort("Error: Command failed. Aborting.", $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"; ...@@ -8,4 +8,7 @@ $myarchitecture="x86_64";
$selfdir=dirname(__FILE__); $selfdir=dirname(__FILE__);
$dirExternal="external"; $dirExternal="external";
$dirBuild="built_packages"; $dirBuild="build";
$dirPackages="built_packages";
$SPC="$selfdir/$dirExternal/bin/spc";
...@@ -46,18 +46,16 @@ echo " ...@@ -46,18 +46,16 @@ echo "
_chdir($selfdir); _chdir($selfdir);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
_h1("External data dir"); _h1("Create directories");
if(!is_dir($dirExternal)){
mkdir($dirExternal, 0755, true); _mkdir($dirExternal);
} _mkdir("$dirExternal/bin");
if(!is_dir("$dirExternal/bin")){ _mkdir($dirBuild);
mkdir("$dirExternal/bin", 0755, true);
}
_chdir("$selfdir/$dirExternal");
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
_h1("Get / update Appmonitor repo"); _h1("Get / update Appmonitor repo");
_chdir("$selfdir/$dirExternal");
if(!is_dir("appmonitor")){ if(!is_dir("appmonitor")){
_exec("git clone $gitAppmonitor"); _exec("git clone $gitAppmonitor");
} else { } else {
...@@ -94,26 +92,29 @@ if(file_put_contents($incfile, $out)){ ...@@ -94,26 +92,29 @@ if(file_put_contents($incfile, $out)){
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
_h1("Get / update spc"); _h1("Get / update spc");
_chdir("$selfdir/$dirExternal/bin"); _chdir("$selfdir/$dirExternal/bin");
if(!file_exists("spc")){ if(!file_exists($SPC)){
_exec("wget -O spc '$spcUrl'"); _exec("wget -O $SPC '$spcUrl'");
} else {
echo "⏩ SKIP download of spc.\n";
} }
if (PHP_OS == "Linux") { if (PHP_OS == "Linux") {
_exec("chmod +x spc"); _exec("chmod +x $SPC");
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
_h1("Spc - prepare environment"); _h1("Spc - prepare environment");
_chdir("$selfdir/$dirBuild");
if(!file_exists("$doneBuild")){ if(!file_exists("$doneBuild")){
_exec("./spc --no-interaction doctor"); _exec("$SPC --no-interaction doctor");
_exec("./spc download --no-interaction --with-php=$php_version --for-extensions '$php_libs'"); _exec("$SPC download --no-interaction --with-php=$php_version --for-extensions '$php_libs'");
echo "Hint: this can take 2 minutes ...\n"; echo "💡 Hint: this can take 2 minutes ...\n";
_exec("./spc build --no-interaction --build-micro '$php_libs'"); _exec("$SPC build --no-interaction --build-micro '$php_libs'");
touch("$doneBuild"); touch("$doneBuild");
} else { } 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