mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-03 14:55:39 +08:00
merge cmake changes from master into icurel
This commit is contained in:
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\util;
|
||||
|
||||
use SPC\builder\freebsd\library\BSDLibraryBase;
|
||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||
use SPC\exception\RuntimeException;
|
||||
use ZM\Logger\ConsoleColor;
|
||||
|
||||
@@ -42,6 +45,10 @@ class UnixShell
|
||||
/* @phpstan-ignore-next-line */
|
||||
logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd));
|
||||
logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']);
|
||||
$env_str = $this->getEnvString();
|
||||
if (!empty($env_str)) {
|
||||
$cmd = "{$env_str} {$cmd}";
|
||||
}
|
||||
if ($this->cd !== null) {
|
||||
$cmd = 'cd ' . escapeshellarg($this->cd) . ' && ' . $cmd;
|
||||
}
|
||||
@@ -52,6 +59,37 @@ class UnixShell
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the environment variable that common build will be used.
|
||||
*
|
||||
* @param BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library Library class
|
||||
*/
|
||||
public function initializeEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library): UnixShell
|
||||
{
|
||||
$this->setEnv([
|
||||
'CFLAGS' => $library->getLibExtraCFlags(),
|
||||
'LDFLAGS' => $library->getLibExtraLdFlags(),
|
||||
'LIBS' => $library->getLibExtraLibs(),
|
||||
'CXXFLAGS' => $library->getLibExtraCXXFlags(),
|
||||
]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function appendEnv(array $env): UnixShell
|
||||
{
|
||||
foreach ($env as $k => $v) {
|
||||
if ($v === '') {
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->env[$k])) {
|
||||
$this->env[$k] = $v;
|
||||
} else {
|
||||
$this->env[$k] = "{$v} {$this->env[$k]}";
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execWithResult(string $cmd, bool $with_log = true): array
|
||||
{
|
||||
if ($with_log) {
|
||||
@@ -80,14 +118,6 @@ class UnixShell
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function execWithEnv(string $cmd): UnixShell
|
||||
{
|
||||
return $this->exec($this->getEnvString() . ' ' . $cmd);
|
||||
}
|
||||
|
||||
private function getEnvString(): string
|
||||
{
|
||||
$str = '';
|
||||
|
||||
Reference in New Issue
Block a user