-
Notifications
You must be signed in to change notification settings - Fork 585
Store result cache paths relative to the install location #6190
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: 2.2.x
Are you sure you want to change the base?
Changes from all commits
79bb38d
e5a2d61
c91bda0
ee12a4f
71e33f2
1733fb1
62c757f
9e1943f
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 |
|---|---|---|
|
|
@@ -410,6 +410,46 @@ jobs: | |
| echo "$OUTPUT" | ||
| ../bashunit -a contains 'Composer metadata changed but no package versions changed; keeping the result cache.' "$OUTPUT" | ||
| ../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT" | ||
| - script: | | ||
| cd e2e/result-cache-relative-path | ||
| # Cold run: paths are stored relative to the phpstan install (the anchor), so the cache | ||
| # no longer embeds the absolute checkout path. Assert the analysed file is NOT stored under | ||
| # its absolute checkout path (i.e. it was relativized). | ||
| ../../bin/phpstan analyse | ||
| if grep -q "'$(pwd)/src/HelloWorld.php'" tmp/resultCache.php; then echo 'cache still holds an absolute analysed path'; exit 1; fi | ||
| # Warm run: the relative cache re-absolutizes against the current anchor and is fully reused. | ||
| OUTPUT=$(../bashunit -a exit_code "0" "../../bin/phpstan analyse -vv") | ||
| echo "$OUTPUT" | ||
| ../bashunit -a contains 'Result cache restored. 0 files will be reanalysed.' "$OUTPUT" | ||
| - script: | | ||
| cd e2e/result-cache-relative-path | ||
| MAIN="$(pwd)" | ||
| # Warm the cache in this checkout; paths are stored relative to the phpstan install, so the | ||
| # cache is portable to another checkout with the same layout. | ||
| ../../bin/phpstan analyse | ||
| # A git worktree is a second checkout of the same repo at a different absolute path. Give it | ||
| # its own phpstan install (vendor) so %rootDir% points at the worktree, and carry the warm | ||
| # cache across. The copy stands in for cache discovery, which is a follow-up and not part of | ||
| # this PR; a real setup would CoW-clone the checkout or share the tmpDir. | ||
| WORKTREE="$(mktemp -d)/phpstan" | ||
| git -C ../.. worktree add --detach "$WORKTREE" HEAD | ||
| cp -al ../../vendor "$WORKTREE/vendor" | ||
| cp -R tmp "$WORKTREE/e2e/result-cache-relative-path/tmp" | ||
| rm -rf "$WORKTREE/e2e/result-cache-relative-path/tmp/cache" | ||
|
Comment on lines
+436
to
+438
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. did I understand it right, that we need this copying because this PR is not going to implement the whole feature in a single shot?
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. Yes, exactly. The copy stands in for cache discovery, PHPStan locating the main checkout's warm cache from a fresh worktree, which is the harder part and a deliberate follow-up, not this PR. This PR makes the cache content portable so it can be reused once it is present; getting it present in a bare worktree is the separate step. I noted it in the code comment and the PR description. |
||
| # Running in the worktree (a different absolute prefix) must re-absolutize the relative cache | ||
| # against the worktree and reuse it, with 0 files reanalysed. | ||
| cd "$WORKTREE/e2e/result-cache-relative-path" | ||
| # -vv progress (incl. "Result cache restored") goes to stderr, so capture both streams | ||
| OUTPUT=$(../../bin/phpstan analyse -vv 2>&1) | ||
| echo "$OUTPUT" | ||
| echo "$OUTPUT" | grep -q 'Result cache restored. 0 files will be reanalysed.' || { echo 'result cache was not reused in the git worktree'; exit 1; } | ||
|
staabm marked this conversation as resolved.
|
||
| # Remove the worktree and confirm the original checkout still reuses its own cache, i.e. | ||
| # running phpstan in a different worktree in between did not disturb it. | ||
| cd "$MAIN" | ||
| git -C ../.. worktree remove --force "$WORKTREE" | ||
| OUTPUT=$(../bashunit -a exit_code "0" "../../bin/phpstan analyse -vv") | ||
| echo "$OUTPUT" | ||
| ../bashunit -a contains 'Result cache restored. 0 files will be reanalysed.' "$OUTPUT" | ||
| - script: | | ||
| cd e2e/result-cache-package-update | ||
| composer install | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /tmp |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| parameters: | ||
| level: 8 | ||
| tmpDir: tmp | ||
| paths: | ||
| - src |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace RelativePathResultCache; | ||
|
|
||
| class HelloWorld | ||
| { | ||
|
|
||
| public function sayHello(string $name): string | ||
| { | ||
| return sprintf('Hello, %s', $name); | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.