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
@@ -13,52 +9,139 @@ import re
13
9
import shutil
14
10
import sys
15
11
import subprocess
12
+ import platform
16
13
17
14
# 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' ]
15
+ ADT_imports = [
16
+ 'APFloat' ,
17
+ 'APInt' ,
18
+ 'APSInt' ,
19
+ 'AllocatorList' ,
20
+ 'ArrayRef' ,
21
+ 'Bit' ,
22
+ 'DenseMap' ,
23
+ 'DenseMapInfo' ,
24
+ 'DenseSet' ,
25
+ 'EpochTracker' ,
26
+ 'FoldingSet' ,
27
+ 'Hashing' ,
28
+ 'IntrusiveRefCntPtr' ,
29
+ 'None' ,
30
+ 'Optional' ,
31
+ 'PointerIntPair' ,
32
+ 'PointerUnion' ,
33
+ 'STLExtras' ,
34
+ 'SmallPtrSet' ,
35
+ 'SmallSet' ,
36
+ 'SmallString' ,
37
+ 'SmallVector' ,
38
+ 'Statistic' ,
39
+ 'StringExtras' ,
40
+ 'StringMap' ,
41
+ 'StringRef' ,
42
+ 'StringSet' ,
43
+ 'StringSwitch' ,
44
+ 'Triple' ,
45
+ 'Twine' ,
46
+ 'edit_distance' ,
47
+ 'ilist' ,
48
+ 'ilist_base' ,
49
+ 'ilist_iterator' ,
50
+ 'ilist_node' ,
51
+ 'ilist_node_base' ,
52
+ 'ilist_node_options' ,
53
+ 'iterator' ,
54
+ 'iterator_range' ,
55
+ 'simple_ilist'
56
+ ]
34
57
35
58
# Support types and infrastructure.
36
59
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' ]
60
+ 'AArch64TargetParser' ,
61
+ 'APFloat' ,
62
+ 'ARMBuildAttributes' ,
63
+ 'ARMTargetParser' ,
64
+ 'AlignOf' ,
65
+ 'Allocator' ,
66
+ 'Atomic' ,
67
+ 'CBindingWrapping' ,
68
+ 'Casting' ,
69
+ 'Chrono' ,
70
+ 'CommandLine' ,
71
+ 'Compiler' ,
72
+ 'ConvertUTF' ,
73
+ 'ConvertUTFWrapper' ,
74
+ 'DJB' ,
75
+ 'DataTypes' ,
76
+ 'Debug' ,
77
+ 'Endian' ,
78
+ 'Errc' ,
79
+ 'Errno' ,
80
+ 'Error' ,
81
+ 'ErrorHandling' ,
82
+ 'ErrorOr' ,
83
+ 'FileSystem' ,
84
+ 'FileUtilities' ,
85
+ 'Format' ,
86
+ 'FormatAdapters' ,
87
+ 'FormatCommon' ,
88
+ 'FormatProviders' ,
89
+ 'FormatVariadic' ,
90
+ 'FormatVariadicDetails' ,
91
+ 'Host' ,
92
+ 'LineIterator' ,
93
+ 'Locale' ,
94
+ 'MD5' ,
95
+ 'ManagedStatic' ,
96
+ 'MathExtras' ,
97
+ 'MemAlloc' ,
98
+ 'Memory' ,
99
+ 'MemoryBuffer' ,
100
+ 'Mutex' ,
101
+ 'MutexGuard' ,
102
+ 'NativeFormatting' ,
103
+ 'Options' ,
104
+ 'Path' ,
105
+ 'PointerLikeTypeTraits' ,
106
+ 'Process' ,
107
+ 'Program' ,
108
+ 'Recycler' ,
109
+ 'ReverseIteration' ,
110
+ 'SMLoc' ,
111
+ 'Signals' ,
112
+ 'SmallVectorMemoryBuffer' ,
113
+ 'SourceMgr' ,
114
+ 'StringSaver' ,
115
+ 'Support' ,
116
+ 'SwapByteOrder' ,
117
+ 'TargetParser' ,
118
+ 'Threading' ,
119
+ 'Timer' ,
120
+ 'Types' ,
121
+ 'Unicode' ,
122
+ 'Unicode' ,
123
+ 'UnicodeCaseFold' ,
124
+ 'UnicodeCharRanges' ,
125
+ 'UniqueLock' ,
126
+ 'Unix' ,
127
+ 'Valgrind' ,
128
+ 'VersionTuple' ,
129
+ 'WindowsError' ,
130
+ 'WindowsSupport' ,
131
+ 'WithColor' ,
132
+ 'X86TargetParser' ,
133
+ 'circular_raw_ostream' ,
134
+ 'raw_ostream' ,
135
+ 'type_traits'
136
+ ]
53
137
54
138
# 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' ])
139
+ C_imports = [
140
+ 'DataTypes' ,
141
+ 'ErrorHandling' ,
142
+ 'Support' ,
143
+ 'Types'
144
+ ]
62
145
63
146
llvm_srcroot = None
64
147
sourcekit_srcroot = None
@@ -80,6 +163,10 @@ def copyfile(src, dst):
80
163
note ("cp %r %r" % (src , dst ))
81
164
shutil .copyfile (src , dst )
82
165
166
+ def movefile (src , dst ):
167
+ note ("mv %r %r" % (src , dst ))
168
+ shutil .movefile (src , dst )
169
+
83
170
def includes_prefix (source , include_dir ):
84
171
defs = subprocess .check_output ([
85
172
'clang' , '-std=c++14' , '-dM' , '-E' ,
@@ -137,12 +224,32 @@ def main():
137
224
llvm_srcroot , = args
138
225
sourcekit_srcroot = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
139
226
227
+ # Remove the old llvm import
228
+ sourcekit_llvm_include = os .path .join (sourcekit_srcroot , 'include' , 'llvm' )
229
+ sourcekit_llvm_lib = os .path .join (sourcekit_srcroot , 'lib' , 'LLVMSupport' )
230
+ if os .path .exists (sourcekit_llvm_include ):
231
+ shutil .rmtree (sourcekit_llvm_include )
232
+ if os .path .exists (sourcekit_llvm_lib ):
233
+ shutil .rmtree (sourcekit_llvm_lib )
234
+
235
+ # Add the platform specific config files
236
+ #
237
+ # NOTE: If you're updating to a newer llvm, you may have to manually merge
238
+ # these with the newer version produced by the llvm build
239
+ sourcekit_llvm_config = os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'include' , 'llvm' , 'Config' )
240
+ shutil .copytree (sourcekit_llvm_config , os .path .join (sourcekit_llvm_include , 'Config' ))
241
+
140
242
def import_header (dir , name ):
141
243
src = os .path .join (llvm_srcroot , 'include' , 'llvm' , dir , name )
244
+ c_src = os .path .join (llvm_srcroot , 'include' , 'llvm-c' , name )
142
245
if os .path .exists (src ):
143
246
dst = os .path .join (sourcekit_srcroot , 'include' , 'llvm' , dir , name )
144
247
mkdir_p (os .path .dirname (dst ))
145
248
copyfile (src , dst )
249
+ if os .path .exists (c_src ):
250
+ dst = os .path .join (sourcekit_srcroot , 'include' , 'llvm-c' , name )
251
+ mkdir_p (os .path .dirname (dst ))
252
+ copyfile (c_src , dst )
146
253
147
254
def import_c_header (name ):
148
255
src = os .path .join (llvm_srcroot , 'include' , 'llvm-c' , name )
@@ -162,23 +269,32 @@ def main():
162
269
163
270
for name in ADT_imports :
164
271
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' )
272
+ import_source ('Support' , name + '.c' )
273
+ import_source ('Support' , name + '.cpp' )
168
274
for name in Support_imports :
169
- if name .endswith ('.def' ):
170
- import_header ('Support' , name )
171
- continue
172
275
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' ))
178
-
276
+ import_header ('Support' , name + '.def' )
277
+ import_source ('Support' , name + '.c' )
278
+ import_source ('Support' , name + '.cpp' )
279
+ import_source ('Support' , name + '.inc' )
280
+ import_source ('Support' , name + '.h' )
281
+ import_source ('Support' , os .path .join ('Unix' , name + '.h' ))
282
+ import_source ('Support' , os .path .join ('Unix' , name + '.inc' ))
283
+ import_source ('Support' , os .path .join ('Windows' , name + '.h' ))
284
+ import_source ('Support' , os .path .join ('Windows' , name + '.inc' ))
179
285
for name in C_imports :
180
286
import_c_header (name + '.h' )
181
287
288
+ # Create symlinks so SwiftPM can find headers
289
+ os .makedirs (os .path .join (sourcekit_llvm_lib , 'include' ))
290
+ os .symlink (os .path .join ('..' , '..' , '..' , 'include' , 'llvm' ),
291
+ os .path .join (sourcekit_llvm_lib , 'include' , 'llvm' ))
292
+ os .symlink (os .path .join ('..' , '..' , '..' , 'include' , 'llvm-c' ),
293
+ os .path .join (sourcekit_llvm_lib , 'include' , 'llvm-c' ))
294
+
295
+ copyfile (os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'lib' , 'LLVMSupport' , 'include' , 'module.modulemap' ),
296
+ os .path .join (sourcekit_srcroot , 'lib' , 'LLVMSupport' , 'include' , 'module.modulemap' ))
297
+
182
298
print ""
183
299
print "Adding prefix header includes"
184
300
@@ -189,11 +305,32 @@ def main():
189
305
]
190
306
191
307
include_dir = os .path .join (sourcekit_srcroot , 'include' )
192
-
193
308
for base in base_dirs :
194
309
for root , dirs , files in os .walk (base ):
195
310
for file in files :
196
311
maybe_add_prefix (os .path .join (root , file ), include_dir )
197
312
313
+ # Finish off with a bunch of really gross hacks. These all offend my better
314
+ # sensibilities and what have you.
315
+
316
+ # TODO: Indexstoredb uses an out of tree/non merged OptionSet.h We should
317
+ # remove uses of this or get it merged upstream.
318
+ copyfile (os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'include' , 'llvm' , 'ADT' , 'OptionSet.h' ),
319
+ os .path .join (sourcekit_srcroot , 'include' , 'llvm' , 'ADT' , 'OptionSet.h' ))
320
+
321
+ # AArch64TargetParser uses a relative path to find the .def file, so we
322
+ # copy this one to the expected location :(
323
+ def_location = os .path .join (sourcekit_srcroot , 'lib' , 'include' , 'llvm' , 'Support' )
324
+ if os .path .exists (def_location ):
325
+ shutil .rmtree (def_location )
326
+ os .makedirs (def_location )
327
+ copyfile (os .path .join (sourcekit_srcroot , 'include' , 'llvm' , 'Support' , 'AArch64TargetParser.def' ),
328
+ os .path .join (def_location , 'AArch64TargetParser.def' ))
329
+
330
+ # Patch out requirements for Demangle and YAML/Regex from the LLVM support we imported
331
+ patch_file = os .path .join (sourcekit_srcroot , 'Utilities' , 'import-llvm.d' , 'RemoveLLVMImports.patch' )
332
+ with open (patch_file , 'r' ) as f :
333
+ subprocess .Popen (['patch' , '-p1' ], stdin = f , cwd = sourcekit_srcroot )
334
+
198
335
if __name__ == '__main__' :
199
336
main ()
0 commit comments