|
| 1 | +// Test path prefix-mapping when using a cas-fs with clang-scan-deps in |
| 2 | +// modules. |
| 3 | + |
| 4 | +// REQUIRES: ondisk_cas |
| 5 | + |
| 6 | +// RUN: rm -rf %t |
| 7 | +// RUN: split-file %s %t |
| 8 | +// RUN: sed -e "s|DIR|%t|g" -e "s|CLANG|%clang|g" -e "s|SDK|%S/Inputs/SDK|g" %t/cdb.json.template > %t/cdb.json |
| 9 | + |
| 10 | +// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \ |
| 11 | +// RUN: -cas-path %t/cas -action-cache-path %t/cache -module-files-dir %t/modules \ |
| 12 | +// RUN: -prefix-map=%t/modules=/^modules -prefix-map=%t=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \ |
| 13 | +// RUN: > %t/full_result.txt |
| 14 | + |
| 15 | +// Check the command-lines. |
| 16 | +// RUN: FileCheck %s -input-file %t/full_result.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK |
| 17 | + |
| 18 | +// Extract individual commands. |
| 19 | +// RUN: %deps-to-rsp %t/full_result.txt --module-name=B > %t/B.cc1.rsp |
| 20 | +// RUN: %deps-to-rsp %t/full_result.txt --module-name=A > %t/A.cc1.rsp |
| 21 | +// RUN: %deps-to-rsp %t/full_result.txt --tu-index 0 > %t/tu.cc1.rsp |
| 22 | + |
| 23 | +// Check the casfs. |
| 24 | +// RUN: cat %t/B.cc1.rsp | sed -E 's/.* "-fcas-fs" "([^ ]+)" .*/\1/' > %t/B_id.txt |
| 25 | +// RUN: cat %t/A.cc1.rsp | sed -E 's/.* "-fcas-fs" "([^ ]+)" .*/\1/' > %t/A_id.txt |
| 26 | +// RUN: cat %t/tu.cc1.rsp | sed -E 's/.* "-fcas-fs" "([^ ]+)" .*/\1/' > %t/tu_id.txt |
| 27 | +// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/B_id.txt > %t/B_fs.txt |
| 28 | +// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/A_id.txt > %t/A_fs.txt |
| 29 | +// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/tu_id.txt > %t/tu_fs.txt |
| 30 | +// RUN: FileCheck %s -input-file %t/A_fs.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK -check-prefixes=FS_NEG,FS |
| 31 | +// RUN: FileCheck %s -input-file %t/B_fs.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK -check-prefixes=FS_NEG,FS |
| 32 | +// RUN: FileCheck %s -input-file %t/tu_fs.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK -check-prefixes=FS_NEG,FS |
| 33 | + |
| 34 | +// FS_NEG-NOT: [[PREFIX]] |
| 35 | +// FS_NEG-NOT: [[SDK_PREFIX]] |
| 36 | +// FS_NEG-NOT: .pcm{{$}} |
| 37 | +// FS: file llvmcas://{{.*}} /^sdk/usr/include/stdlib.h |
| 38 | +// FS: file llvmcas://{{.*}} /^src/a.h |
| 39 | +// FS: file llvmcas://{{.*}} /^src/b.h |
| 40 | +// FS: file llvmcas://{{.*}} /^src/module.modulemap |
| 41 | +// FS: file llvmcas://{{.*}} /^tc/lib/clang/{{.*}}/include/stdarg.h |
| 42 | + |
| 43 | +// Check that it builds. |
| 44 | +// RUN: %clang @%t/B.cc1.rsp |
| 45 | +// RUN: %clang @%t/A.cc1.rsp |
| 46 | +// RUN: %clang @%t/tu.cc1.rsp |
| 47 | + |
| 48 | +// CHECK: { |
| 49 | +// CHECK: "modules": [ |
| 50 | +// CHECK: { |
| 51 | +// CHECK: "casfs-root-id": "[[A_ROOT_ID:llvmcas://[[:xdigit:]]+]]" |
| 52 | +// CHECK: "clang-module-deps": [ |
| 53 | +// CHECK: { |
| 54 | +// CHECK: "module-name": "B" |
| 55 | +// CHECK: } |
| 56 | +// CHECK: ] |
| 57 | +// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" |
| 58 | +// CHECK: "command-line": [ |
| 59 | +// CHECK: "-fcas-path" |
| 60 | +// CHECK: "[[PREFIX]]/cas" |
| 61 | +// CHECK: "-faction-cache-path" |
| 62 | +// CHECK: "[[PREFIX]]/cache" |
| 63 | +// CHECK: "-fcas-fs" |
| 64 | +// CHECK: "[[A_ROOT_ID]]" |
| 65 | +// CHECK: "-fcas-fs-working-directory" |
| 66 | +// CHECK: "/^src" |
| 67 | +// CHECK: "-fmodule-map-file=/^src/module.modulemap" |
| 68 | +// CHECK: "-o" |
| 69 | +// CHECK: "[[PREFIX]]/modules/{{.*}}/A-{{.*}}.pcm" |
| 70 | +// CHECK: "-fmodule-file-cache-key=/^modules/{{.*}}/B-[[B_CONTEXT_HASH:[^.]+]].pcm=llvmcas://{{.*}}" |
| 71 | +// CHECK: "-x" |
| 72 | +// CHECK: "c" |
| 73 | +// CHECK: "/^src/module.modulemap" |
| 74 | +// CHECK: "-isysroot" |
| 75 | +// CHECK: "/^sdk" |
| 76 | +// CHECK: "-resource-dir" |
| 77 | +// CHECK: "/^tc/lib/clang/{{.*}}" |
| 78 | +// CHECK: "-fmodule-file=B=/^modules/{{.*}}/B-[[B_CONTEXT_HASH]].pcm" |
| 79 | +// CHECK: "-isystem" |
| 80 | +// CHECK: "/^tc/lib/clang/{{.*}}/include" |
| 81 | +// CHECK: "-internal-externc-isystem" |
| 82 | +// CHECK: "/^sdk/usr/include" |
| 83 | +// CHECK: ] |
| 84 | +// CHECK: "file-deps": [ |
| 85 | +// CHECK: "[[PREFIX]]/a.h" |
| 86 | +// CHECK: "[[PREFIX]]/module.modulemap" |
| 87 | +// CHECK: ] |
| 88 | +// CHECK: "name": "A" |
| 89 | +// CHECK: } |
| 90 | +// CHECK: { |
| 91 | +// CHECK: "casfs-root-id": "[[B_ROOT_ID:llvmcas://[[:xdigit:]]+]]" |
| 92 | +// CHECK: "clang-module-deps": [], |
| 93 | +// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" |
| 94 | +// CHECK: "command-line": [ |
| 95 | +// CHECK: "-fcas-path" |
| 96 | +// CHECK: "[[PREFIX]]/cas" |
| 97 | +// CHECK: "-faction-cache-path" |
| 98 | +// CHECK: "[[PREFIX]]/cache" |
| 99 | +// CHECK: "-fcas-fs" |
| 100 | +// CHECK: "[[B_ROOT_ID]]" |
| 101 | +// CHECK: "-fcas-fs-working-directory" |
| 102 | +// CHECK: "/^src" |
| 103 | +// CHECK: "-o" |
| 104 | +// CHECK: "[[PREFIX]]/modules/{{.*}}/B-[[B_CONTEXT_HASH]].pcm" |
| 105 | +// CHECK: "-x" |
| 106 | +// CHECK: "c" |
| 107 | +// CHECK: "/^src/module.modulemap" |
| 108 | +// CHECK: "-isysroot" |
| 109 | +// CHECK: "/^sdk" |
| 110 | +// CHECK: "-resource-dir" |
| 111 | +// CHECK: "/^tc/lib/clang/{{.*}}" |
| 112 | +// CHECK: "-isystem" |
| 113 | +// CHECK: "/^tc/lib/clang/{{.*}}/include" |
| 114 | +// CHECK: "-internal-externc-isystem" |
| 115 | +// CHECK: "/^sdk/usr/include" |
| 116 | +// CHECK: ] |
| 117 | +// CHECK: "context-hash": "[[B_CONTEXT_HASH]]" |
| 118 | +// CHECK: "file-deps": [ |
| 119 | +// CHECK: "{{.*}}/include/stdarg.h" |
| 120 | +// CHECK: "[[PREFIX]]/b.h" |
| 121 | +// CHECK: "[[PREFIX]]/module.modulemap" |
| 122 | +// CHECK: "[[SDK_PREFIX]]/usr/include/stdlib.h" |
| 123 | +// CHECK: ] |
| 124 | +// CHECK: "name": "B" |
| 125 | +// CHECK: } |
| 126 | +// CHECK: ] |
| 127 | +// CHECK: "translation-units": [ |
| 128 | +// CHECK: { |
| 129 | +// CHECK: "commands": [ |
| 130 | +// CHECK: { |
| 131 | +// CHECK: "casfs-root-id": "[[TU_ROOT_ID:llvmcas://[[:xdigit:]]+]]" |
| 132 | +// CHECK: "clang-module-deps": [ |
| 133 | +// CHECK: { |
| 134 | +// CHECK: "module-name": "A" |
| 135 | +// CHECK: } |
| 136 | +// CHECK: ] |
| 137 | +// CHECK: "command-line": [ |
| 138 | +// CHECK: "-fcas-path" |
| 139 | +// CHECK: "[[PREFIX]]/cas" |
| 140 | +// CHECK: "-faction-cache-path" |
| 141 | +// CHECK: "[[PREFIX]]/cache" |
| 142 | +// CHECK: "-fcas-fs" |
| 143 | +// CHECK: "[[TU_ROOT_ID]]" |
| 144 | +// CHECK: "-fcas-fs-working-directory" |
| 145 | +// CHECK: "/^src" |
| 146 | +// CHECK: "-fmodule-map-file=/^src/module.modulemap" |
| 147 | +// CHECK: "-fmodule-file-cache-key=/^modules/{{.*}}A-{{.*}}.pcm=llvmcas://{{.*}}" |
| 148 | +// CHECK: "-x" |
| 149 | +// CHECK: "c" |
| 150 | +// CHECK: "/^src/t.c" |
| 151 | +// CHECK: "-isysroot" |
| 152 | +// CHECK: "/^sdk" |
| 153 | +// CHECK: "-resource-dir" |
| 154 | +// CHECK: "/^tc/lib/clang/{{.*}}" |
| 155 | +// CHECK: "-fmodule-file=A=/^modules/{{.*}}/A-{{.*}}.pcm" |
| 156 | +// CHECK: "-isystem" |
| 157 | +// CHECK: "/^tc/lib/clang/{{.*}}/include" |
| 158 | +// CHECK: "-internal-externc-isystem" |
| 159 | +// CHECK: "/^sdk/usr/include" |
| 160 | +// CHECK: ], |
| 161 | +// CHECK: "file-deps": [ |
| 162 | +// CHECK: "[[PREFIX]]/t.c" |
| 163 | +// CHECK: ] |
| 164 | +// CHECK: "input-file": "[[PREFIX]]/t.c" |
| 165 | +// CHECK: } |
| 166 | + |
| 167 | + |
| 168 | +//--- cdb.json.template |
| 169 | +[ |
| 170 | + { |
| 171 | + "directory": "DIR", |
| 172 | + "command": "CLANG -fsyntax-only DIR/t.c -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/mcp -target x86_64-apple-macos11 -isysroot SDK", |
| 173 | + "file": "DIR/t.c" |
| 174 | + } |
| 175 | +] |
| 176 | + |
| 177 | +//--- t.c |
| 178 | +#include "a.h" |
| 179 | + |
| 180 | +//--- module.modulemap |
| 181 | +module A { header "a.h" } |
| 182 | +module B { header "b.h" } |
| 183 | + |
| 184 | +//--- a.h |
| 185 | +#include "b.h" |
| 186 | + |
| 187 | +//--- b.h |
| 188 | +#include <stdarg.h> |
| 189 | +#include <stdlib.h> |
0 commit comments