Skip to content

Commit f158fba

Browse files
committed
Remove unused cmake things
1 parent 059d134 commit f158fba

File tree

3 files changed

+16
-67
lines changed

3 files changed

+16
-67
lines changed

src/SPC/builder/traits/UnixSystemUtilTrait.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,11 @@
44

55
namespace SPC\builder\traits;
66

7-
use SPC\exception\FileSystemException;
8-
use SPC\store\FileSystem;
9-
107
/**
118
* Unix 系统的工具函数 Trait,适用于 Linux、macOS
129
*/
1310
trait UnixSystemUtilTrait
1411
{
15-
/**
16-
* 生成 toolchain.cmake,用于 cmake 构建
17-
*
18-
* @param string $os 操作系统代号
19-
* @param string $target_arch 目标架构
20-
* @param string $cflags CFLAGS 参数
21-
* @param null|string $cc CC 参数(默认空)
22-
* @param null|string $cxx CXX 参数(默认空)
23-
* @throws FileSystemException
24-
*/
25-
public static function makeCmakeToolchainFile(
26-
string $os,
27-
string $target_arch,
28-
string $cflags,
29-
?string $cc = null,
30-
?string $cxx = null
31-
): string {
32-
logger()->debug("making cmake tool chain file for {$os} {$target_arch} with CFLAGS='{$cflags}'");
33-
$root = BUILD_ROOT_PATH;
34-
$ccLine = '';
35-
if ($cc) {
36-
$ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
37-
}
38-
$cxxLine = '';
39-
if ($cxx) {
40-
$cxxLine = 'SET(CMAKE_CXX_COMPILER ' . $cxx . ')';
41-
}
42-
$toolchain = <<<CMAKE
43-
{$ccLine}
44-
{$cxxLine}
45-
SET(CMAKE_C_FLAGS "{$cflags}")
46-
SET(CMAKE_CXX_FLAGS "{$cflags}")
47-
SET(CMAKE_FIND_ROOT_PATH "{$root}")
48-
SET(CMAKE_PREFIX_PATH "{$root}")
49-
SET(CMAKE_INSTALL_PREFIX "{$root}")
50-
SET(CMAKE_INSTALL_LIBDIR "lib")
51-
52-
set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config")
53-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
54-
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
55-
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
56-
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
57-
set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm -lutil")
58-
CMAKE;
59-
// 有时候系统的 cmake 找不到 ar 命令,真奇怪
60-
if (PHP_OS_FAMILY === 'Linux') {
61-
$toolchain .= "\nSET(CMAKE_AR \"ar\")";
62-
}
63-
FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain);
64-
return realpath(SOURCE_PATH . '/toolchain.cmake');
65-
}
66-
6712
/**
6813
* @param string $name 命令名称
6914
* @param array $paths 寻找的目标路径(如果不传入,则使用环境变量 PATH)

src/SPC/builder/unix/executor/UnixCMakeExecutor.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
namespace SPC\builder\unix\executor;
66

7+
use Closure;
78
use SPC\exception\FileSystemException;
89
use SPC\exception\WrongUsageException;
910
use SPC\store\FileSystem;
1011

12+
/**
13+
* Unix-like OS cmake command executor.
14+
*/
1115
class UnixCMakeExecutor extends Executor
1216
{
13-
/** @var null|string CMake build dir */
1417
protected ?string $cmake_build_dir = null;
1518

16-
/** @var array CMake additional configure arguments */
1719
protected array $configure_args = [];
1820

1921
protected ?array $custom_default_args = null;
@@ -80,6 +82,12 @@ public function addConfigureArgs(...$args): static
8082
return $this;
8183
}
8284

85+
/**
86+
* To build steps.
87+
*
88+
* @param int $step Step number, accept 1-3
89+
* @return $this
90+
*/
8391
public function toStep(int $step): static
8492
{
8593
$this->steps = $step;
@@ -106,6 +114,10 @@ public function setCustomDefaultArgs(...$args): static
106114
return $this;
107115
}
108116

117+
/**
118+
* Set the reset status.
119+
* If we set it to false, it will not clean and create the specified cmake working directory.
120+
*/
109121
public function setReset(bool $reset): static
110122
{
111123
$this->reset = $reset;
@@ -152,6 +164,8 @@ private function initCMakeBuildDir(): void
152164
}
153165

154166
/**
167+
* Generate cmake toolchain file for current spc instance, and return the file path.
168+
*
155169
* @return string CMake toolchain file path
156170
* @throws FileSystemException
157171
* @throws WrongUsageException

tests/SPC/builder/unix/UnixSystemUtilTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use SPC\builder\freebsd\SystemUtil as FreebsdSystemUtil;
99
use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
1010
use SPC\builder\macos\SystemUtil as MacosSystemUtil;
11-
use SPC\exception\FileSystemException;
1211

1312
/**
1413
* @internal
@@ -31,15 +30,6 @@ public function setUp(): void
3130
$this->util = new $util_class();
3231
}
3332

34-
/**
35-
* @throws FileSystemException
36-
*/
37-
public function testMakeCmakeToolchainFile()
38-
{
39-
$str = $this->util->makeCmakeToolchainFile(PHP_OS_FAMILY, 'x86_64', '');
40-
$this->assertIsString($str);
41-
}
42-
4333
public function testFindCommand()
4434
{
4535
$this->assertIsString($this->util->findCommand('bash'));

0 commit comments

Comments
 (0)