1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #4464 - bust cache when Psalm’s version changes, not just composer’s

This commit is contained in:
Matt Brown 2020-11-01 09:01:43 -05:00 committed by Daniil Gentili
parent afc38b841c
commit 9d35e3c251
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 13 additions and 9 deletions

View File

@ -640,7 +640,7 @@ class ProjectAnalyzer
if ($this->project_cache_provider && $this->parser_cache_provider) { if ($this->project_cache_provider && $this->parser_cache_provider) {
$removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches( $removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches(
$is_diff ? $this->project_cache_provider->getLastRun() : $start_checks $is_diff ? $this->project_cache_provider->getLastRun(\PSALM_VERSION) : $start_checks
); );
if ($removed_parser_files) { if ($removed_parser_files) {
@ -1069,7 +1069,7 @@ class ProjectAnalyzer
$diff_files = []; $diff_files = [];
$last_run = $this->project_cache_provider->getLastRun(); $last_run = $this->project_cache_provider->getLastRun(\PSALM_VERSION);
$file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions); $file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions);

View File

@ -40,7 +40,7 @@ class ProjectCacheProvider
return $cache_directory && file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME); return $cache_directory && file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME);
} }
public function processSuccessfulRun(float $start_time): void public function processSuccessfulRun(float $start_time, string $psalm_version): void
{ {
$cache_directory = Config::getInstance()->getCacheDirectory(); $cache_directory = Config::getInstance()->getCacheDirectory();
@ -50,16 +50,20 @@ class ProjectCacheProvider
$run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME; $run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME;
file_put_contents($run_cache_location, $psalm_version);
\touch($run_cache_location, (int)$start_time); \touch($run_cache_location, (int)$start_time);
} }
public function getLastRun(): int public function getLastRun(string $psalm_version): int
{ {
if ($this->last_run === null) { if ($this->last_run === null) {
$cache_directory = Config::getInstance()->getCacheDirectory(); $cache_directory = Config::getInstance()->getCacheDirectory();
if (file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME)) { $run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME;
$this->last_run = \filemtime($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME);
if (file_exists($run_cache_location) && file_get_contents($run_cache_location) === $psalm_version) {
$this->last_run = \filemtime($run_cache_location);
} else { } else {
$this->last_run = 0; $this->last_run = 0;
} }

View File

@ -669,7 +669,7 @@ class IssueBuffer
$codebase->file_reference_provider->removeDeletedFilesFromReferences(); $codebase->file_reference_provider->removeDeletedFilesFromReferences();
if ($project_analyzer->project_cache_provider) { if ($project_analyzer->project_cache_provider) {
$project_analyzer->project_cache_provider->processSuccessfulRun($start_time); $project_analyzer->project_cache_provider->processSuccessfulRun($start_time, \PSALM_VERSION);
} }
if ($codebase->statements_provider->parser_cache_provider) { if ($codebase->statements_provider->parser_cache_provider) {

View File

@ -12,12 +12,12 @@ class ProjectCacheProvider extends \Psalm\Internal\Provider\ProjectCacheProvider
{ {
} }
public function getLastRun(): int public function getLastRun(string $psalm_version): int
{ {
return $this->last_run; return $this->last_run;
} }
public function processSuccessfulRun(float $start_time): void public function processSuccessfulRun(float $start_time, string $psalm_version): void
{ {
$this->last_run = (int) $start_time; $this->last_run = (int) $start_time;
} }