From db305c11f5c2232087f5f3736a50c76519b393fc Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 21 Sep 2026 13:30:11 +0800 Subject: [PATCH] test(backend): add GCC include path syntax test for Windows platform - Add testGccOnWindowsUsesGccIncludeSyntaxForAllSourceTypes method to verify include path formatting - Test include paths with GCC compiler on Windows for C, C++, and assembler files - Verify that GCC uses -I flag syntax instead of /I for all source types on Windows - Confirm proper escaping of include paths with spaces using escapeshellarg - Add formatIncludePaths method to handle include flag formatting consistently across platforms --- phpunit/src/Backend/BackendTest.php | 21 +++++++++++++++++++++ src/Backend/GccLikeBackend.php | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/phpunit/src/Backend/BackendTest.php b/phpunit/src/Backend/BackendTest.php index d5734e7c..57fc95a6 100644 --- a/phpunit/src/Backend/BackendTest.php +++ b/phpunit/src/Backend/BackendTest.php @@ -213,6 +213,27 @@ class BackendTest extends TestCase $this->assertStringContainsString('-fno-rtti', $cmd); } + public function testGccOnWindowsUsesGccIncludeSyntaxForAllSourceTypes(): void + { + $compiler = new Gcc(new Windows()); + $includePaths = ['C:\\phpx\\include', 'C:\\Program Files\\PHP\\include']; + $options = [ + 'include_paths' => $includePaths, + ]; + $commands = [ + $compiler->buildCompileCommand('test.cpp', 'test.obj', $options), + $compiler->buildCCompileCommand('test.c', 'test.obj', $options), + $compiler->buildNativeCompileCommand('test.S', 'test.obj', $options, 'assembler'), + ]; + + foreach ($commands as $cmd) { + foreach ($includePaths as $path) { + $this->assertStringContainsString('-I' . escapeshellarg($path), $cmd); + } + $this->assertStringNotContainsString('/I ', $cmd); + } + } + public function testGccBuildCCompileCommandKeepsSharedCompilerOptions(): void { $platform = new Linux(); diff --git a/src/Backend/GccLikeBackend.php b/src/Backend/GccLikeBackend.php index a6c42ae7..2d94ad16 100644 --- a/src/Backend/GccLikeBackend.php +++ b/src/Backend/GccLikeBackend.php @@ -51,6 +51,17 @@ abstract class GccLikeBackend extends CompilerBackend return '-o'; } + /** Include flag syntax is defined by the compiler driver, not the host platform. */ + protected function formatIncludePaths(array $includePaths): string + { + $flags = []; + foreach ($includePaths as $path) { + $flags[] = '-I' . escapeshellarg($path); + } + + return implode(' ', $flags); + } + /** Format the sanitizer flag. */ protected function formatSanitizerFlag(string $sanitizer): string {