Skip to content

Commit 8f79f1b

Browse files
committed
Adding a test case against command line inputs that contain relative paths.
1 parent 1306637 commit 8f79f1b

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

clang/test/ClangScanDeps/modules-context-hash-cwd.c

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
// RUN: split-file %s %t
77
// RUN: sed -e "s|DIR|%/t|g" %t/cdb0.json.in > %t/cdb0.json
88
// RUN: sed -e "s|DIR|%/t|g" %t/cdb1.json.in > %t/cdb1.json
9-
// RUN: sed -e "s|DIR|%/t|g" %t/cdb2.json.in > %t/cdb2.json
9+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb3.json.in > %t/cdb3.json
10+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb4.json.in > %t/cdb4.json
1011
// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format experimental-full > %t/result0.json
1112
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full > %t/result1.json
12-
// RUN: clang-scan-deps -compilation-database %t/cdb2.json -format experimental-full -optimize-args=header-search,system-warnings,vfs,canonicalize-macros > %t/result2.json
13+
// It is not a typo to use cdb1.json for result2. We intend to use the same
14+
// compilation database, but different clang-scan-deps optimize-args options.
15+
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=header-search,system-warnings,vfs,canonicalize-macros > %t/result2.json
16+
// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format experimental-full > %t/result3.json
17+
// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format experimental-full > %t/result4.json
1318
// RUN: cat %t/result0.json %t/result1.json | FileCheck %s
1419
// RUN: cat %t/result0.json %t/result2.json | FileCheck %s -check-prefix=SKIPOPT
20+
// RUN: cat %t/result3.json %t/result4.json | FileCheck %s -check-prefix=RELPATH
1521

1622
//--- cdb0.json.in
1723
[{
@@ -27,13 +33,21 @@
2733
"file": "DIR/tu.c"
2834
}]
2935

30-
//--- cdb2.json.in
36+
// cdb2 is skipped because we reuse cdb1.
37+
38+
//--- cdb3.json.in
3139
[{
32-
"directory": "DIR/a/",
33-
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -o DIR/tu.o",
40+
"directory": "DIR",
41+
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ",
3442
"file": "DIR/tu.c"
3543
}]
3644

45+
//--- cdb4.json.in
46+
[{
47+
"directory": "DIR/a/",
48+
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ",
49+
"file": "DIR/tu.c"
50+
}]
3751
//--- include/module.modulemap
3852
module mod {
3953
header "mod.h"
@@ -121,3 +135,43 @@ module mod {
121135
// SKIPOPT: }
122136
// SKIPOPT: ],
123137

138+
// Check that result3 and result4 contain different hashes because
139+
// both have a same relative path as a command line input, and
140+
// they are produced using different compiler working directories.
141+
// RELPATH: {
142+
// RELPATH-NEXT: "modules": [
143+
// RELPATH-NEXT: {
144+
// RELPATH-NEXT: "clang-module-deps": [],
145+
// RELPATH: "context-hash": "[[HASH3:.*]]",
146+
// RELPATH: }
147+
// RELPATH: "translation-units": [
148+
// RELPATH: {
149+
// RELPATH: "commands": [
150+
// RELPATH: {
151+
// RELPATH-NEXT: "clang-context-hash": "{{.*}}",
152+
// RELPATH-NEXT: "clang-module-deps": [
153+
// RELPATH-NEXT: {
154+
// RELPATH-NEXT: "context-hash": "[[HASH3]]",
155+
// RELPATH-NEXT: "module-name": "mod"
156+
// RELPATH: }
157+
// RELPATH: ],
158+
// RELPATH: {
159+
// RELPATH-NEXT: "modules": [
160+
// RELPATH-NEXT: {
161+
// RELPATH-NEXT: "clang-module-deps": [],
162+
// RELPATH-NOT: "context-hash": "[[HASH3]]",
163+
// RELPATH: "context-hash": "[[HASH4:.*]]",
164+
// RELPATH: }
165+
// RELPATH: "translation-units": [
166+
// RELPATH: {
167+
// RELPATH: "commands": [
168+
// RELPATH: {
169+
// RELPATH-NEXT: "clang-context-hash": "{{.*}}",
170+
// RELPATH-NEXT: "clang-module-deps": [
171+
// RELPATH-NEXT: {
172+
// RELPATH-NOT: "context-hash": "[[HASH3]]",
173+
// RELPATH-NEXT: "context-hash": "[[HASH4]]"
174+
// RELPATH-NEXT: "module-name": "mod"
175+
// RELPATH: }
176+
// RELPATH: ],
177+

0 commit comments

Comments
 (0)