summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/DependencyFile.cpp
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-10-19 23:53:27 +0000
committerPeter Wu <peter@lekensteyn.nl>2017-10-19 23:53:27 +0000
commit90161dad75f4a47cd4af6891f1664bb04a1c52ec (patch)
tree7a23e7ed22ce8ec467bd35a762a6281ad9921e25 /clang/lib/Frontend/DependencyFile.cpp
parentb2f894ff2275a04324b68dc7f327b9fa88dc50bd (diff)
downloadbcm5719-llvm-90161dad75f4a47cd4af6891f1664bb04a1c52ec.tar.gz
bcm5719-llvm-90161dad75f4a47cd4af6891f1664bb04a1c52ec.zip
Try to shorten system header paths when using -MD depfiles
GCC tries to shorten system headers in depfiles using its real path (resolving components like ".." and following symlinks). Mimic this feature to ensure that the Ninja build tool detects the correct dependencies when a symlink changes directory levels, see https://github.com/ninja-build/ninja/issues/1330 An option to disable this feature is added in case "these changed header paths may conflict with some compilation environments", see https://gcc.gnu.org/ml/gcc-patches/2012-09/msg00287.html Note that the original feature request for GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52974) also included paths preprocessed output (-E) and diagnostics. That is not implemented now since I am not sure if it breaks something else. Differential Revision: https://reviews.llvm.org/D37954 llvm-svn: 316193
Diffstat (limited to 'clang/lib/Frontend/DependencyFile.cpp')
-rw-r--r--clang/lib/Frontend/DependencyFile.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp
index 561eb9c4a31..b6e4cfa3385 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -161,6 +161,7 @@ class DFGImpl : public PPCallbacks {
bool AddMissingHeaderDeps;
bool SeenMissingHeader;
bool IncludeModuleFiles;
+ bool CanonicalSystemHeaders;
DependencyOutputFormat OutputFormat;
private:
@@ -176,6 +177,7 @@ public:
AddMissingHeaderDeps(Opts.AddMissingHeaderDeps),
SeenMissingHeader(false),
IncludeModuleFiles(Opts.IncludeModuleFiles),
+ CanonicalSystemHeaders(Opts.CanonicalSystemHeaders),
OutputFormat(Opts.OutputFormat) {
for (const auto &ExtraDep : Opts.ExtraDeps) {
AddFilename(ExtraDep);
@@ -288,6 +290,15 @@ void DFGImpl::FileChanged(SourceLocation Loc,
if (!FileMatchesDepCriteria(Filename.data(), FileType))
return;
+ // Try to shorten system header paths like GCC does (unless
+ // -fno-canonical-system-headers is given).
+ if (CanonicalSystemHeaders && isSystem(FileType)) {
+ StringRef RealPath = FE->tryGetRealPathName();
+ if (!RealPath.empty() && RealPath.size() < Filename.size()) {
+ Filename = RealPath;
+ }
+ }
+
AddFilename(llvm::sys::path::remove_leading_dotslash(Filename));
}
OpenPOWER on IntegriCloud