File: modules-cas-fs-prefix-mapping.c

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (188 lines) | stat: -rw-r--r-- 7,546 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Test path prefix-mapping when using a cas-fs with clang-scan-deps in
// modules.

// REQUIRES: ondisk_cas

// RUN: rm -rf %t
// RUN: split-file %s %t
// 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

// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
// RUN:    -cas-path %t/cas -module-files-dir %t/modules \
// RUN:    -prefix-map=%t/modules=/^modules -prefix-map=%t=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \
// RUN:  > %t/full_result.txt

// Check the command-lines.
// RUN: FileCheck %s -input-file %t/full_result.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK

// Extract individual commands.
// RUN: %deps-to-rsp %t/full_result.txt --module-name=B > %t/B.cc1.rsp
// RUN: %deps-to-rsp %t/full_result.txt --module-name=A > %t/A.cc1.rsp
// RUN: %deps-to-rsp %t/full_result.txt --tu-index 0 > %t/tu.cc1.rsp

// Check the casfs.
// RUN: cat %t/B.cc1.rsp | sed -E 's/.* "-fcas-fs" "([^ ]+)" .*/\1/' > %t/B_id.txt
// RUN: cat %t/A.cc1.rsp | sed -E 's/.* "-fcas-fs" "([^ ]+)" .*/\1/' > %t/A_id.txt
// RUN: cat %t/tu.cc1.rsp | sed -E 's/.* "-fcas-fs" "([^ ]+)" .*/\1/' > %t/tu_id.txt
// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/B_id.txt > %t/B_fs.txt
// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/A_id.txt > %t/A_fs.txt
// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/tu_id.txt > %t/tu_fs.txt
// RUN: FileCheck %s -input-file %t/A_fs.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK -check-prefixes=FS_NEG,FS
// RUN: FileCheck %s -input-file %t/B_fs.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK -check-prefixes=FS_NEG,FS
// RUN: FileCheck %s -input-file %t/tu_fs.txt -DPREFIX=%t -DSDK_PREFIX=%S/Inputs/SDK -check-prefixes=FS_NEG,FS

// FS_NEG-NOT: [[PREFIX]]
// FS_NEG-NOT: [[SDK_PREFIX]]
// FS_NEG-NOT: .pcm{{$}}
// FS: file llvmcas://{{.*}} /^sdk/usr/include/stdlib.h
// FS: file llvmcas://{{.*}} /^src/a.h
// FS: file llvmcas://{{.*}} /^src/b.h
// FS: file llvmcas://{{.*}} /^src/module.modulemap
// FS: file llvmcas://{{.*}} /^tc/lib/clang/{{.*}}/include/stdarg.h

// Check that it builds.
// RUN: %clang @%t/B.cc1.rsp
// RUN: %clang @%t/A.cc1.rsp
// RUN: %clang @%t/tu.cc1.rsp

