[clang] Canonicalize absolute paths in dependency file (#117458)
[llvm-project.git] / clang / test / ClangScanDeps / modules-priv-fw-from-pub.m
blobdd314e1a3006a73e297277a1929e88e5fb7ceb99
1 // This test checks that importing private headers from the public headers of
2 // a framework is consistent between the dependency scanner and the explicit build.
4 // RUN: rm -rf %t
5 // RUN: split-file %s %t
7 //--- frameworks/FW.framework/Modules/module.modulemap
8 framework module FW { header "FW.h" }
9 //--- frameworks/FW.framework/Modules/module.private.modulemap
10 framework module FW_Private { header "FW_Private.h"}
11 //--- frameworks/FW.framework/Headers/FW.h
12 #include <FW/FW_Private.h>
13 //--- frameworks/FW.framework/PrivateHeaders/FW_Private.h
14 @import Dependency;
16 //--- modules/module.modulemap
17 module Dependency { header "dependency.h" }
18 //--- modules/dependency.h
19 // empty
21 //--- tu.m
22 #include <FW/FW.h>
24 //--- cdb.json.in
26   "file": "DIR/tu.m",
27   "directory": "DIR",
28   "command": "clang -fmodules -fmodules-cache-path=DIR/cache -fimplicit-module-maps -I DIR/modules -F DIR/frameworks -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -c DIR/tu.m -o DIR/tu.o"
31 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
32 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/deps.json
34 // Check that FW is reported to depend on FW_Private.
35 // RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
36 // CHECK:      {
37 // CHECK-NEXT:   "modules": [
38 // CHECK-NEXT:     {
39 // CHECK-NEXT:       "clang-module-deps": [],
40 // CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/modules/module.modulemap",
41 // CHECK-NEXT:       "command-line": [
42 // CHECK:            ],
43 // CHECK-NEXT:       "context-hash": "{{.*}}",
44 // CHECK-NEXT:       "file-deps": [
45 // CHECK-NEXT:         "[[PREFIX]]/modules/module.modulemap",
46 // CHECK-NEXT:         "[[PREFIX]]/modules/dependency.h"
47 // CHECK-NEXT:       ],
48 // CHECK-NEXT:       "link-libraries": [],
49 // CHECK-NEXT:       "name": "Dependency"
50 // CHECK-NEXT:     },
51 // CHECK-NEXT:     {
52 // CHECK-NEXT:       "clang-module-deps": [
53 // CHECK-NEXT:         {
54 // CHECK-NEXT:           "context-hash": "{{.*}}",
55 // CHECK-NEXT:           "module-name": "FW_Private"
56 // CHECK-NEXT:         }
57 // CHECK-NEXT:       ],
58 // CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
59 // CHECK-NEXT:       "command-line": [
60 // CHECK:            ],
61 // CHECK-NEXT:       "context-hash": "{{.*}}",
62 // CHECK-NEXT:       "file-deps": [
63 // CHECK-NEXT:         "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
64 // CHECK-NEXT:         "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
65 // CHECK-NEXT:         "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h"
66 // CHECK-NEXT:       ],
67 // CHECK-NEXT:       "link-libraries": [
68 // CHECK-NEXT:         {
69 // CHECK-NEXT:           "isFramework": true,
70 // CHECK-NEXT:           "link-name": "FW"
71 // CHECK-NEXT:         }
72 // CHECK-NEXT:       ],
73 // CHECK-NEXT:       "name": "FW"
74 // CHECK-NEXT:     },
75 // CHECK-NEXT:     {
76 // CHECK-NEXT:       "clang-module-deps": [
77 // CHECK-NEXT:         {
78 // CHECK-NEXT:           "context-hash": "{{.*}}",
79 // CHECK-NEXT:           "module-name": "Dependency"
80 // CHECK-NEXT:         }
81 // CHECK-NEXT:       ],
82 // CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
83 // CHECK-NEXT:       "command-line": [
84 // CHECK:            ],
85 // CHECK-NEXT:       "context-hash": "{{.*}}",
86 // CHECK-NEXT:       "file-deps": [
87 // CHECK-NEXT:         "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
88 // CHECK-NEXT:         "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/FW_Private.h",
89 // CHECK-NEXT:         "[[PREFIX]]/modules/module.modulemap"
90 // CHECK-NEXT:       ],
91 // CHECK-NEXT:       "link-libraries": [
92 // CHECK-NEXT:         {
93 // CHECK-NEXT:           "isFramework": true,
94 // CHECK-NEXT:           "link-name": "FW"
95 // CHECK-NEXT:         }
96 // CHECK-NEXT:       ],
97 // CHECK-NEXT:       "name": "FW_Private"
98 // CHECK-NEXT:     }
99 // CHECK-NEXT:   ],
100 // CHECK-NEXT:   "translation-units": [
101 // CHECK-NEXT:     {
102 // CHECK-NEXT:       "commands": [
103 // CHECK-NEXT:         {
104 // CHECK-NEXT:           "clang-context-hash": "{{.*}}",
105 // CHECK-NEXT:           "clang-module-deps": [
106 // CHECK-NEXT:             {
107 // CHECK-NEXT:               "context-hash": "{{.*}}",
108 // CHECK-NEXT:               "module-name": "FW"
109 // CHECK-NEXT:             }
110 // CHECK-NEXT:           ],
111 // CHECK-NEXT:           "command-line": [
112 // CHECK:                ],
113 // CHECK:                "file-deps": [
114 // CHECK-NEXT:             "[[PREFIX]]/tu.m"
115 // CHECK-NEXT:           ],
116 // CHECK-NEXT:           "input-file": "[[PREFIX]]/tu.m"
117 // CHECK-NEXT:         }
118 // CHECK-NEXT:       ]
119 // CHECK-NEXT:     }
120 // CHECK-NEXT:   ]
121 // CHECK-NEXT: }
123 // Check that building FW succeeds. If FW_Private was to be treated textually,
124 // building FW would fail due to Dependency not being present on the command line.
125 // RUN: %deps-to-rsp %t/deps.json --module-name=Dependency > %t/Dependency.cc1.rsp
126 // RUN: %deps-to-rsp %t/deps.json --module-name=FW_Private > %t/FW_Private.cc1.rsp
127 // RUN: %deps-to-rsp %t/deps.json --module-name=FW > %t/FW.cc1.rsp
128 // RUN: %deps-to-rsp %t/deps.json --tu-index=0 > %t/tu.rsp
130 // RUN: %clang @%t/Dependency.cc1.rsp
131 // RUN: %clang @%t/FW_Private.cc1.rsp
132 // RUN: %clang @%t/FW.cc1.rsp
133 // RUN: %clang @%t/tu.rsp