xref: /llvm-project/clang/test/ClangScanDeps/submodule-order.c (revision 71e32d5cf0053090aaad62d946fcfd00f1915f26)
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
4 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/deps1.json
5 // RUN: mv %t/tu2.c %t/tu.c
6 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/deps2.json
7 // RUN: diff -u %t/deps1.json %t/deps2.json
8 // RUN: FileCheck %s < %t/deps1.json
9 
10 // CHECK: "-fmodule-file={{.*}}Indirect1
11 // CHECK-NOT: "-fmodule-file={{.*}}Indirect
12 // CHECK: "-fmodule-file={{.*}}Indirect2
13 // CHECK-NOT: "-fmodule-file={{.*}}Indirect
14 
15 //--- cdb.json.template
16 [{
17   "directory": "DIR",
18   "command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
19   "file": "DIR/tu.c"
20 }]
21 
22 //--- module.modulemap
23 module Indirect1 { header "Indirect1.h" }
24 module Indirect2 { header "Indirect2.h" }
25 module Mod {
26   umbrella "Mod"
27   module * { export * }
28 }
29 
30 //--- Indirect1.h
31 void indirect1(void);
32 
33 //--- Indirect2.h
34 void indirect2(void);
35 
36 //--- Mod/SubMod1.h
37 #include "../Indirect1.h"
38 
39 //--- Mod/SubMod2.h
40 #include "../Indirect2.h"
41 
42 //--- tu.c
43 #include "Mod/SubMod1.h"
44 #include "Mod/SubMod2.h"
tu1(void)45 void tu1(void) {
46   indirect1();
47   indirect2();
48 }
49 
50 //--- tu2.c
51 #include "Mod/SubMod2.h"
52 #include "Mod/SubMod1.h"
tu1(void)53 void tu1(void) {
54   indirect1();
55   indirect2();
56 }