parent
9f26e8d06d
commit
159df7dae0
17 changed files with 215 additions and 80 deletions
@ -0,0 +1,37 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of TypePHP(AOT). |
||||
* |
||||
* @link https://www.swoole.com/aot/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace TypePhpTest\Build; |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
use TypePhp\Build\CompilerRuntime; |
||||
|
||||
/** |
||||
* @internal |
||||
* @coversNothing |
||||
*/ |
||||
final class CompilerRuntimeTest extends TestCase |
||||
{ |
||||
public function testSourceRuntimeKeepsInstallationRootSeparateFromEntrypoint(): void |
||||
{ |
||||
$runtime = CompilerRuntime::source(dirname(__DIR__, 3), PHP_BINARY); |
||||
|
||||
self::assertTrue($runtime->sourceEntry); |
||||
self::assertSame(realpath(dirname(__DIR__, 3)), $runtime->installationRoot); |
||||
self::assertSame(realpath(PHP_BINARY), $runtime->executable); |
||||
} |
||||
|
||||
public function testNativeRuntimeUsesExecutableDirectory(): void |
||||
{ |
||||
$runtime = CompilerRuntime::native(PHP_BINARY); |
||||
|
||||
self::assertFalse($runtime->sourceEntry); |
||||
self::assertSame(realpath(PHP_BINARY), $runtime->executable); |
||||
self::assertSame(realpath(dirname(PHP_BINARY)), $runtime->installationRoot); |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of TypePHP(AOT). |
||||
* |
||||
* @link https://www.swoole.com/aot/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace TypePhp\Build; |
||||
|
||||
final readonly class CompilerRuntime |
||||
{ |
||||
private function __construct( |
||||
public string $installationRoot, |
||||
public string $executable, |
||||
public bool $sourceEntry, |
||||
) { |
||||
} |
||||
|
||||
public static function source(string $installationRoot, string $argument): self |
||||
{ |
||||
return new self( |
||||
self::directory($installationRoot), |
||||
ExecutableLocator::resolve($argument) ?? $argument, |
||||
true, |
||||
); |
||||
} |
||||
|
||||
public static function native(string $argument): self |
||||
{ |
||||
$executable = ExecutableLocator::resolve($argument) ?? $argument; |
||||
return self::nativeAt(dirname($executable), $executable); |
||||
} |
||||
|
||||
public static function nativeAt(string $installationRoot, string $executable): self |
||||
{ |
||||
return new self(self::directory($installationRoot), $executable, false); |
||||
} |
||||
|
||||
private static function directory(string $path): string |
||||
{ |
||||
return realpath($path) ?: $path; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue