This commit is contained in:
crazywhalecc
2023-04-23 20:31:58 +08:00
parent 5d5ffe8866
commit 42b2d36319
8 changed files with 142 additions and 85 deletions

View File

@@ -56,12 +56,15 @@ trait UnixBuilderTrait
}
/**
* Sanity check after build complete
*
* @throws RuntimeException
*/
public function sanityCheck(int $build_micro_rule): void
public function sanityCheck(int $build_target): void
{
logger()->info('running sanity check');
if ($build_micro_rule !== BUILD_MICRO_ONLY) {
// sanity check for php-cli
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
logger()->info('running cli sanity check');
[$ret, $output] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "echo \"hello\";"');
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
throw new RuntimeException('cli failed sanity check');
@@ -80,7 +83,9 @@ trait UnixBuilderTrait
}
}
}
if ($build_micro_rule !== BUILD_MICRO_NONE) {
// sanity check for phpmicro
if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) {
if (file_exists(SOURCE_PATH . '/hello.exe')) {
@unlink(SOURCE_PATH . '/hello.exe');
}
@@ -107,11 +112,12 @@ trait UnixBuilderTrait
public function deployBinary(int $type): bool
{
$src = match ($type) {
BUILD_TYPE_CLI => SOURCE_PATH . '/php-src/sapi/cli/php',
BUILD_TYPE_MICRO => SOURCE_PATH . '/php-src/sapi/micro/micro.sfx',
BUILD_TARGET_CLI => SOURCE_PATH . '/php-src/sapi/cli/php',
BUILD_TARGET_MICRO => SOURCE_PATH . '/php-src/sapi/micro/micro.sfx',
BUILD_TARGET_FPM => SOURCE_PATH . '/php-src/sapi/fpm/php-fpm',
default => throw new RuntimeException('Deployment does not accept type ' . $type),
};
logger()->info('Deploying ' . ($type === BUILD_TYPE_CLI ? 'cli' : 'micro') . ' file');
logger()->info('Deploying ' . $this->getBuildTypeName($type) . ' file');
FileSystem::createDir(BUILD_ROOT_PATH . '/bin');
shell()->exec('cp ' . escapeshellarg($src) . ' ' . escapeshellarg(BUILD_ROOT_PATH . '/bin/'));
return true;