Skip to content

Commit 6962d24

Browse files
committed
unify CMakeExecutor and AutoConfExecutor
1 parent eb56690 commit 6962d24

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/SPC/util/executor/UnixAutoconfExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class UnixAutoconfExecutor extends Executor
1414
{
15-
protected ?UnixShell $shell = null;
15+
protected UnixShell $shell;
1616

1717
protected array $configure_args = [];
1818

src/SPC/util/executor/UnixCMakeExecutor.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,36 @@
55
namespace SPC\util\executor;
66

77
use Closure;
8+
use SPC\builder\freebsd\library\BSDLibraryBase;
9+
use SPC\builder\linux\library\LinuxLibraryBase;
10+
use SPC\builder\macos\library\MacOSLibraryBase;
811
use SPC\exception\FileSystemException;
912
use SPC\exception\WrongUsageException;
1013
use SPC\store\FileSystem;
14+
use SPC\util\UnixShell;
1115

1216
/**
1317
* Unix-like OS cmake command executor.
1418
*/
1519
class UnixCMakeExecutor extends Executor
1620
{
17-
protected ?string $build_dir = null;
21+
protected UnixShell $shell;
1822

1923
protected array $configure_args = [];
2024

25+
protected ?string $build_dir = null;
26+
2127
protected ?array $custom_default_args = null;
2228

2329
protected int $steps = 3;
2430

2531
protected bool $reset = true;
2632

27-
protected array $extra_env = [];
33+
public function __construct(protected BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library)
34+
{
35+
parent::__construct($library);
36+
$this->initShell();
37+
}
2838

2939
public function build(string $build_pos = '..'): void
3040
{
@@ -35,17 +45,14 @@ public function build(string $build_pos = '..'): void
3545
FileSystem::resetDir($this->build_dir);
3646
}
3747

38-
// prepare shell
39-
$shell = shell()->cd($this->build_dir)->initializeEnv($this->library)->appendEnv($this->extra_env);
40-
4148
// config
42-
$this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}");
49+
$this->steps >= 1 && $this->shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}");
4350

4451
// make
45-
$this->steps >= 2 && $shell->exec("cmake --build . -j {$this->library->getBuilder()->concurrency}");
52+
$this->steps >= 2 && $this->shell->exec("cmake --build . -j {$this->library->getBuilder()->concurrency}");
4653

4754
// install
48-
$this->steps >= 3 && $shell->exec('make install');
55+
$this->steps >= 3 && $this->shell->exec('make install');
4956
}
5057

5158
/**
@@ -79,12 +86,9 @@ public function addConfigureArgs(...$args): static
7986
return $this;
8087
}
8188

82-
/**
83-
* Add extra environment flags
84-
*/
85-
public function addExtraEnv(array $env): static
89+
public function appendEnv(array $env): static
8690
{
87-
$this->extra_env = [...$this->extra_env, ...$env];
91+
$this->shell->appendEnv($env);
8892
return $this;
8993
}
9094

@@ -220,4 +224,9 @@ private function makeCmakeToolchainFile(): string
220224
FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain);
221225
return $created = realpath(SOURCE_PATH . '/toolchain.cmake');
222226
}
227+
228+
private function initShell(): void
229+
{
230+
$this->shell = shell()->cd($this->build_dir)->initializeEnv($this->library);
231+
}
223232
}

0 commit comments

Comments
 (0)