File tree Expand file tree Collapse file tree 3 files changed +90
-0
lines changed
lib/Tooling/DependencyScanning Expand file tree Collapse file tree 3 files changed +90
-0
lines changed Original file line number Diff line number Diff line change @@ -816,7 +816,18 @@ IncludeTreeBuilder::getObjectForBuffer(const SrcMgr::FileInfo &FI) {
816
816
817
817
Expected<cas::ObjectRef>
818
818
IncludeTreeBuilder::addToFileList (FileManager &FM, const FileEntry *FE) {
819
+ SmallString<128 > PathStorage;
819
820
StringRef Filename = FE->getName ();
821
+ // Apply -working-directory to relative paths. This option causes filesystem
822
+ // lookups to use absolute paths, so make paths in the include-tree filesystem
823
+ // absolute to match.
824
+ if (!llvm::sys::path::is_absolute (Filename) &&
825
+ !FM.getFileSystemOpts ().WorkingDir .empty ()) {
826
+ PathStorage = Filename;
827
+ FM.FixupRelativePath (PathStorage);
828
+ Filename = PathStorage;
829
+ }
830
+
820
831
llvm::ErrorOr<std::optional<cas::ObjectRef>> CASContents =
821
832
FM.getObjectRefForFileContent (Filename);
822
833
if (!CASContents)
Original file line number Diff line number Diff line change
1
+ // RUN: rm -rf %t
2
+ // RUN: mkdir -p %t/other
3
+ // RUN: split-file %s %t
4
+ // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
5
+
6
+ // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree-full -cas-path %t/cas \
7
+ // RUN: > %t/deps.json
8
+
9
+ // Build the include-tree command
10
+ // RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
11
+ // RUN: %clang @%t/tu.rsp -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-MISS
12
+ // RUN: %clang @%t/tu.rsp -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-HIT
13
+ // RUN: ls %t/t.o
14
+
15
+ // CACHE-MISS: remark: compile job cache miss
16
+ // CACHE-HIT: remark: compile job cache hit
17
+
18
+ // RUN: cat %t/tu.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/tu.casid
19
+ // RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/tu.casid | FileCheck %s -DPREFIX=%/t
20
+
21
+ // CHECK: [[PREFIX]]/t.c llvmcas://
22
+ // CHECK: 1:1 <built-in> llvmcas://
23
+ // CHECK: 2:1 [[PREFIX]]/relative/h1.h llvmcas://
24
+ // CHECK: Files:
25
+ // CHECK: [[PREFIX]]/t.c llvmcas://
26
+ // CHECK: [[PREFIX]]/relative/h1.h llvmcas://
27
+
28
+ //--- cdb.json.template
29
+ [{
30
+ "directory" : "DIR /other ",
31
+ " command ": " clang - c t .c - I relative - working - directory DIR - o t .o ",
32
+ " file ": " DIR /t .c "
33
+ }]
34
+
35
+ //--- relative/h1.h
36
+
37
+ //--- t.c
38
+ #include "h1.h"
Original file line number Diff line number Diff line change
1
+ // RUN: rm -rf %t
2
+ // RUN: mkdir -p %t/other
3
+ // RUN: split-file %s %t
4
+ // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
5
+
6
+ // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree-full -cas-path %t/cas \
7
+ // RUN: > %t/deps.json
8
+
9
+ // Build the include-tree command
10
+ // RUN: %deps-to-rsp %t/deps.json --module H > %t/H.rsp
11
+ // RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
12
+ // RUN: %clang @%t/H.rsp -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-MISS
13
+ // RUN: %clang @%t/H.rsp -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-HIT
14
+ // RUN: %clang @%t/tu.rsp -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-MISS
15
+ // RUN: %clang @%t/tu.rsp -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-HIT
16
+
17
+ // CACHE-MISS: remark: compile job cache miss
18
+ // CACHE-HIT: remark: compile job cache hit
19
+
20
+ // RUN: cat %t/H.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/H.casid
21
+ // RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/H.casid | FileCheck %s -DPREFIX=%/t
22
+
23
+ // CHEK:C <module-includes>
24
+ // CHECK: 2:1 [[PREFIX]]/relative/h1.h llvmcas://
25
+ // CHECK: Files:
26
+ // CHECK: [[PREFIX]]/relative/h1.h llvmcas://
27
+
28
+ //--- cdb.json.template
29
+ [{
30
+ "directory" : "DIR /other ",
31
+ " command ": " clang - fsyntax - only t .c - I relative - working - directory DIR - fmodules - fimplicit - modules - fimplicit - module - maps ",
32
+ " file ": " DIR /t .c "
33
+ }]
34
+
35
+ //--- relative/h1.h
36
+
37
+ //--- relative/module.modulemap
38
+ module H { header "h1.h" }
39
+
40
+ //--- t.c
41
+ #include "h1.h"
You can’t perform that action at this time.
0 commit comments