xref: /llvm-project/clang/test/Modules/implicit-module-header-maps.cpp (revision bf916aeebd8c96c0618a1ccbb01a1517710f8766)
1 // UNSUPPORTED: system-windows
2 // RUN: rm -rf %t
3 // RUN: split-file %s %t
4 // RUN: cd %t
5 //
6 // RUN: %hmaptool write a.hmap.json hmap
7 //
8 // RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap -fmodules-cache-path=%t test.cpp
9 //
10 // RUN: cd %T
11 // RUN: rm -rf %t
12 // RUN: split-file %s %t
13 // RUN: cd %t
14 //
15 // RUN: sed -e "s|OUTPUTS_DIR|%t|g" b.hmap.json > hmap.json
16 // RUN: %hmaptool write hmap.json hmap
17 //
18 // RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap -fmodules-cache-path=%t test.cpp
19 
20 //--- After/Mapping.h
21 #ifdef FOO
22 #error foo
23 #endif
24 
25 //--- a.hmap.json
26 {
27   "mappings" :
28     {
29      "Before/Mapping.h" : "After/Mapping.h",
30      "After/Mapping.h" : "After/Mapping.h"
31     }
32 }
33 
34 //--- b.hmap.json
35 {
36   "mappings" :
37     {
38      "Before/Mapping.h" : "OUTPUTS_DIR/After/Mapping.h"
39     }
40 }
41 
42 //--- module.modulemap
43 module a {
44   header "After/Mapping.h"
45 }
46 
47 
48 //--- test.cpp
49 #define FOO
50 // This include will fail if:
51 // 1) modules are't used, as the `FOO` define will propagate into the included
52 //    header and trip a `#error`, or
53 // 2) header maps aren't used, as the header name doesn't exist and relies on
54 //    the header map to remap it to the real header.
55 #include "Before/Mapping.h"
56