1
1
#!/usr/bin/env python
2
2
3
3
# This is a helper script for importing the things we use from LLVM.
4
- #
5
- # NOTE: We have slightly modified copies of some of the files, to reduce the
6
- # dependency surface area, so if you run this to update the sources, please
7
- # examine the diffs to remove things that don't make sense.
8
4
9
5
import errno
10
6
import optparse
@@ -15,50 +11,160 @@ import sys
15
11
import subprocess
16
12
17
13
# ADT types.
18
- ADT_imports = ['EpochTracker' , 'iterator' , 'iterator_range' , 'Hashing' , 'None' , 'Optional' ,
19
- 'Statistic' , 'StringExtras' , 'STLExtras' , 'AllocatorList' , 'Triple' ]
20
-
21
- # ADT basic data structures.
22
- ADT_imports += ['APFloat' , 'APInt' , 'APSInt' , 'ArrayRef' , 'PointerIntPair' , 'SetVector' , 'StringRef' , 'StringSwitch' ,
23
- 'Twine' , 'IntrusiveRefCntPtr' , 'ilist' , 'ilist_base' , 'ilist_node' , 'ilist_node_base' ,
24
- 'ilist_node_options' , 'ilist_iterator' , 'simple_ilist' , 'OptionSet' , 'PointerUnion' ]
25
-
26
- # ADT Mapping structures.
27
- ADT_imports += ['DenseMap' , 'DenseMapInfo' , 'DenseSet' , 'FoldingSet' , 'StringMap' , 'StringSet' ]
28
-
29
- # ADT "Small" structures.
30
- ADT_imports += ['SmallPtrSet' , 'SmallSet' , 'SmallString' , 'SmallVector' ]
31
-
32
- # ADT Algorithms.
33
- ADT_imports += ['edit_distance' ]
14
+ ADT_imports = [
15
+ 'APFloat' ,
16
+ 'APInt' ,
17
+ 'APSInt' ,
18
+ 'AllocatorList' ,
19
+ 'ArrayRef' ,
20
+ 'Bit' ,
21
+ 'DenseMap' ,
22
+ 'DenseMapInfo' ,
23
+ 'DenseSet' ,
24
+ 'EpochTracker' ,
25
+ 'FoldingSet' ,
26
+ 'Hashing' ,
27
+ 'IntrusiveRefCntPtr' ,
28
+ 'None' ,
29
+ 'Optional' ,
30
+ 'PointerIntPair' ,
31
+ 'PointerUnion' ,
32
+ 'STLExtras' ,
33
+ 'SmallPtrSet' ,
34
+ 'SmallSet' ,
35
+ 'SmallString' ,
36
+ 'SmallVector' ,
37
+ 'Statistic' ,
38
+ 'StringExtras' ,
39
+ 'StringMap' ,
40
+ 'StringRef' ,
41
+ 'StringSet' ,
42
+ 'StringSwitch' ,
43
+ 'Triple' ,
44
+ 'Twine' ,
45
+ 'edit_distance' ,
46
+ 'ilist' ,
47
+ 'ilist_base' ,
48
+ 'ilist_iterator' ,
49
+ 'ilist_node' ,
50
+ 'ilist_node_base' ,
51
+ 'ilist_node_options' ,
52
+ 'iterator' ,
53
+ 'iterator_range' ,
54
+ 'simple_ilist'
55
+ ]
56
+
57
+
58
+
59
+ Demangle_imports = [
60
+ 'Compiler' ,
61
+ 'ItaniumDemangle' ,
62
+ 'Utility' ,
63
+ 'Demangle' ,
64
+ 'MicrosoftDemangle' ,
65
+ 'MicrosoftDemangleNodes' ,
66
+ 'StringView' ,
67
+ ]
34
68
35
69
# Support types and infrastructure.
36
70
Support_imports = [
37
- 'AlignOf' , 'Allocator' , 'Atomic' , 'CBindingWrapping' , 'Casting' , 'Capacity' , 'CommandLine' , 'Compiler' ,
38
- 'Endian' , 'Errno' , 'ErrorHandling' , 'Errc' , 'ErrorOr' , 'Error' , 'Format' ,
39
- 'ManagedStatic' , 'MathExtras' , 'Mutex' , 'MutexGuard' , 'Memory' ,
40
- 'MemoryBuffer' , 'PointerLikeTypeTraits' , 'Recycler' , 'SwapByteOrder' ,
41
- 'Timer' , 'TimeValue' , 'Threading' , 'Unicode' , 'UniqueLock' , 'Unix' , 'WindowsError' ,
42
- 'Valgrind' , 'circular_raw_ostream' , 'raw_ostream' , 'type_traits' , 'JSON' ]
43
-
44
- # Stuff we don't want, but have to pull in.
45
- Support_imports += [
46
- 'COFF' , 'ConvertUTF' , 'ConvertUTFWrapper' , 'Debug' , 'FileSystem' ,
47
- 'FileUtilities' , 'Host' , 'Locale' , 'MachO' , 'Path' , 'Process' , 'Program' , 'SMLoc' ,
48
- 'SourceMgr' , 'Signals' , 'StringSaver' , 'ToolOutputFile' , 'TrailingObjects' , 'Unicode' , 'UnicodeCharRanges' ,
49
- 'MemAlloc' , 'Chrono' , 'FormatProviders' , 'FormatVariadic' , 'FormatCommon' ,
50
- 'FormatVariadicDetails' , 'NativeFormatting' , 'DJB' , 'ReverseIteration' , 'MD5' ,
51
- 'SmallVectorMemoryBuffer' , 'WithColor' , 'Options' , 'PrettyStackTrace' , 'Watchdog' ,
52
- 'TargetParser' , 'ARMBuildAttributes' , 'ARMTargetParser.def' , 'AArch64TargetParser.def' , 'X86TargetParser.def' , 'LineIterator' ]
71
+ 'AArch64TargetParser' ,
72
+ 'APFloat' ,
73
+ 'ARMBuildAttributes' ,
74
+ 'ARMTargetParser' ,
75
+ 'AlignOf' ,
76
+ 'Allocator' ,
77
+ 'Atomic' ,
78
+ 'CBindingWrapping' ,
79
+ 'Casting' ,
80
+ 'Chrono' ,
81
+ 'CommandLine' ,
82
+ 'Compiler' ,
83
+ 'ConvertUTF' ,
84
+ 'ConvertUTFWrapper' ,
85
+ 'DJB' ,
86
+ 'DataTypes' ,
87
+ 'Debug' ,
88
+ 'Endian' ,
89
+ 'Errc' ,
90
+ 'Errno' ,
91
+ 'Error' ,
92
+ 'ErrorHandling' ,
93
+ 'ErrorOr' ,
94
+ 'FileSystem' ,
95
+ 'FileUtilities' ,
96
+ 'Format' ,
97
+ 'FormatAdapters' ,
98
+ 'FormatCommon' ,
99
+ 'FormatProviders' ,
100
+ 'FormatVariadic' ,
101
+ 'FormatVariadicDetails' ,
102
+ 'Host' ,
103
+ 'LineIterator' ,
104
+ 'Locale' ,
105
+ 'MD5' ,
106
+ 'ManagedStatic' ,
107
+ 'MathExtras' ,
108
+ 'MemAlloc' ,
109
+ 'Memory' ,
110
+ 'MemoryBuffer' ,
111
+ 'Mutex' ,
112
+ 'MutexGuard' ,
113
+ 'NativeFormatting' ,
114
+ 'Options' ,
115
+ 'Path' ,
116
+ 'PointerLikeTypeTraits' ,
117
+ 'Process' ,
118
+ 'Program' ,
119
+ 'Recycler' ,
120
+ 'Regex' ,
121
+ 'ReverseIteration' ,
122
+ 'SMLoc' ,
123
+ 'Signals' ,
124
+ 'SmallVectorMemoryBuffer' ,
125
+ 'SourceMgr' ,
126
+ 'StringSaver' ,
127
+ 'Support' ,
128
+ 'SwapByteOrder' ,
129
+ 'TargetParser' ,
130
+ 'Threading' ,
131
+ 'Timer' ,
132
+ 'Types' ,
133
+ 'Unicode' ,
134
+ 'Unicode' ,
135
+ 'UnicodeCaseFold' ,
136
+ 'UnicodeCharRanges' ,
137
+ 'UniqueLock' ,
138
+ 'Unix' ,
139
+ 'Valgrind' ,
140
+ 'VersionTuple' ,
141
+ 'WindowsError' ,
142
+ 'WindowsSupport' ,
143
+ 'WithColor' ,
144
+ 'X86TargetParser' ,
145
+ 'YAMLParser' ,
146
+ 'YAMLTraits' ,
147
+ 'circular_raw_ostream' ,
148
+ 'raw_ostream' ,
149
+ 'regcomp' ,
150
+ 'regengine' ,
151
+ 'regerror' ,
152
+ 'regex2' ,
153
+ 'regex_impl' ,
154
+ 'regexec' ,
155
+ 'regfree' ,
156
+ 'regstrlcpy' ,
157
+ 'regutils' ,
158
+ 'type_traits'
159
+ ]
53
160
54
161
# Dependencies from llvm-c needed by Support.
55
- C_imports = ['Types' , 'DataTypes' , 'Support' , 'ErrorHandling' ]
56
-
57
- # Support data structures.
58
- Support_imports += ['YAMLParser' , 'YAMLTraits' ]
59
-
60
- # Source files to exclude.
61
- Support_source_excludes = set (['Host' ])
162
+ C_imports = [
163
+ 'DataTypes' ,
164
+ 'ErrorHandling' ,
165
+ 'Support' ,
166
+ 'Types'
167
+ ]
62
168
63
169
llvm_srcroot = None
64
170
sourcekit_srcroot = None
@@ -80,6 +186,10 @@ def copyfile(src, dst):
80
186
note ("cp %r %r" % (src , dst ))
81
187
shutil .copyfile (src , dst )
82
188
189
+ def movefile (src , dst ):
190
+ note ("mv %r %r" % (src , dst ))
191
+ shutil .movefile (src , dst )
192
+
83
193
def includes_prefix (source , include_dir ):
84
194
defs = subprocess .check_output ([
85
195
'clang' , '-std=c++14' , '-dM' , '-E' ,
@@ -137,12 +247,32 @@ def main():
137
247
llvm_srcroot , = args
138
248
sourcekit_srcroot = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
139
249
250
+ # Remove the old llvm import
251
+ sourcekit_llvm_include = os .path .join (sourcekit_srcroot , 'include' , 'llvm' )
252
+ sourcekit_llvm_lib = os .path .join (sourcekit_srcroot , 'lib' , 'LLVMSupport' )
253
+ if os .path .exists (sourcekit_llvm_include ):
254
+ shutil .rmtree (sourcekit_llvm_include )
255
+ if os .path .exists (sourcekit_llvm_lib ):
256
+ shutil .rmtree (sourcekit_llvm_lib )
257
+
258
+ # Add the platform specific config files
259
+ #
260
+ # NOTE: If you're updating to a newer llvm, you may have to manually merge
261
+ # these with the newer version produced by the llvm build
262
+ sourcekit_llvm_config = os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'include' , 'llvm' , 'Config' )
263
+ shutil .copytree (sourcekit_llvm_config , os .path .join (sourcekit_llvm_include , 'Config' ))
264
+
140
265
def import_header (dir , name ):
141
266
src = os .path .join (llvm_srcroot , 'include' , 'llvm' , dir , name )
267
+ c_src = os .path .join (llvm_srcroot , 'include' , 'llvm-c' , name )
142
268
if os .path .exists (src ):
143
269
dst = os .path .join (sourcekit_srcroot , 'include' , 'llvm' , dir , name )
144
270
mkdir_p (os .path .dirname (dst ))
145
271
copyfile (src , dst )
272
+ if os .path .exists (c_src ):
273
+ dst = os .path .join (sourcekit_srcroot , 'include' , 'llvm-c' , name )
274
+ mkdir_p (os .path .dirname (dst ))
275
+ copyfile (c_src , dst )
146
276
147
277
def import_c_header (name ):
148
278
src = os .path .join (llvm_srcroot , 'include' , 'llvm-c' , name )
@@ -162,23 +292,50 @@ def main():
162
292
163
293
for name in ADT_imports :
164
294
import_header ('ADT' , name + '.h' )
165
- if name not in Support_source_excludes :
166
- import_source ('Support' , name + '.c' )
167
- import_source ('Support' , name + '.cpp' )
295
+ import_source ('Support' , name + '.c' )
296
+ import_source ('Support' , name + '.cpp' )
168
297
for name in Support_imports :
169
- if name .endswith ('.def' ):
170
- import_header ('Support' , name )
171
- continue
172
298
import_header ('Support' , name + '.h' )
173
- if name not in Support_source_excludes :
174
- import_source ('Support' , name + '.c' )
175
- import_source ('Support' , name + '.cpp' )
176
- import_source ('Support' , os .path .join ('Unix' , name + '.h' ))
177
- import_source ('Support' , os .path .join ('Unix' , name + '.inc' ))
299
+ import_header ('Support' , name + '.def' )
300
+ import_source ('Support' , name + '.c' )
301
+ import_source ('Support' , name + '.cpp' )
302
+ import_source ('Support' , name + '.inc' )
303
+ import_source ('Support' , name + '.h' )
304
+ import_source ('Support' , os .path .join ('Unix' , name + '.h' ))
305
+ import_source ('Support' , os .path .join ('Unix' , name + '.inc' ))
306
+ import_source ('Support' , os .path .join ('Windows' , name + '.h' ))
307
+ import_source ('Support' , os .path .join ('Windows' , name + '.inc' ))
308
+ for name in Demangle_imports :
309
+ import_header ('Demangle' , name + '.h' )
310
+ import_source ('Demangle' , name + '.cpp' )
178
311
179
312
for name in C_imports :
180
313
import_c_header (name + '.h' )
181
314
315
+ # Create symlinks so SwiftPM can find headers
316
+ os .makedirs (os .path .join (sourcekit_llvm_lib , 'include' ))
317
+ os .symlink (os .path .join ('..' , '..' , '..' , 'include' , 'llvm' ),
318
+ os .path .join (sourcekit_llvm_lib , 'include' , 'llvm' ))
319
+ os .symlink (os .path .join ('..' , '..' , '..' , 'include' , 'llvm-c' ),
320
+ os .path .join (sourcekit_llvm_lib , 'include' , 'llvm-c' ))
321
+
322
+ copyfile (os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'lib' , 'LLVMSupport' , 'include' , 'module.modulemap' ),
323
+ os .path .join (sourcekit_srcroot , 'lib' , 'LLVMSupport' , 'include' , 'module.modulemap' ))
324
+
325
+ # TODO: Indexstoredb uses an out of tree/non merged OptionSet.h We should
326
+ # remove uses of this or get it merged upstream.
327
+ copyfile (os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'include' , 'llvm' , 'ADT' , 'OptionSet.h' ),
328
+ os .path .join (sourcekit_srcroot , 'include' , 'llvm' , 'ADT' , 'OptionSet.h' ))
329
+
330
+ # AArch64TargetParser uses a relative path to find the .def file, so we
331
+ # copy this one to the expected location :(
332
+ def_location = os .path .join (sourcekit_srcroot , 'lib' , 'include' , 'llvm' , 'Support' )
333
+ if os .path .exists (def_location ):
334
+ shutil .rmtree (def_location )
335
+ os .makedirs (def_location )
336
+ copyfile (os .path .join (sourcekit_srcroot , 'include' , 'llvm' , 'Support' , 'AArch64TargetParser.def' ),
337
+ os .path .join (def_location , 'AArch64TargetParser.def' ))
338
+
182
339
print ""
183
340
print "Adding prefix header includes"
184
341
@@ -189,7 +346,6 @@ def main():
189
346
]
190
347
191
348
include_dir = os .path .join (sourcekit_srcroot , 'include' )
192
-
193
349
for base in base_dirs :
194
350
for root , dirs , files in os .walk (base ):
195
351
for file in files :
0 commit comments