From 1a8082ce2ffd0d21a18d33d4d64e30d0b24990d0 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 27 Jan 2026 18:49:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(build):=20=E4=BF=AE=E5=A4=8D=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E8=A7=A3=E6=9E=90=E5=92=8C?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=80=89=E9=A1=B9=E9=85=8D=E7=BD=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复相对路径和绝对路径的处理逻辑 - 添加对不存在源文件的错误检查和提示 - 支持 cxxflags 和 ldflags 配置为数组格式 - 改进路径规范化和文件存在性验证 --- examples/prime/project.yml | 2 +- src/Php/Translator.php | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/examples/prime/project.yml b/examples/prime/project.yml index a5c1099f..48bd6ce7 100644 --- a/examples/prime/project.yml +++ b/examples/prime/project.yml @@ -8,6 +8,6 @@ ldflags: | -L/usr/lib/x86_64-linux-gnu/ -lssl sources: - - php-src + - php-src* - ./cpp-src - main.php \ No newline at end of file diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 5aae2c7e..51b3fb3d 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -176,13 +176,18 @@ class Translator extends Preprocessor foreach ($sources as $src) { $src = trim($src); if ($src[0] != '/') { - $src = $projectDir . '/' . $src; + $absPath = $projectDir . '/' . $src; + } else { + $absPath = $src; + } + $realPath = realpath($absPath); + if (!$realPath) { + $this->error('Source file not exists: `' . $src . '`'); } - $src = realpath($src); - if (is_file($src)) { - $list[] = $src; + if (is_file($realPath)) { + $list[] = $realPath; } else { - $tmp = $this->getFilesFromDir($src); + $tmp = $this->getFilesFromDir($realPath); $list = array_merge($list, $tmp); } } @@ -190,10 +195,18 @@ class Translator extends Preprocessor $list = $this->getFilesFromDir($projectDir); } if (!empty($cfg['cxxflags'])) { - $this->cxxflags = str_replace("\n", " ", $cfg['cxxflags']); + if (is_array($cfg['cxxflags'])) { + $this->cxxflags = implode(' ', $cfg['cxxflags']); + } else { + $this->cxxflags = str_replace("\n", " ", $cfg['cxxflags']); + } } if (!empty($cfg['ldflags'])) { - $this->ldflags = str_replace("\n", " ", $cfg['ldflags']); + if (is_array($cfg['ldflags'])) { + $this->ldflags = implode(' ', $cfg['ldflags']); + } else { + $this->ldflags = str_replace("\n", " ", $cfg['ldflags']); + } } if (!empty($cfg['name'])) { $this->setTargetName($cfg['name']);