xref: /llvm-project/clang/test/ExtractAPI/relative_include.m (revision e05c1b46d0d3739cc48ad912dbe6e9affce05927)
1// RUN: rm -rf %t
2// RUN: split-file %s %t
3
4// Setup framework root
5// RUN: mkdir -p %t/Frameworks/MyFramework.framework/Headers
6// RUN: cp %t/MyFramework.h %t/Frameworks/MyFramework.framework/Headers/
7// RUN: cp %t/MyHeader.h %t/Frameworks/MyFramework.framework/Headers/
8
9// RUN: sed -e "s@SRCROOT@%{/t:regex_replacement}@g" \
10// RUN: %t/reference.output.json.in >> %t/reference.output.json
11
12// Headermap maps headers to the source root SRCROOT
13// RUN: sed -e "s@SRCROOT@%{/t:regex_replacement}@g" \
14// RUN: %t/headermap.hmap.json.in >> %t/headermap.hmap.json
15// RUN: %hmaptool write %t/headermap.hmap.json %t/headermap.hmap
16
17// Input headers use paths to the framework root/DSTROOT
18// RUN: %clang_cc1 -extract-api --pretty-sgf -v --product-name=MyFramework \
19// RUN: -triple arm64-apple-macosx \
20// RUN: -iquote%t -I%t/headermap.hmap -F%t/Frameworks \
21// RUN: -x objective-c-header \
22// RUN: %t/Frameworks/MyFramework.framework/Headers/MyFramework.h \
23// RUN: %t/Frameworks/MyFramework.framework/Headers/MyHeader.h \
24// RUN: %t/QuotedHeader.h \
25// RUN: -o %t/output.json 2>&1 -verify | FileCheck -allow-empty %s
26
27// Generator version is not consistent across test runs, normalize it.
28// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
29// RUN: %t/output.json >> %t/output-normalized.json
30// RUN: diff %t/reference.output.json %t/output-normalized.json
31
32// CHECK:      <extract-api-includes>:
33// CHECK-NEXT: #import <MyFramework/MyFramework.h>
34// CHECK-NEXT: #import <MyFramework/MyHeader.h>
35// CHECK-NEXT: #import "QuotedHeader.h"
36
37//--- headermap.hmap.json.in
38{
39  "mappings" :
40    {
41     "MyFramework/MyHeader.h" : "SRCROOT/MyHeader.h"
42    }
43}
44
45//--- MyFramework.h
46// Umbrella for MyFramework
47#import <MyFramework/MyHeader.h>
48// expected-no-diagnostics
49
50//--- MyHeader.h
51#import <OtherFramework/OtherHeader.h>
52int MyInt;
53// expected-no-diagnostics
54
55//--- QuotedHeader.h
56char MyChar;
57// expected-no-diagnostics
58
59//--- Frameworks/OtherFramework.framework/Headers/OtherHeader.h
60int OtherInt;
61// expected-no-diagnostics
62
63//--- reference.output.json.in
64{
65  "metadata": {
66    "formatVersion": {
67      "major": 0,
68      "minor": 5,
69      "patch": 3
70    },
71    "generator": "?"
72  },
73  "module": {
74    "name": "MyFramework",
75    "platform": {
76      "architecture": "arm64",
77      "operatingSystem": {
78        "minimumVersion": {
79          "major": 11,
80          "minor": 0,
81          "patch": 0
82        },
83        "name": "macosx"
84      },
85      "vendor": "apple"
86    }
87  },
88  "relationships": [],
89  "symbols": [
90    {
91      "accessLevel": "public",
92      "declarationFragments": [
93        {
94          "kind": "typeIdentifier",
95          "preciseIdentifier": "c:I",
96          "spelling": "int"
97        },
98        {
99          "kind": "text",
100          "spelling": " "
101        },
102        {
103          "kind": "identifier",
104          "spelling": "MyInt"
105        },
106        {
107          "kind": "text",
108          "spelling": ";"
109        }
110      ],
111      "identifier": {
112        "interfaceLanguage": "objective-c",
113        "precise": "c:@MyInt"
114      },
115      "kind": {
116        "displayName": "Global Variable",
117        "identifier": "objective-c.var"
118      },
119      "location": {
120        "position": {
121          "character": 4,
122          "line": 1
123        },
124        "uri": "file://SRCROOT/MyHeader.h"
125      },
126      "names": {
127        "navigator": [
128          {
129            "kind": "identifier",
130            "spelling": "MyInt"
131          }
132        ],
133        "subHeading": [
134          {
135            "kind": "identifier",
136            "spelling": "MyInt"
137          }
138        ],
139        "title": "MyInt"
140      },
141      "pathComponents": [
142        "MyInt"
143      ]
144    },
145    {
146      "accessLevel": "public",
147      "declarationFragments": [
148        {
149          "kind": "typeIdentifier",
150          "preciseIdentifier": "c:C",
151          "spelling": "char"
152        },
153        {
154          "kind": "text",
155          "spelling": " "
156        },
157        {
158          "kind": "identifier",
159          "spelling": "MyChar"
160        },
161        {
162          "kind": "text",
163          "spelling": ";"
164        }
165      ],
166      "identifier": {
167        "interfaceLanguage": "objective-c",
168        "precise": "c:@MyChar"
169      },
170      "kind": {
171        "displayName": "Global Variable",
172        "identifier": "objective-c.var"
173      },
174      "location": {
175        "position": {
176          "character": 5,
177          "line": 0
178        },
179        "uri": "file://SRCROOT/QuotedHeader.h"
180      },
181      "names": {
182        "navigator": [
183          {
184            "kind": "identifier",
185            "spelling": "MyChar"
186          }
187        ],
188        "subHeading": [
189          {
190            "kind": "identifier",
191            "spelling": "MyChar"
192          }
193        ],
194        "title": "MyChar"
195      },
196      "pathComponents": [
197        "MyChar"
198      ]
199    }
200  ]
201}
202