// CHECK:      {
// CHECK:        "modules": [
// CHECK:          {
// CHECK:            "casfs-root-id": "[[A_ROOT_ID:llvmcas://[[:xdigit:]]+]]"
// CHECK:            "clang-module-deps": [
// CHECK:              {
// CHECK:                "module-name": "B"
// CHECK:              }
// CHECK:            ]
// CHECK:            "clang-modulemap-file": "[[PREFIX]]/module.modulemap"
// CHECK:            "command-line": [
// CHECK:              "-fcas-path"
// CHECK:              "[[PREFIX]]/cas"
// CHECK:              "-fcas-fs"
// CHECK:              "[[A_ROOT_ID]]"
// CHECK:              "-fcas-fs-working-directory"
// CHECK:              "/^src"
// CHECK:              "-fmodule-map-file=/^src/module.modulemap"
// CHECK:              "-o"
// CHECK:              "[[PREFIX]]/modules/{{.*}}/A-{{.*}}.pcm"
// CHECK:              "-fmodule-file-cache-key"
// CHECK:              "/^modules/{{.*}}/B-[[B_CONTEXT_HASH:[^.]+]].pcm"
// CHECK:              "llvmcas://{{.*}}"
// CHECK:              "-x"
// CHECK:              "c"
// CHECK:              "/^src/module.modulemap"
// CHECK:              "-isysroot"
// CHECK:              "/^sdk"
// CHECK:              "-resource-dir"
// CHECK:              "/^tc/lib/clang/{{.*}}"
// CHECK:              "-fmodule-file=B=/^modules/{{.*}}/B-[[B_CONTEXT_HASH]].pcm"
// CHECK:              "-isystem"
// CHECK:              "/^tc/lib/clang/{{.*}}/include"
// CHECK:              "-internal-externc-isystem"
// CHECK:              "/^sdk/usr/include"
// CHECK:            ]
// CHECK:            "file-deps": [
// CHECK:              "[[PREFIX]]/a.h"
// CHECK:              "[[PREFIX]]/module.modulemap"
// CHECK:            ]
// CHECK:            "name": "A"
// CHECK:          }
// CHECK:          {
// CHECK:            "casfs-root-id": "[[B_ROOT_ID:llvmcas://[[:xdigit:]]+]]"
// CHECK:            "clang-module-deps": [],
// CHECK:            "clang-modulemap-file": "[[PREFIX]]/module.modulemap"
// CHECK:            "command-line": [
// CHECK:              "-fcas-path"
// CHECK:              "[[PREFIX]]/cas"
// CHECK:              "-fcas-fs"
// CHECK:              "[[B_ROOT_ID]]"
// CHECK:              "-fcas-fs-working-directory"
// CHECK:              "/^src"
// CHECK:              "-o"
// CHECK:              "[[PREFIX]]/modules/{{.*}}/B-[[B_CONTEXT_HASH]].pcm"
// CHECK:              "-x"
// CHECK:              "c"
// CHECK:              "/^src/module.modulemap"
// CHECK:              "-isysroot"
// CHECK:              "/^sdk"
// CHECK:              "-resource-dir"
// CHECK:              "/^tc/lib/clang/{{.*}}"
// CHECK:              "-isystem"
// CHECK:              "/^tc/lib/clang/{{.*}}/include"
// CHECK:              "-internal-externc-isystem"
// CHECK:              "/^sdk/usr/include"
// CHECK:            ]
// CHECK:            "context-hash": "[[B_CONTEXT_HASH]]"
// CHECK:            "file-deps": [
// Note: PREFIX, SDK_PREFIX and toolchain path are unordered
// CHECK-DAG:          "{{.*}}/include/stdarg.h"
// CHECK-DAG:          "[[PREFIX]]/b.h"
// CHECK-DAG:          "[[PREFIX]]/module.modulemap"
// CHECK-DAG:          "[[SDK_PREFIX]]/usr/include/stdlib.h"
// CHECK:            ]
// CHECK:            "name": "B"
// CHECK:          }
// CHECK:        ]
// CHECK:        "translation-units": [
// CHECK:          {
// CHECK:            "commands": [
// CHECK:              {
// CHECK:                "casfs-root-id": "[[TU_ROOT_ID:llvmcas://[[:xdigit:]]+]]"
// CHECK:                "clang-module-deps": [
// CHECK:                  {
// CHECK:                    "module-name": "A"
// CHECK:                  }
// CHECK:                ]
// CHECK:                "command-line": [
// CHECK:                  "-fcas-path"
// CHECK:                  "[[PREFIX]]/cas"
// CHECK:                  "-fcas-fs"
// CHECK:                  "[[TU_ROOT_ID]]"
// CHECK:                  "-fcas-fs-working-directory"
// CHECK:                  "/^src"
// CHECK:                  "-fmodule-map-file=/^src/module.modulemap"
// CHECK:                  "-fmodule-file-cache-key"
// CHECK:                  "/^modules/{{.*}}A-{{.*}}.pcm"
// CHECK:                  "llvmcas://{{.*}}"
// CHECK:                  "-x"
// CHECK:                  "c"
// CHECK:                  "/^src/t.c"
// CHECK:                  "-isysroot"
// CHECK:                  "/^sdk"
// CHECK:                  "-resource-dir"
// CHECK:                  "/^tc/lib/clang/{{.*}}"
// CHECK:                  "-fmodule-file=A=/^modules/{{.*}}/A-{{.*}}.pcm"
// CHECK:                  "-isystem"
// CHECK:                  "/^tc/lib/clang/{{.*}}/include"
// CHECK:                  "-internal-externc-isystem"
// CHECK:                  "/^sdk/usr/include"
// CHECK:                ],
// CHECK:                "file-deps": [
// CHECK:                  "[[PREFIX]]/t.c"
// CHECK:                ]
// CHECK:                "input-file": "[[PREFIX]]/t.c"
// CHECK:              }


//--- cdb.json.template
[
  {
    "directory": "DIR",
    "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",
    "file": "DIR/t.c"
  }
]

//--- t.c
#include "a.h"

//--- module.modulemap
module A { header "a.h" }
module B { header "b.h" }

//--- a.h
#include "b.h"

//--- b.h
#include <stdarg.h>
#include <stdlib.h>