forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 354
[clang][cas] Fix caching builds with -fdiagnostics-absolute-paths #12033
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
Open
benlangmuir
wants to merge
2
commits into
next
Choose a base branch
from
eng/blangmuir/fdiagnostics-absolute-paths-cas
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+83
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // RUN: rm -rf %t | ||
| // RUN: split-file %s %t | ||
| // RUN: cd %t | ||
| // RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \ | ||
| // RUN: %clang subdir/tu.c -I. -fdiagnostics-absolute-paths -E \ | ||
| // RUN: -Rcompile-job-cache > %t/stdout-miss 2> %t/stderr-miss | ||
| // RUN: FileCheck %s -DPREFIX=%/t -check-prefix=PP -input-file=%t/stdout-miss | ||
| // RUN: FileCheck %s -DPREFIX=%/t -check-prefix=DIAG -input-file=%t/stderr-miss | ||
| // RUN: FileCheck %s -DPREFIX=%/t -check-prefix=MISS -input-file=%t/stderr-miss | ||
|
|
||
| // Again, but with a cache hit. | ||
| // RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \ | ||
| // RUN: %clang subdir/tu.c -I. -fdiagnostics-absolute-paths -E \ | ||
| // RUN: -Rcompile-job-cache > %t/stdout-hit 2> %t/stderr-hit | ||
| // RUN: FileCheck %s -DPREFIX=%/t -check-prefix=PP -input-file=%t/stdout-hit | ||
| // RUN: FileCheck %s -DPREFIX=%/t -check-prefix=DIAG -input-file=%t/stderr-hit | ||
| // RUN: FileCheck %s -DPREFIX=%/t -check-prefix=HIT -input-file=%t/stderr-hit | ||
|
|
||
| // Preprocessor does not force absolute paths. | ||
| // PP: # 1 "subdir/tu.c" | ||
| // PP: # 1 "./h1.h" | ||
| // PP: const char *filename = "./h1.h"; | ||
|
|
||
| // Diagnostics force absolute paths. | ||
| // DIAG: [[PREFIX]]/subdir/tu.c:1:2: warning: "from tu" | ||
| // DIAG: In file included from [[PREFIX]]/subdir/tu.c | ||
| // DIAG: [[PREFIX]]/h1.h:1:2: warning: "from h1" | ||
|
|
||
| // MISS: remark: compile job cache miss | ||
| // HIT: remark: compile job cache hit | ||
|
|
||
| //--- subdir/tu.c | ||
| #warning "from tu" | ||
| #include "h1.h" | ||
|
|
||
| //--- h1.h | ||
| #warning "from h1" | ||
| const char *filename = __FILE__; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you explain again with
llvm::sys::path::make_absoluteis not sufficient here?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.
My goal for this PR is to match the behaviour without caching, which uses getCanonicalName -> getRealPath.
As to why it's done this way in the first place: I dug through the history of changes and review comments on this code and it seems like the motivation is to eliminate . and .. components in paths, which seems to be motivated by two issues: 1) some editors apparently were opening a separate tab for (a/b/../c and a/c), and 2) there are some cases where the extra dots make the absolute path really long. The code on Windows handles this directly, but it's not correct on other systems.
As a separate change, I am thinking of proposing that this behaviour change to make it instead do basically what Windows is doing (make absolute and remove dots), but add an additional check on non-Windows system that the two paths resolve to the same file. That will hopefully be cheaper in most cases, since stat() will be cheaper than realpath(). If the paths really are different files then we can fallback to only removing single dots. Even if there is some possibility it leaves some of the file paths "too long" in rare situations with symlinks, it seems like a better tradeoff to me overall.