Skip to content

Commit 15cbae6

Browse files
[IncludeTree] Support DepScan using IncludeTree and ModuleName
Teach IncludeTreeDepScanning to support ModuleName inputs. (cherry picked from commit d1caf7e)
1 parent 7733a79 commit 15cbae6

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ void GetDependenciesByModuleNameAction::ExecuteAction() {
11951195
Preprocessor &PP = CI.getPreprocessor();
11961196
SourceManager &SM = PP.getSourceManager();
11971197
FileID MainFileID = SM.getMainFileID();
1198+
PP.EnterSourceFile(MainFileID, nullptr, SourceLocation());
11981199
SourceLocation FileStart = SM.getLocForStartOfFile(MainFileID);
11991200
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
12001201
IdentifierInfo *ModuleID = PP.getIdentifierInfo(ModuleName);

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
2828
#include "clang/Tooling/DependencyScanning/ScanAndUpdateArgs.h"
2929
#include "clang/Tooling/Tooling.h"
30+
#include "llvm/CAS/CASProvidingFileSystem.h"
3031
#include "llvm/CAS/CachingOnDiskFileSystem.h"
3132
#include "llvm/CAS/ObjectStore.h"
3233
#include "llvm/Support/Allocator.h"
@@ -641,8 +642,6 @@ bool DependencyScanningWorker::computeDependencies(
641642
auto InMemoryFS =
642643
llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
643644
InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
644-
OverlayFS->pushOverlay(InMemoryFS);
645-
ModifiedFS = OverlayFS;
646645

647646
SmallString<128> FakeInputPath;
648647
// TODO: We should retry the creation if the path already exists.
@@ -651,6 +650,16 @@ bool DependencyScanningWorker::computeDependencies(
651650
/*MakeAbsolute=*/false);
652651
InMemoryFS->addFile(FakeInputPath, 0, llvm::MemoryBuffer::getMemBuffer(""));
653652

653+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> InMemoryOverlay =
654+
InMemoryFS;
655+
// If we are using a CAS but not dependency CASFS, we need to provide the
656+
// fake input file in a CASProvidingFS for include-tree.
657+
if (CAS && !DepCASFS)
658+
InMemoryOverlay =
659+
llvm::cas::createCASProvidingFileSystem(CAS, std::move(InMemoryFS));
660+
661+
OverlayFS->pushOverlay(InMemoryOverlay);
662+
ModifiedFS = OverlayFS;
654663
ModifiedCommandLine = CommandLine;
655664
ModifiedCommandLine->emplace_back(FakeInputPath);
656665
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// UNSUPPORTED: target=powerpc64-ibm-aix{{.*}}
2+
// REQUIRES: ondisk_cas
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
//--- module.modulemap
8+
module root { header "root.h" }
9+
module direct { header "direct.h" }
10+
module transitive { header "transitive.h" }
11+
//--- root.h
12+
#include "direct.h"
13+
#include "root/textual.h"
14+
//--- direct.h
15+
#include "transitive.h"
16+
//--- transitive.h
17+
// empty
18+
19+
//--- root/textual.h
20+
// This is here to verify that the "root" directory doesn't clash with name of
21+
// the "root" module.
22+
23+
//--- cdb.json.template
24+
[{
25+
"file": "",
26+
"directory": "DIR",
27+
"command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR -x c"
28+
}]
29+
30+
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
31+
// RUN: clang-scan-deps -compilation-database %t/cdb.json \
32+
// RUN: -cas-path %t/cas -format experimental-include-tree-full -module-name=root > %t/result.json
33+
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
34+
35+
// CHECK: {
36+
// CHECK-NEXT: "modules": [
37+
// CHECK-NEXT: {
38+
// CHECK-NEXT: "cache-key": "[[DIRECT_CACHE_KEY:llvmcas://[[:xdigit:]]+]]"
39+
// CHECK-NEXT: "cas-include-tree-id": "[[LEFT_ROOT_ID:llvmcas://[[:xdigit:]]+]]"
40+
// CHECK-NEXT: "clang-module-deps": [
41+
// CHECK-NEXT: {
42+
// CHECK-NEXT: "context-hash": "{{.*}}",
43+
// CHECK-NEXT: "module-name": "transitive"
44+
// CHECK-NEXT: }
45+
// CHECK-NEXT: ],
46+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
47+
// CHECK-NEXT: "command-line": [
48+
// CHECK: "-fmodule-file-cache-key"
49+
// CHECK-NEXT: "{{.*transitive-.*\.pcm}}"
50+
// CHECK-NEXT: "[[TRANSITIVE_CACHE_KEY:llvmcas://[[:xdigit:]]+]]"
51+
// CHECK: ],
52+
// CHECK-NEXT: "context-hash": "{{.*}}",
53+
// CHECK-NEXT: "file-deps": [
54+
// CHECK-NEXT: "[[PREFIX]]/direct.h"
55+
// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
56+
// CHECK-NEXT: ],
57+
// CHECK-NEXT: "name": "direct"
58+
// CHECK-NEXT: },
59+
// CHECK-NEXT: {
60+
// CHECK-NEXT: "cache-key": "[[ROOT_CACHE_KEY:llvmcas://[[:xdigit:]]+]]"
61+
// CHECK-NEXT: "cas-include-tree-id": "[[ROOT_ROOT_ID:llvmcas://[[:xdigit:]]+]]"
62+
// CHECK-NEXT: "clang-module-deps": [
63+
// CHECK-NEXT: {
64+
// CHECK-NEXT: "context-hash": "{{.*}}",
65+
// CHECK-NEXT: "module-name": "direct"
66+
// CHECK-NEXT: }
67+
// CHECK-NEXT: ],
68+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
69+
// CHECK-NEXT: "command-line": [
70+
// CHECK: "-fmodule-file-cache-key"
71+
// CHECK-NEXT: "{{.*direct-.*\.pcm}}"
72+
// CHECK-NEXT: "[[DIRECT_CACHE_KEY]]"
73+
// CHECK: ],
74+
// CHECK-NEXT: "context-hash": "{{.*}}",
75+
// CHECK-NEXT: "file-deps": [
76+
// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
77+
// CHECK-NEXT: "[[PREFIX]]/root.h"
78+
// CHECK-NEXT: "[[PREFIX]]/root/textual.h"
79+
// CHECK-NEXT: ],
80+
// CHECK-NEXT: "name": "root"
81+
// CHECK-NEXT: },
82+
// CHECK-NEXT: {
83+
// CHECK-NEXT: "cache-key": "[[TRANSITIVE_CACHE_KEY]]"
84+
// CHECK-NEXT: "cas-include-tree-id": "[[TRANSITIVE_ROOT_ID:llvmcas://[[:xdigit:]]+]]"
85+
// CHECK-NEXT: "clang-module-deps": [],
86+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
87+
// CHECK-NEXT: "command-line": [
88+
// CHECK: ],
89+
// CHECK-NEXT: "context-hash": "{{.*}}",
90+
// CHECK-NEXT: "file-deps": [
91+
// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
92+
// CHECK-NEXT: "[[PREFIX]]/transitive.h"
93+
// CHECK-NEXT: ],
94+
// CHECK-NEXT: "name": "transitive"
95+
// CHECK-NEXT: }
96+
// CHECK-NEXT: ],
97+
// CHECK-NEXT: "translation-units": []
98+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)