-
Notifications
You must be signed in to change notification settings - Fork 545
use a separate resultCache per project config file #1469
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
base: 1.8.x
Are you sure you want to change the base?
Changes from all commits
ccf2063
a633809
bab9ff0
3e83afc
1f90cc2
e24b20e
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 |
|---|---|---|
|
|
@@ -27,11 +27,13 @@ | |
| use function array_unique; | ||
| use function array_values; | ||
| use function count; | ||
| use function dirname; | ||
| use function get_loaded_extensions; | ||
| use function is_array; | ||
| use function is_file; | ||
| use function is_string; | ||
| use function ksort; | ||
| use function md5; | ||
| use function sha1; | ||
| use function sort; | ||
| use function sprintf; | ||
|
|
@@ -99,11 +101,10 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? | |
| return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], []); | ||
| } | ||
|
|
||
| $cacheFilePath = $this->cacheFilePath; | ||
| $cacheFilePath = $this->getCacheFilePath($resultCacheName, $projectConfigArray); | ||
| if ($resultCacheName !== null) { | ||
| $tmpCacheFile = $this->tempResultCachePath . '/' . $resultCacheName . '.php'; | ||
| if (is_file($tmpCacheFile)) { | ||
| $cacheFilePath = $tmpCacheFile; | ||
| if (!is_file($cacheFilePath)) { | ||
| $cacheFilePath = $this->cacheFilePath; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -578,16 +579,13 @@ private function save( | |
|
|
||
| ksort($exportedNodes); | ||
|
|
||
| $file = $this->cacheFilePath; | ||
| if ($resultCacheName !== null) { | ||
| $file = $this->tempResultCachePath . '/' . $resultCacheName . '.php'; | ||
| } | ||
|
|
||
| $projectConfigArray = $meta['projectConfig']; | ||
| if ($projectConfigArray !== null) { | ||
| $meta['projectConfig'] = Neon::encode($projectConfigArray); | ||
| } | ||
|
|
||
| $file = $this->getCacheFilePath($resultCacheName, $projectConfigArray); | ||
|
|
||
| FileWriter::write( | ||
| $file, | ||
| sprintf( | ||
|
|
@@ -603,6 +601,27 @@ private function save( | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed[]|null $projectConfig | ||
| */ | ||
| private function getCacheFilePath(?string $resultCacheName, ?array $projectConfig): string | ||
| { | ||
| if ($resultCacheName !== null) { | ||
| return $this->tempResultCachePath . '/' . $resultCacheName . '.php'; | ||
| } | ||
|
|
||
| if ($projectConfig !== null && | ||
| array_key_exists('parameters', $projectConfig) && | ||
| !array_key_exists('resultCachePath', $projectConfig['parameters']) && | ||
| (!array_key_exists('tmpDir', $projectConfig['parameters']) || $projectConfig['parameters']['tmpDir'] === null) | ||
|
||
| ) { | ||
|
|
||
| return dirname($this->cacheFilePath) . '/resultCache-' . md5(Neon::encode([$this->analysedPaths, ComposerHelper::getPhpStanVersion()])) . '.php'; | ||
| } | ||
|
|
||
| return $this->cacheFilePath; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed[]|null $projectConfig | ||
| * @param array<string, mixed> $dependencies | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,11 @@ | |
| use PHPUnit\Framework\TestCase; | ||
| use function array_map; | ||
| use function chdir; | ||
| use function count; | ||
| use function escapeshellarg; | ||
| use function exec; | ||
| use function file_put_contents; | ||
| use function glob; | ||
| use function implode; | ||
| use function ksort; | ||
| use function sort; | ||
|
|
@@ -136,6 +138,15 @@ public function testResultCachePath(): void | |
| $this->assertResultCache(__DIR__ . '/resultCache_1.php', sys_get_temp_dir() . '/phpstan/myResultCacheFile.php'); | ||
| } | ||
|
|
||
| public function testSeparateResultCachePath(): void | ||
| { | ||
| $this->runPhpstan(0, __DIR__ . '/phpstan_separate_cache.neon'); | ||
|
|
||
| $resultCacheFiles = glob(sys_get_temp_dir() . '/phpstan/resultCache-*.php'); | ||
|
||
| $this->assertNotFalse($resultCacheFiles); | ||
| $this->assertTrue(count($resultCacheFiles) > 0); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed[] | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # test whether a config, which does not define tmpDir or resultCachePath, will get a separate md5-hashed result cache | ||
|
|
||
| includes: | ||
| - baseline.neon | ||
|
|
||
| parameters: | ||
| level: 2 |
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 condition is covered by #1475