Skip to content

Commit db305c1

Browse files
committed
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
1 parent 745556f commit db305c1

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

phpunit/src/Backend/BackendTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,27 @@ public function testGccBuildCompileCommandUsesCustomCompilerAndIncludes(): void
213213
$this->assertStringContainsString('-fno-rtti', $cmd);
214214
}
215215

216+
public function testGccOnWindowsUsesGccIncludeSyntaxForAllSourceTypes(): void
217+
{
218+
$compiler = new Gcc(new Windows());
219+
$includePaths = ['C:\\phpx\\include', 'C:\\Program Files\\PHP\\include'];
220+
$options = [
221+
'include_paths' => $includePaths,
222+
];
223+
$commands = [
224+
$compiler->buildCompileCommand('test.cpp', 'test.obj', $options),
225+
$compiler->buildCCompileCommand('test.c', 'test.obj', $options),
226+
$compiler->buildNativeCompileCommand('test.S', 'test.obj', $options, 'assembler'),
227+
];
228+
229+
foreach ($commands as $cmd) {
230+
foreach ($includePaths as $path) {
231+
$this->assertStringContainsString('-I' . escapeshellarg($path), $cmd);
232+
}
233+
$this->assertStringNotContainsString('/I ', $cmd);
234+
}
235+
}
236+
216237
public function testGccBuildCCompileCommandKeepsSharedCompilerOptions(): void
217238
{
218239
$platform = new Linux();

src/Backend/GccLikeBackend.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ protected function getLinkerOutputFlag(): string
5151
return '-o';
5252
}
5353

54+
/** Include flag syntax is defined by the compiler driver, not the host platform. */
55+
protected function formatIncludePaths(array $includePaths): string
56+
{
57+
$flags = [];
58+
foreach ($includePaths as $path) {
59+
$flags[] = '-I' . escapeshellarg($path);
60+
}
61+
62+
return implode(' ', $flags);
63+
}
64+
5465
/** Format the sanitizer flag. */
5566
protected function formatSanitizerFlag(string $sanitizer): string
5667
{

0 commit comments

Comments
 (0)