Skip to content

Commit c3ec155

Browse files
committed
[clang][modules] Test for llvm#139751 (#10661)
The input file section in module files only stored files loaded into the `SourceManager`. When rebuilding the module cache, include-trees also include other files, like the SDKSettings.json file. If we don't invalidate the module cache when that file changes, the corresponding include-trees won't agree with the primary TU include-tree on the file contents. This was fixed in llvm#139751 and this PR adds an include tree test. I intentionally suppress reporting of this new file in tests, so that I don't have go updating ~all of them. This file is getting reported by the scanning C API, so that the build system is given the ability to eventually act on this file being out-of-date. rdar://149868539
1 parent 286f675 commit c3ec155

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This test checks that the module cache gets invalidated when the
2+
// SDKSettings.json file changes. This prevents "file changed during build"
3+
// errors when the TU does get rescanned and recompiled.
4+
5+
// REQUIRES: ondisk_cas
6+
7+
// RUN: rm -rf %t
8+
// RUN: split-file %s %t
9+
10+
//--- sdk/SDKSettings.json
11+
{
12+
"Version": "11.0",
13+
"MaximumDeploymentTarget": "11.0.99"
14+
}
15+
16+
//--- module.modulemap
17+
module M { header "M.h" }
18+
//--- M.h
19+
//--- tu.c
20+
#include "M.h"
21+
22+
// RUN: clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -o %t/deps_clean.json \
23+
// RUN: -- %clang -target x86_64-apple-macos11 -isysroot %t/sdk \
24+
// RUN: -c %t/tu.c -o %t/tu.o -fmodules -fmodules-cache-path=%t/cache
25+
26+
// RUN: sleep 1
27+
// RUN: echo " " >> %t/sdk/SDKSettings.json
28+
// RUN: echo " " >> %t/tu.c
29+
30+
// RUN: clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -o %t/deps_incremental.json \
31+
// RUN: -- %clang -target x86_64-apple-macos11 -isysroot %t/sdk \
32+
// RUN: -c %t/tu.c -o %t/tu.o -fmodules -fmodules-cache-path=%t/cache
33+
34+
// RUN: %deps-to-rsp %t/deps_incremental.json --module-name M > %t/M.rsp
35+
// RUN: %deps-to-rsp %t/deps_incremental.json --tu-index 0 > %t/tu.rsp
36+
// RUN: %clang @%t/M.rsp
37+
// RUN: %clang @%t/tu.rsp

clang/tools/c-index-test/core_main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,10 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
850850
llvm::outs() << " " << ModuleName << "\n";
851851
llvm::outs() << " file-deps:\n";
852852
for (const auto &FileName : ArrayRef(FileDeps.Strings, FileDeps.Count))
853-
llvm::outs() << " " << FileName << "\n";
853+
// Not reporting SDKSettings.json so that test checks can remain
854+
// (mostly) platform-agnostic.
855+
if (!StringRef(FileName).ends_with("SDKSettings.json"))
856+
llvm::outs() << " " << FileName << "\n";
854857
llvm::outs() << " build-args:";
855858
for (const auto &Arg :
856859
ArrayRef(BuildArguments.Strings, BuildArguments.Count))

0 commit comments

Comments
 (0)