15
15
# Constants
16
16
17
17
PACKAGE_DIR = os .path .dirname (os .path .realpath (__file__ ))
18
- WORKSPACE_DIR = os .path .realpath (PACKAGE_DIR + '/..' )
18
+ WORKSPACE_DIR = os .path .dirname (PACKAGE_DIR )
19
19
20
- INCR_TRANSFER_ROUNDTRIP_EXEC = \
21
- WORKSPACE_DIR + '/ swift/utils/incrparse/incr_transfer_round_trip.py'
20
+ LLVM_DIR = os . path . join ( WORKSPACE_DIR , 'llvm-project' , 'llvm' )
21
+ SWIFT_DIR = os . path . join ( WORKSPACE_DIR , ' swift' )
22
22
23
- GYB_EXEC = os .path .join (WORKSPACE_DIR , 'swift' , 'utils' , 'gyb' )
23
+ INCR_TRANSFER_ROUNDTRIP_EXEC = os .path .join (
24
+ SWIFT_DIR , 'utils' , 'incrparse' , 'incr_transfer_round_trip.py' )
24
25
25
- LIT_EXEC = WORKSPACE_DIR + '/llvm-project/llvm/utils/lit/lit.py'
26
+ GYB_EXEC = os .path .join (
27
+ SWIFT_DIR , 'utils' , 'gyb' )
26
28
27
- GROUP_INFO_PATH = PACKAGE_DIR + '/utils/group.json'
29
+ LIT_EXEC = os .path .join (
30
+ LLVM_DIR , 'utils' , 'lit' , 'lit.py' )
31
+
32
+ GROUP_INFO_PATH = os .path .join (
33
+ PACKAGE_DIR , 'utils' , 'group.json' )
28
34
29
35
BASE_KIND_FILES = {
30
36
'Decl' : 'SyntaxDeclNodes.swift' ,
@@ -126,20 +132,24 @@ def generate_single_gyb_file(gyb_exec, gyb_file, output_file_name, destination,
126
132
[] if add_source_locations else ['--line-directive=' ])
127
133
128
134
# Generate the new file
129
- check_call ([gyb_exec ] +
130
- [gyb_file ] +
131
- ['-o' , temp_files_dir + '/' + output_file_name ] +
132
- line_directive_flags +
133
- additional_gyb_flags ,
134
- verbose = verbose )
135
+ gyb_command = [
136
+ gyb_exec , gyb_file ,
137
+ '-o' , os .path .join (temp_files_dir , output_file_name ),
138
+ ]
139
+ gyb_command += line_directive_flags
140
+ gyb_command += additional_gyb_flags
141
+
142
+ check_call (gyb_command , verbose = verbose )
135
143
136
144
# Copy the file if different from the file already present in
137
145
# gyb_generated
138
- check_call (['rsync' ] +
139
- ['--checksum' ] +
140
- [temp_files_dir + '/' + output_file_name ] +
141
- [destination + '/' + output_file_name ],
142
- verbose = verbose )
146
+ rsync_command = [
147
+ 'rsync' , '--checksum' ,
148
+ os .path .join (temp_files_dir , output_file_name ),
149
+ os .path .join (destination , output_file_name ),
150
+ ]
151
+
152
+ check_call (rsync_command , verbose = verbose )
143
153
144
154
145
155
def generate_gyb_files (gyb_exec , verbose , add_source_locations ,
@@ -149,8 +159,8 @@ def generate_gyb_files(gyb_exec, verbose, add_source_locations,
149
159
check_gyb_exec (gyb_exec )
150
160
check_rsync ()
151
161
152
- swiftsyntax_sources_dir = os .path .join (PACKAGE_DIR , 'Sources' ,
153
- 'SwiftSyntax' )
162
+ swiftsyntax_sources_dir = os .path .join (
163
+ PACKAGE_DIR , 'Sources' , 'SwiftSyntax' )
154
164
temp_files_dir = tempfile .gettempdir ()
155
165
156
166
if destination is None :
@@ -189,11 +199,13 @@ def generate_gyb_files(gyb_exec, verbose, add_source_locations,
189
199
if not gyb_file .endswith ('.gyb' ):
190
200
continue
191
201
202
+ gyb_file_path = os .path .join (swiftsyntax_sources_dir , gyb_file )
203
+
192
204
# Slice off the '.gyb' to get the name for the output file
193
205
output_file_name = gyb_file [:- 4 ]
194
206
195
207
generate_single_gyb_file (gyb_exec ,
196
- swiftsyntax_sources_dir + '/' + gyb_file ,
208
+ gyb_file_path ,
197
209
output_file_name , destination ,
198
210
temp_files_dir , add_source_locations ,
199
211
additional_gyb_flags = [],
@@ -202,7 +214,8 @@ def generate_gyb_files(gyb_exec, verbose, add_source_locations,
202
214
for base_kind in BASE_KIND_FILES :
203
215
output_file_name = BASE_KIND_FILES [base_kind ]
204
216
205
- gyb_file = swiftsyntax_sources_dir + '/SyntaxNodes.swift.gyb.template'
217
+ gyb_file = os .path .join (
218
+ swiftsyntax_sources_dir , 'SyntaxNodes.swift.gyb.template' )
206
219
207
220
generate_single_gyb_file (gyb_exec , gyb_file , output_file_name ,
208
221
template_destination , temp_files_dir ,
@@ -271,8 +284,9 @@ def build(self, product_name, module_group_path=''):
271
284
# Testing
272
285
273
286
def verify_generated_files (gyb_exec , verbose ):
274
- user_generated_dir = os .path .join (PACKAGE_DIR , 'Sources' , 'SwiftSyntax' ,
275
- 'gyb_generated' )
287
+ user_generated_dir = os .path .join (
288
+ PACKAGE_DIR , 'Sources' , 'SwiftSyntax' , 'gyb_generated' )
289
+
276
290
self_generated_dir = tempfile .mkdtemp ()
277
291
generate_gyb_files (gyb_exec , verbose = verbose ,
278
292
add_source_locations = False ,
@@ -346,7 +360,7 @@ def find_lit_test_helper_exec(toolchain, build_dir, release):
346
360
swiftpm_call .extend (['--show-bin-path' ])
347
361
348
362
bin_dir = subprocess .check_output (swiftpm_call , stderr = subprocess .STDOUT )
349
- return bin_dir .strip () + '/ lit-test-helper'
363
+ return os . path . join ( bin_dir .strip (), ' lit-test-helper')
350
364
351
365
352
366
def run_lit_tests (toolchain , build_dir , release , filecheck_exec , verbose ):
@@ -361,7 +375,7 @@ def run_lit_tests(toolchain, build_dir, release, filecheck_exec, verbose):
361
375
release = release )
362
376
363
377
lit_call = [LIT_EXEC ]
364
- lit_call .extend ([ PACKAGE_DIR + '/ lit_tests'] )
378
+ lit_call .append ( os . path . join ( PACKAGE_DIR , ' lit_tests') )
365
379
366
380
if filecheck_exec :
367
381
lit_call .extend (['--param' , 'FILECHECK=' + filecheck_exec ])
@@ -431,22 +445,26 @@ def check_and_sync(file_path, install_path):
431
445
432
446
433
447
def install (build_dir , dylib_dir , swiftmodule_base_name , stdlib_rpath ):
434
- dylibPath = build_dir + '/libSwiftSyntax.dylib'
435
- modulePath = build_dir + '/SwiftSyntax.swiftmodule'
436
- docPath = build_dir + '/SwiftSyntax.swiftdoc'
448
+ dylib_name = get_installed_dylib_name ()
449
+
450
+ dylib_path = os .path .join (build_dir , dylib_name )
451
+ module_path = os .path .join (build_dir , 'SwiftSyntax.swiftmodule' )
452
+ doc_path = os .path .join (build_dir , 'SwiftSyntax.swiftdoc' )
453
+
437
454
# users should find the dylib as if it's a part of stdlib.
438
- change_id_rpath ('@rpath/' + get_installed_dylib_name (), dylibPath )
455
+ change_id_rpath (os .path .join ('@rpath' , dylib_name ), dylib_path )
456
+
439
457
# we don't wanna hard-code the stdlib dylibs into rpath.
440
- delete_rpath (stdlib_rpath , dylibPath )
441
- check_and_sync (file_path = dylibPath ,
442
- install_path = dylib_dir + '/' + get_installed_dylib_name ())
458
+ delete_rpath (stdlib_rpath , dylib_path )
459
+ check_and_sync (file_path = dylib_path ,
460
+ install_path = os .path .join (dylib_dir , dylib_name ))
461
+
443
462
# Optionally install .swiftmodule
444
463
if swiftmodule_base_name :
445
464
module_dest = swiftmodule_base_name + '.swiftmodule'
446
465
doc_dest = swiftmodule_base_name + '.swiftdoc'
447
- check_and_sync (file_path = modulePath , install_path = module_dest )
448
- check_and_sync (file_path = docPath , install_path = doc_dest )
449
- return
466
+ check_and_sync (file_path = module_path , install_path = module_dest )
467
+ check_and_sync (file_path = doc_path , install_path = doc_dest )
450
468
451
469
452
470
# -----------------------------------------------------------------------------
@@ -606,10 +624,10 @@ def main():
606
624
if not args .build_dir :
607
625
fatal_error ('Must specify build directory to copy from' )
608
626
if args .release :
609
- build_dir = args .build_dir + '/ release'
627
+ build_dir = os . path . join ( args .build_dir , ' release')
610
628
else :
611
629
# will this ever happen?
612
- build_dir = args .build_dir + '/ debug'
630
+ build_dir = os . path . join ( args .build_dir , ' debug')
613
631
stdlib_rpath = os .path .join (
614
632
args .toolchain , 'usr' , 'lib' , 'swift' , 'macosx' )
615
633
install (build_dir = build_dir , dylib_dir = args .dylib_dir ,
0 commit comments