Skip to content

Commit c5e486c

Browse files
ondrejmirtesclaude
andcommitted
Run the trusted-types file-cache check on phpize and Windows builds
The opcache.file_cache check added in ab78d7d spawns a child PHP, and that child failed outside the Makefile build on Linux and macOS: - phpize legs: the child loaded the extension from its Makefile location, turbo-ext/phpstan_turbo.so, which phpize builds never write. The step now passes TURBO_DLL like the smoke and arena steps next to it. - Windows: sys_get_temp_dir() is an 8.3 path (C:\Users\RUNNER~1\...), and the CLI passes a -d value that starts with a letter into the ini unquoted, where ~ is an operator. The value is now quoted, and the child runs from an argument list, because escapeshellarg() on Windows replaces double quotes with spaces. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CmttmeH2WqiTdVc9HGHBNL
1 parent 358f51d commit c5e486c

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎.github/workflows/phar.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ jobs:
316316
run: php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" turbo-ext/tests/exit-immediately.php
317317

318318
- name: "Trusted types (the optimizer pass drops type checks under the prefix only)"
319+
# the opcache.file_cache child process locates the extension through
320+
# TURBO_DLL — its default, turbo-ext/phpstan_turbo.so, only exists in
321+
# Makefile builds
322+
env:
323+
TURBO_DLL: ${{ runner.temp }}/turbo-ext/modules/phpstan_turbo.so
319324
run: php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" -d opcache.enable_cli=1 turbo-ext/tests/trusted-types.php
320325

321326
- name: "Signature parity (reflect native classes against the PHP twins)"

‎turbo-ext/tests/trusted-types.php‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,25 @@ function check(string $label, array $expected, array $actual): bool
135135
$fileCacheDir = sys_get_temp_dir() . '/phpstan-trusted-types-file-cache-' . getmypid();
136136
@mkdir($fileCacheDir);
137137
$extension = getenv('TURBO_DLL') ?: dirname(__DIR__) . '/phpstan_turbo.so';
138-
$armedWithFileCache = exec(sprintf(
139-
'%s -d extension=%s -d opcache.enable_cli=1 -d opcache.file_cache=%s -r %s',
140-
escapeshellarg(PHP_BINARY),
141-
escapeshellarg($extension),
142-
escapeshellarg($fileCacheDir),
143-
escapeshellarg('var_export(PHPStanTurbo\\Runtime::trustTypesUnder(' . var_export($trustedPrefix, true) . '));'),
144-
));
138+
// The file cache path is quoted for the ini parser: the CLI quotes a -d value
139+
// itself only when it does not start with a letter or digit, and on Windows
140+
// the temp dir is an 8.3 path whose ~ is an operator in unquoted ini syntax.
141+
// The quotes are why this is an argument list rather than a shell command:
142+
// escapeshellarg() on Windows replaces double quotes with spaces.
143+
$process = proc_open([
144+
PHP_BINARY,
145+
'-d', 'extension=' . $extension,
146+
'-d', 'opcache.enable_cli=1',
147+
'-d', 'opcache.file_cache="' . $fileCacheDir . '"',
148+
'-r', 'var_export(PHPStanTurbo\\Runtime::trustTypesUnder(' . var_export($trustedPrefix, true) . '));',
149+
], [1 => ['pipe', 'w']], $pipes);
150+
if ($process === false) {
151+
fwrite(STDERR, "proc_open failed\n");
152+
exit(1);
153+
}
154+
$armedWithFileCache = trim(stream_get_contents($pipes[1]));
155+
fclose($pipes[1]);
156+
proc_close($process);
145157
if ($armedWithFileCache !== 'false') {
146158
fwrite(STDERR, sprintf("FAIL: trustTypesUnder() must refuse with opcache.file_cache set, got %s\n", var_export($armedWithFileCache, true)));
147159
$ok = false;

0 commit comments

Comments
 (0)