Skip to content

Commit 38fc844

Browse files
authored
Merge pull request #11270 from vimeo/latest_patch_version
Force usage of latest patch version to avoid JIT bugs
2 parents 4bc6e99 + b63a208 commit 38fc844

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/Psalm/Internal/Analyzer/ProjectAnalyzer.php

+20-19
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
use function number_format;
7878
use function preg_match;
7979
use function rename;
80-
use function sprintf;
8180
use function str_ends_with;
8281
use function str_starts_with;
8382
use function strlen;
@@ -87,6 +86,7 @@
8786
use function usort;
8887

8988
use const PHP_EOL;
89+
use const PHP_VERSION;
9090
use const PSALM_VERSION;
9191
use const STDERR;
9292

@@ -280,7 +280,7 @@ private function clearCacheDirectoryIfConfigOrComposerLockfileChanged(): void
280280
clearstatcache(true, $cache_directory);
281281
if (is_dir($cache_directory)) {
282282
$this->progress->debug(
283-
'Composer lockfile change detected, clearing cache directory ' . $cache_directory . "\n",
283+
'Composer lockfile change detected, clearing cache directory ' . $cache_directory . PHP_EOL,
284284
);
285285

286286
Config::removeCacheDirectory($cache_directory);
@@ -297,7 +297,7 @@ private function clearCacheDirectoryIfConfigOrComposerLockfileChanged(): void
297297
clearstatcache(true, $cache_directory);
298298
if (is_dir($cache_directory)) {
299299
$this->progress->debug(
300-
'Config change detected, clearing cache directory ' . $cache_directory . "\n",
300+
'Config change detected, clearing cache directory ' . $cache_directory . PHP_EOL,
301301
);
302302

303303
Config::removeCacheDirectory($cache_directory);
@@ -350,7 +350,7 @@ private function visitAutoloadFiles(): void
350350
$now_time = microtime(true);
351351

352352
$this->progress->debug(
353-
'Visiting autoload files took ' . number_format($now_time - $start_time, 3) . 's' . "\n",
353+
'Visiting autoload files took ' . number_format($now_time - $start_time, 3) . 's' . PHP_EOL,
354354
);
355355
}
356356

@@ -411,12 +411,11 @@ private function generatePHPVersionMessage(): string
411411
$codebase->config->php_extensions_supported_by_psalm_callmaps,
412412
);
413413

414-
$message = sprintf(
415-
"Target PHP version: %d.%d %s",
416-
$codebase->getMajorAnalysisPhpVersion(),
417-
$codebase->getMinorAnalysisPhpVersion(),
418-
$source,
419-
);
414+
$message = "Target PHP version: "
415+
.$codebase->getMajorAnalysisPhpVersion()."."
416+
.$codebase->getMinorAnalysisPhpVersion()." "
417+
.$source
418+
;
420419

421420
$enabled_extensions_names = array_keys(array_filter($codebase->config->php_extensions));
422421
if (count($enabled_extensions_names) > 0) {
@@ -427,7 +426,9 @@ private function generatePHPVersionMessage(): string
427426
$message .= ' (unsupported extensions: ' . implode(', ', $unsupported_php_extensions) . ')';
428427
}
429428

430-
return "$message.\n";
429+
$message .= '.'.PHP_EOL.PHP_EOL."Running on PHP ".PHP_VERSION.'.'.PHP_EOL.PHP_EOL;
430+
431+
return $message;
431432
}
432433

433434
public function check(string $base_dir, bool $is_diff = false): void
@@ -479,8 +480,8 @@ public function check(string $base_dir, bool $is_diff = false): void
479480
$this->codebase->infer_types_from_usage = true;
480481
} else {
481482
$this->codebase->diff_run = true;
482-
$this->progress->debug(count($diff_files) . ' changed files: ' . "\n");
483-
$this->progress->debug(' ' . implode("\n ", $diff_files) . "\n");
483+
$this->progress->debug(count($diff_files) . ' changed files: ' . PHP_EOL);
484+
$this->progress->debug(' ' . implode(PHP_EOL." ", $diff_files) . PHP_EOL);
484485

485486
$this->codebase->analyzer->addFilesToShowResults($this->project_files);
486487

@@ -528,7 +529,7 @@ public function check(string $base_dir, bool $is_diff = false): void
528529
$removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches($start_checks);
529530

530531
if ($removed_parser_files) {
531-
$this->progress->debug('Removed ' . $removed_parser_files . ' old parser caches' . "\n");
532+
$this->progress->debug('Removed ' . $removed_parser_files . ' old parser caches' . PHP_EOL);
532533
}
533534
}
534535
}
@@ -851,14 +852,14 @@ public function findReferencesTo(string $symbol): void
851852
$selection_start = $selection_bounds[0] - $snippet_bounds[0];
852853
$selection_length = $selection_bounds[1] - $selection_bounds[0];
853854

