Skip to content

Commit 7f0bfe0

Browse files
committed
Add copy runtime binaries
1 parent 5740c36 commit 7f0bfe0

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Component\Compiler\Action;
6+
7+
use Boson\Component\Compiler\Configuration;
8+
use Composer\InstalledVersions;
9+
10+
/**
11+
* @template-extends AssemblyAction<CopyRuntimeBinaryStatus>
12+
*/
13+
final readonly class CopyRuntimeBinaryAction extends AssemblyAction
14+
{
15+
public function process(Configuration $config): iterable
16+
{
17+
yield CopyRuntimeBinaryStatus::ReadyToCopy;
18+
19+
$sourceBinary = $this->getSourceRuntimeBinary();
20+
$targetBinary = $this->getTargetRuntimeBinary($config);
21+
22+
if (!\is_readable($sourceBinary)) {
23+
throw new \RuntimeException(\sprintf(
24+
'Could not find runtime binary "%s"',
25+
$this->assembly->frontend,
26+
));
27+
}
28+
29+
if (!\is_file($targetBinary)) {
30+
\copy($sourceBinary, $targetBinary);
31+
}
32+
33+
yield CopyRuntimeBinaryStatus::Copied;
34+
}
35+
36+
/**
37+
* @return non-empty-string
38+
*/
39+
private function getTargetRuntimeBinary(Configuration $config): string
40+
{
41+
return $this->assembly->getBuildDirectory($config)
42+
. \DIRECTORY_SEPARATOR . $this->assembly->frontend;
43+
}
44+
45+
/**
46+
* @return non-empty-string
47+
*/
48+
private function getSourceRuntimeBinary(): string
49+
{
50+
return InstalledVersions::getInstallPath('boson-php/runtime')
51+
. \DIRECTORY_SEPARATOR . 'bin'
52+
. \DIRECTORY_SEPARATOR . $this->assembly->frontend;
53+
}
54+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Component\Compiler\Action;
6+
7+
enum CopyRuntimeBinaryStatus
8+
{
9+
case ReadyToCopy;
10+
case Copied;
11+
}

src/Workflow/CompileApplicationWorkflow.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Boson\Component\Compiler\Action\ClearBuildAssemblyDirectoryAction;
88
use Boson\Component\Compiler\Action\CompileAction;
9+
use Boson\Component\Compiler\Action\CopyRuntimeBinaryAction;
910
use Boson\Component\Compiler\Action\CreateBuildAssemblyDirectoryAction;
1011
use Boson\Component\Compiler\Assembly\Assembly;
1112
use Boson\Component\Compiler\Configuration;
@@ -30,6 +31,10 @@ public function process(Configuration $config, iterable $assemblies): iterable
3031
// Compile assembly
3132
yield from new CompileAction($assembly)
3233
->process($config);
34+
35+
// Copy runtime binaries
36+
yield from new CopyRuntimeBinaryAction($assembly)
37+
->process($config);
3338
}
3439
}
3540
}

0 commit comments

Comments
 (0)