Repository navigation
Tell the user when a phar runs without the Turbo extension #6719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| use Phar; | ||
| use function dirname; | ||
| use function file_get_contents; | ||
| use function is_dir; | ||
| use function is_file; | ||
| use function php_uname; | ||
| use function sprintf; | ||
|
|
@@ -74,32 +75,38 @@ public static function findExtensionForWorkers(): ?string | |
| } | ||
|
|
||
| /** | ||
| * Locates the distributed extension binary for the current platform — | ||
| * present only next to a phar-based installation. | ||
| * Whether PHPStan runs from a bare copy of phpstan.phar, without the | ||
| * turbo-ext/ directory the phpstan/phpstan Composer package ships next to | ||
| * it, on a runtime the extension is built for, and no php.ini loads the | ||
| * extension either. | ||
| */ | ||
| public static function findExtension(): ?string | ||
| public static function isMissingNextToPhar(): bool | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should only error for php-runtime-versions which are compatible with turbo
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm should it share most logic with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 5a24d48: both methods now share one helper. The note only shows where There is no upper bound yet, in either method. A bare phar on a future PHP 8.7 would show the note before an 8.7 binary exists. Should I add one? |
||
| { | ||
| if (PHP_VERSION_ID < self::MINIMUM_PHP_VERSION_ID) { | ||
| return null; | ||
| $platformDirectory = self::getPlatformDirectoryNextToPhar(); | ||
| if ($platformDirectory === null) { | ||
| return false; | ||
| } | ||
| if ((bool) PHP_DEBUG) { | ||
| return null; | ||
| if (TurboExtensionEnabler::isLoaded()) { | ||
| return false; | ||
| } | ||
|
|
||
| $pharPath = Phar::running(false); | ||
| if ($pharPath === '') { | ||
| return null; | ||
| } | ||
| return !is_dir(dirname($platformDirectory)); | ||
| } | ||
|
|
||
| $platform = self::resolvePlatformDirectory(PHP_OS_FAMILY, php_uname('m'), self::isMusl()); | ||
| if ($platform === null) { | ||
| /** | ||
| * Locates the distributed extension binary for the current platform — | ||
| * present only next to a phar-based installation. | ||
| */ | ||
| public static function findExtension(): ?string | ||
| { | ||
| $platformDirectory = self::getPlatformDirectoryNextToPhar(); | ||
| if ($platformDirectory === null) { | ||
| return null; | ||
| } | ||
|
|
||
| $file = sprintf( | ||
| '%s/turbo-ext/%s/phpstan_turbo-%d.%d%s.%s', | ||
| dirname($pharPath), | ||
| $platform, | ||
| '%s/phpstan_turbo-%d.%d%s.%s', | ||
| $platformDirectory, | ||
| PHP_MAJOR_VERSION, | ||
| PHP_MINOR_VERSION, | ||
| (bool) PHP_ZTS ? '-zts' : '', | ||
|
|
@@ -118,6 +125,34 @@ public static function findExtension(): ?string | |
| return $file; | ||
| } | ||
|
|
||
| /** | ||
| * The directory of turbo-ext/ next to the running phar that holds the | ||
| * binaries for this platform, whether it exists or not. Null when no | ||
| * binary is built for this runtime: PHP older than the minimum, a debug | ||
| * build, a run from source, or a platform without binaries. | ||
| */ | ||
| private static function getPlatformDirectoryNextToPhar(): ?string | ||
| { | ||
| if (PHP_VERSION_ID < self::MINIMUM_PHP_VERSION_ID) { | ||
| return null; | ||
| } | ||
| if ((bool) PHP_DEBUG) { | ||
| return null; | ||
| } | ||
|
|
||
| $pharPath = Phar::running(false); | ||
| if ($pharPath === '') { | ||
| return null; | ||
| } | ||
|
|
||
| $platform = self::resolvePlatformDirectory(PHP_OS_FAMILY, php_uname('m'), self::isMusl()); | ||
| if ($platform === null) { | ||
| return null; | ||
| } | ||
|
|
||
| return sprintf('%s/turbo-ext/%s', dirname($pharPath), $platform); | ||
| } | ||
|
|
||
| /** | ||
| * The shared core the extension binary loads, in the same directory. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same
shivammathur/setup-phpaction, pinned to the same commit, thatphar.ymlalready uses in 13 other steps. The new job needs PHP 8.3 or newer, so it installs PHP the same way as the other jobs.