854-
echo $location->file_name . ':' . $location->getLineNumber() . "\n" .
855+
echo $location->file_name . ':' . $location->getLineNumber() . PHP_EOL .
855856
(
856857
$this->stdout_report_options->use_color
857858
? substr($snippet, 0, $selection_start) .
858859
"\e[97;42m" . substr($snippet, $selection_start, $selection_length) .
859860
"\e[0m" . substr($snippet, $selection_length + $selection_start)
860861
: $snippet
861-
) . "\n" . "\n";
862+
) . PHP_EOL . PHP_EOL;
862863
}
863864
}
864865

@@ -947,7 +948,7 @@ private function checkDiffFilesWithConfig(Config $config, array $file_list = [])
947948
}
948949

949950
if (!$config->isInProjectDirs($file_path)) {
950-
$this->progress->debug('skipping ' . $file_path . "\n");
951+
$this->progress->debug('skipping ' . $file_path . PHP_EOL);
951952

952953
continue;
953954
}
@@ -960,7 +961,7 @@ private function checkDiffFilesWithConfig(Config $config, array $file_list = [])
960961

961962
public function checkFile(string $file_path): void
962963
{
963-
$this->progress->debug('Checking ' . $file_path . "\n");
964+
$this->progress->debug('Checking ' . $file_path . PHP_EOL);
964965

965966
$this->config->visitPreloadedStubFiles($this->codebase, $this->progress);
966967

@@ -1003,7 +1004,7 @@ public function checkPaths(array $paths_to_check): void
10031004
$this->codebase->scanner->addFilesToShallowScan($this->extra_files);
10041005

10051006
foreach ($paths_to_check as $path) {
1006-
$this->progress->debug('Checking ' . $path . "\n");
1007+
$this->progress->debug('Checking ' . $path . PHP_EOL);
10071008

10081009
if (is_dir($path)) {
10091010
$this->checkDirWithConfig($path, $this->config, true);

src/Psalm/Internal/CliUtils.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,6 @@ public static function runningInCI(): bool
524524

525525
public static function checkRuntimeRequirements(): void
526526
{
527-
$required_php_version = 8_01_17;
528-
$required_php_version_text = '8.1.17';
529-
530527
// the following list was taken from vendor/composer/platform_check.php
531528
// It includes both Psalm's requirements (from composer.json) and the
532529
// requirements of our dependencies `netresearch/jsonmapper` and
@@ -545,9 +542,21 @@ public static function checkRuntimeRequirements(): void
545542
];
546543
$issues = [];
547544

548-
if (PHP_VERSION_ID < $required_php_version) {
549-
$issues[] = 'Psalm requires a PHP version ">= ' . $required_php_version_text . '".'
545+
$major_minor = PHP_VERSION_ID - (PHP_VERSION_ID % 100);
546+
foreach ([
547+
8_01_31 => '8.1.31',
548+
8_02_27 => '8.2.27',
549+
8_03_16 => '8.3.16',
550+
8_04_03 => '8.4.3',
551+
] as $version => $txt) {
552+
$version_m = $version - ($version % 100);
553+
if ($version_m === $major_minor) {
554+
if (PHP_VERSION_ID < $version) {
555+
$issues[] = 'Psalm requires a PHP version ">= ' . $txt . '".'
550556
. ' You are running ' . PHP_VERSION . '.';
557+
}
558+
break;
559+
}
551560
}
552561

553562
$missing_extensions = array_filter(

0 commit comments

Comments
 (0)