| 1 |
// Most likely platform specific sed differences |
| 2 |
// UNSUPPORTED: system-windows |
| 3 |
// Test current directory pruning when computing the context hash. |
| 4 |
|
| 5 |
// RUN: rm -rf %t |
| 6 |
// RUN: split-file %s %t |
| 7 |
// RUN: sed -e "s|DIR|%/t|g" %t/cdb0.json.in > %t/cdb0.json |
| 8 |
// RUN: sed -e "s|DIR|%/t|g" %t/cdb1.json.in > %t/cdb1.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 |
| 11 |
// RUN: sed -e "s|DIR|%/t|g" %t/cdb5.json.in > %t/cdb5.json |
| 12 |
// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format experimental-full -optimize-args=all > %t/result0.json |
| 13 |
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=all > %t/result1.json |
| 14 |
// It is not a typo to use cdb1.json for result2. We intend to use the same |
| 15 |
// compilation database, but different clang-scan-deps optimize-args options. |
| 16 |
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=header-search,system-warnings,vfs,canonicalize-macros > %t/result2.json |
| 17 |
// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format experimental-full -optimize-args=all > %t/result3.json |
| 18 |
// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format experimental-full -optimize-args=all > %t/result4.json |
| 19 |
// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format experimental-full -optimize-args=all > %t/result5.json |
| 20 |
// RUN: cat %t/result0.json %t/result1.json | FileCheck %s |
| 21 |
// RUN: cat %t/result0.json %t/result2.json | FileCheck %s -check-prefix=SKIPOPT |
| 22 |
// RUN: cat %t/result3.json %t/result4.json | FileCheck %s -check-prefix=RELPATH |
| 23 |
// RUN: cat %t/result0.json %t/result5.json | FileCheck %s |
| 24 |
|
| 25 |
//--- cdb0.json.in |
| 26 |
[{ |
| 27 |
"directory": "DIR", |
| 28 |
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -o DIR/tu.o", |
| 29 |
"file": "DIR/tu.c" |
| 30 |
}] |
| 31 |
|
| 32 |
//--- cdb1.json.in |
| 33 |
[{ |
| 34 |
"directory": "DIR/a", |
| 35 |
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -o DIR/tu.o", |
| 36 |
"file": "DIR/tu.c" |
| 37 |
}] |
| 38 |
|
| 39 |
// cdb2 is skipped because we reuse cdb1. |
| 40 |
|
| 41 |
//--- cdb3.json.in |
| 42 |
[{ |
| 43 |
"directory": "DIR", |
| 44 |
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ", |
| 45 |
"file": "DIR/tu.c" |
| 46 |
}] |
| 47 |
|
| 48 |
//--- cdb4.json.in |
| 49 |
[{ |
| 50 |
"directory": "DIR/a/", |
| 51 |
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ", |
| 52 |
"file": "DIR/tu.c" |
| 53 |
}] |
| 54 |
|
| 55 |
//--- cdb5.json.in |
| 56 |
[{ |
| 57 |
"directory": "DIR", |
| 58 |
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -Xclang -working-directory=DIR/a/ -o DIR/tu.o", |
| 59 |
"file": "DIR/tu.c" |
| 60 |
}] |
| 61 |
|
| 62 |
//--- include/module.modulemap |
| 63 |
module mod { |
| 64 |
header "mod.h" |
| 65 |
} |
| 66 |
|
| 67 |
//--- include/mod.h |
| 68 |
|
| 69 |
//--- tu.c |
| 70 |
#include "mod.h" |
| 71 |
|
| 72 |
// Check that result0 and result1/result5 compute the same hash with |
| 73 |
// optimization on. The only difference between result0 and result1/result5 is |
| 74 |
// the compiler's working directory. |
| 75 |
// CHECK: { |
| 76 |
// CHECK-NEXT: "modules": [ |
| 77 |
// CHECK-NEXT: { |
| 78 |
// CHECK-NEXT: "clang-module-deps": [], |
| 79 |
// CHECK: "context-hash": "[[HASH:.*]]", |
| 80 |
// CHECK: } |
| 81 |
// CHECK: "translation-units": [ |
| 82 |
// CHECK: { |
| 83 |
// CHECK: "commands": [ |
| 84 |
// CHECK: { |
| 85 |
// CHECK-NEXT: "clang-context-hash": "{{.*}}", |
| 86 |
// CHECK-NEXT: "clang-module-deps": [ |
| 87 |
// CHECK-NEXT: { |
| 88 |
// CHECK-NEXT: "context-hash": "[[HASH]]", |
| 89 |
// CHECK-NEXT: "module-name": "mod" |
| 90 |
// CHECK: } |
| 91 |
// CHECK: ], |
| 92 |
// CHECK: { |
| 93 |
// CHECK-NEXT: "modules": [ |
| 94 |
// CHECK-NEXT: { |
| 95 |
// CHECK-NEXT: "clang-module-deps": [], |
| 96 |
// CHECK: "context-hash": "[[HASH]]", |
| 97 |
// CHECK: } |
| 98 |
// CHECK: "translation-units": [ |
| 99 |
// CHECK: { |
| 100 |
// CHECK: "commands": [ |
| 101 |
// CHECK: { |
| 102 |
// CHECK-NEXT: "clang-context-hash": "{{.*}}", |
| 103 |
// CHECK-NEXT: "clang-module-deps": [ |
| 104 |
// CHECK-NEXT: { |
| 105 |
// CHECK-NEXT: "context-hash": "[[HASH]]", |
| 106 |
// CHECK-NEXT: "module-name": "mod" |
| 107 |
// CHECK: } |
| 108 |
// CHECK: ], |
| 109 |
|
| 110 |
// Check that result0 and result2 compute different hashes because |
| 111 |
// the working directory optmization is turned off for result2. |
| 112 |
// SKIPOPT: { |
| 113 |
// SKIPOPT-NEXT: "modules": [ |
| 114 |
// SKIPOPT-NEXT: { |
| 115 |
// SKIPOPT-NEXT: "clang-module-deps": [], |
| 116 |
// SKIPOPT: "context-hash": "[[HASH0:.*]]", |
| 117 |
// SKIPOPT: } |
| 118 |
// SKIPOPT: "translation-units": [ |
| 119 |
// SKIPOPT: { |
| 120 |
// SKIPOPT: "commands": [ |
| 121 |
// SKIPOPT: { |
| 122 |
// SKIPOPT-NEXT: "clang-context-hash": "{{.*}}", |
| 123 |
// SKIPOPT-NEXT: "clang-module-deps": [ |
| 124 |
// SKIPOPT-NEXT: { |
| 125 |
// SKIPOPT-NEXT: "context-hash": "[[HASH0]]", |
| 126 |
// SKIPOPT-NEXT: "module-name": "mod" |
| 127 |
// SKIPOPT: } |
| 128 |
// SKIPOPT: ], |
| 129 |
// SKIPOPT: { |
| 130 |
// SKIPOPT-NEXT: "modules": [ |
| 131 |
// SKIPOPT-NEXT: { |
| 132 |
// SKIPOPT-NEXT: "clang-module-deps": [], |
| 133 |
// SKIPOPT-NOT: "context-hash": "[[HASH0]]", |
| 134 |
// SKIPOPT: "context-hash": "[[HASH2:.*]]", |
| 135 |
// SKIPOPT: } |
| 136 |
// SKIPOPT: "translation-units": [ |
| 137 |
// SKIPOPT: { |
| 138 |
// SKIPOPT: "commands": [ |
| 139 |
// SKIPOPT: { |
| 140 |
// SKIPOPT-NEXT: "clang-context-hash": "{{.*}}", |
| 141 |
// SKIPOPT-NEXT: "clang-module-deps": [ |
| 142 |
// SKIPOPT-NEXT: { |
| 143 |
// SKIPOPT-NOT: "context-hash": "[[HASH0]]", |
| 144 |
// SKIPOPT-NEXT: "context-hash": "[[HASH2]]" |
| 145 |
// SKIPOPT-NEXT: "module-name": "mod" |
| 146 |
// SKIPOPT: } |
| 147 |
// SKIPOPT: ], |
| 148 |
|
| 149 |
// Check that result3 and result4 contain different hashes because |
| 150 |
// both have a same relative path as a command line input, and |
| 151 |
// they are produced using different compiler working directories. |
| 152 |
// RELPATH: { |
| 153 |
// RELPATH-NEXT: "modules": [ |
| 154 |
// RELPATH-NEXT: { |
| 155 |
// RELPATH-NEXT: "clang-module-deps": [], |
| 156 |
// RELPATH: "context-hash": "[[HASH3:.*]]", |
| 157 |
// RELPATH: } |
| 158 |
// RELPATH: "translation-units": [ |
| 159 |
// RELPATH: { |
| 160 |
// RELPATH: "commands": [ |
| 161 |
// RELPATH: { |
| 162 |
// RELPATH-NEXT: "clang-context-hash": "{{.*}}", |
| 163 |
// RELPATH-NEXT: "clang-module-deps": [ |
| 164 |
// RELPATH-NEXT: { |
| 165 |
// RELPATH-NEXT: "context-hash": "[[HASH3]]", |
| 166 |
// RELPATH-NEXT: "module-name": "mod" |
| 167 |
// RELPATH: } |
| 168 |
// RELPATH: ], |
| 169 |
// RELPATH: { |
| 170 |
// RELPATH-NEXT: "modules": [ |
| 171 |
// RELPATH-NEXT: { |
| 172 |
// RELPATH-NEXT: "clang-module-deps": [], |
| 173 |
// RELPATH-NOT: "context-hash": "[[HASH3]]", |
| 174 |
// RELPATH: "context-hash": "[[HASH4:.*]]", |
| 175 |
// RELPATH: } |
| 176 |
// RELPATH: "translation-units": [ |
| 177 |
// RELPATH: { |
| 178 |
// RELPATH: "commands": [ |
| 179 |
// RELPATH: { |
| 180 |
// RELPATH-NEXT: "clang-context-hash": "{{.*}}", |
| 181 |
// RELPATH-NEXT: "clang-module-deps": [ |
| 182 |
// RELPATH-NEXT: { |
| 183 |
// RELPATH-NOT: "context-hash": "[[HASH3]]", |
| 184 |
// RELPATH-NEXT: "context-hash": "[[HASH4]]" |
| 185 |
// RELPATH-NEXT: "module-name": "mod" |
| 186 |
// RELPATH: } |
| 187 |
// RELPATH: ], |
| 188 |
|