[clang] Canonicalize system headers in dependency file when -canonical-prefixes
authorArthur Eubanks <aeubanks@google.com>
Tue, 25 Apr 2023 20:16:01 +0000 (13:16 -0700)
committerArthur Eubanks <aeubanks@google.com>
Mon, 1 May 2023 17:40:18 +0000 (10:40 -0700)
commit8f0dd4ef3ed2137d1e2554204127434fc46ee190
treee0c829e03af0cdd899d55a6716b9cdceb728ee5c
parent49df068836bfbb538771395d8bb293548afd414e
[clang] Canonicalize system headers in dependency file when -canonical-prefixes

Clang was writing paths to the dependency file that don't exist when using a sysroot with symlinks, causing everything to get rebuilt every time. This is reproducible on Linux by creating a symlink to '/', using that as the sysroot, and trying to build something with ninja that includes the C++ stdlib (e.g. a typical build of LLVM).

This fixes https://github.com/ninja-build/ninja/issues/1330 and somewhat matches gcc.

gcc canonicalizes system headers in dependency files under a -f[no-]canonical-system-headers, but it makes more sense to look at -canonical-prefixes.

D37954 was a previous attempt at this.

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D149187
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/DependencyOutputOptions.h
clang/include/clang/Frontend/Utils.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/DependencyFile.cpp
clang/test/Driver/canonical-system-headers.c [new file with mode: 0644]
clang/test/Preprocessor/Inputs/canonical-system-headers/a.h [new file with mode: 0644]
clang/test/Preprocessor/canonical-system-headers.c [new file with mode: 0644]