5
5
namespace SPC \util \executor ;
6
6
7
7
use Closure ;
8
+ use SPC \builder \freebsd \library \BSDLibraryBase ;
9
+ use SPC \builder \linux \library \LinuxLibraryBase ;
10
+ use SPC \builder \macos \library \MacOSLibraryBase ;
8
11
use SPC \exception \FileSystemException ;
9
12
use SPC \exception \WrongUsageException ;
10
13
use SPC \store \FileSystem ;
14
+ use SPC \util \UnixShell ;
11
15
12
16
/**
13
17
* Unix-like OS cmake command executor.
14
18
*/
15
19
class UnixCMakeExecutor extends Executor
16
20
{
17
- protected ? string $ build_dir = null ;
21
+ protected UnixShell $ shell ;
18
22
19
23
protected array $ configure_args = [];
20
24
25
+ protected ?string $ build_dir = null ;
26
+
21
27
protected ?array $ custom_default_args = null ;
22
28
23
29
protected int $ steps = 3 ;
24
30
25
31
protected bool $ reset = true ;
26
32
27
- protected array $ extra_env = [];
33
+ public function __construct (protected BSDLibraryBase |LinuxLibraryBase |MacOSLibraryBase $ library )
34
+ {
35
+ parent ::__construct ($ library );
36
+ $ this ->initShell ();
37
+ }
28
38
29
39
public function build (string $ build_pos = '.. ' ): void
30
40
{
@@ -35,17 +45,14 @@ public function build(string $build_pos = '..'): void
35
45
FileSystem::resetDir ($ this ->build_dir );
36
46
}
37
47
38
- // prepare shell
39
- $ shell = shell ()->cd ($ this ->build_dir )->initializeEnv ($ this ->library )->appendEnv ($ this ->extra_env );
40
-
41
48
// 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 }" );
43
50
44
51
// 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 }" );
46
53
47
54
// install
48
- $ this ->steps >= 3 && $ shell ->exec ('make install ' );
55
+ $ this ->steps >= 3 && $ this -> shell ->exec ('make install ' );
49
56
}
50
57
51
58
/**
@@ -79,12 +86,9 @@ public function addConfigureArgs(...$args): static
79
86
return $ this ;
80
87
}
81
88
82
- /**
83
- * Add extra environment flags
84
- */
85
- public function addExtraEnv (array $ env ): static
89
+ public function appendEnv (array $ env ): static
86
90
{
87
- $ this ->extra_env = [... $ this -> extra_env , ... $ env] ;
91
+ $ this ->shell -> appendEnv ( $ env) ;
88
92
return $ this ;
89
93
}
90
94
@@ -220,4 +224,9 @@ private function makeCmakeToolchainFile(): string
220
224
FileSystem::writeFile (SOURCE_PATH . '/toolchain.cmake ' , $ toolchain );
221
225
return $ created = realpath (SOURCE_PATH . '/toolchain.cmake ' );
222
226
}
227
+
228
+ private function initShell (): void
229
+ {
230
+ $ this ->shell = shell ()->cd ($ this ->build_dir )->initializeEnv ($ this ->library );
231
+ }
223
232
}
0 commit comments