forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlit.cfg
771 lines (656 loc) · 31.8 KB
/
lit.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
##===--- lit.cfg ---------------------------------------------*- Python -*-===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See http://swift.org/LICENSE.txt for license information
## See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
##
##===----------------------------------------------------------------------===##
#
# This is a configuration file for the 'lit' test runner.
#
# Refer to docs/Testing.rst for documentation.
#
# Update docs/Testing.rst when changing this file.
#
##===----------------------------------------------------------------------===##
import os
import platform
import re
import subprocess
import tempfile
import lit.formats
import lit.util
#
# Helper functions.
#
def darwin_get_sdk_version(xcrun_sdk_name):
sdk_path = subprocess.check_output(
[ "xcrun", "--sdk", xcrun_sdk_name, "--show-sdk-path" ]).rstrip()
system_version_plist_path = os.path.join(
sdk_path, "System", "Library", "CoreServices", "SystemVersion.plist")
name = subprocess.check_output(
[ "defaults", "read", system_version_plist_path,
"ProductName" ]).rstrip()
vers = subprocess.check_output(
[ "defaults", "read", system_version_plist_path,
"ProductVersion" ]).rstrip()
build = subprocess.check_output(
[ "defaults", "read", system_version_plist_path,
"ProductBuildVersion" ]).rstrip()
return (name, vers, build)
def darwin_sdk_build_version_split(version):
m = re.search("([0-9]+)([A-Z])([0-9]+)", version)
return (int(m.group(1)), m.group(2), int(m.group(3)))
def darwin_sdk_build_version_cmp(lhs, rhs):
return cmp(
darwin_sdk_build_version_split(lhs),
darwin_sdk_build_version_split(rhs))
# Run sw_vers on the target to be tested and return the results.
def darwin_get_sw_vers(commandPrefix=[]):
name = lit.util.executeCommand(
commandPrefix + ['/usr/bin/sw_vers', '-productName'])[0].rstrip()
vers = lit.util.executeCommand(
commandPrefix + ['/usr/bin/sw_vers', '-productVersion'])[0].rstrip()
build = lit.util.executeCommand(
commandPrefix + ['/usr/bin/sw_vers', '-buildVersion'])[0].rstrip()
return (name, vers, build)
# Returns the "prefix" command that should be prepended to the command line to
# run an executable compiled for iOS or AppleTV simulator.
def get_simulator_command(run_os, xcrun_sdk_name):
(name, vers, build) = darwin_get_sdk_version(xcrun_sdk_name)
if run_os == 'ios':
# There are two binaries for the iOS simulator: 'sim' and 'simctl'.
# 'sim' is only supported for iOS <= 8.1 and early versions of 8.2.
# 'simctl' is supported for iOS >= 8.2.
# 'simctl' used to have a bug where it failed to propagate the exit
# code of the child process. This was fixed only in the middle of 8.2
# development cycle.
if ((darwin_sdk_build_version_cmp(build, "12E999") <= 0) or
(darwin_sdk_build_version_cmp("12F1", build) <= 0 and
darwin_sdk_build_version_cmp(build, "12F12") <= 0) or
(darwin_sdk_build_version_cmp("12H1", build) <= 0 and
darwin_sdk_build_version_cmp(build, "12H11") <= 0)):
return "sim"
else:
return "simctl spawn 'iPhone 6'"
elif run_os == 'tvos':
return "simctl spawn 'Apple TV 1080p'"
elif run_os == 'watchos':
return "simctl spawn 'Apple Watch - 42mm'"
else:
lit_config.fatal("Unknown simulator OS %r" % run_os)
assert darwin_sdk_build_version_cmp("11A1", "12A1") < 0
assert darwin_sdk_build_version_cmp("12A1", "11A1") > 0
assert darwin_sdk_build_version_cmp("11A1", "11B1") < 0
assert darwin_sdk_build_version_cmp("11B1", "11A1") > 0
assert darwin_sdk_build_version_cmp("11A22", "11A100") < 0
assert darwin_sdk_build_version_cmp("11A100", "11A22") > 0
###
# Check that the object root is known.
if config.test_exec_root is None:
# Otherwise, we haven't loaded the site specific configuration (the user is
# probably trying to run on a test file directly, and either the site
# configuration hasn't been created by the build system, or we are in an
# out-of-tree build situation).
# Check for 'swift_site_config' user parameter, and use that if available.
site_cfg = lit_config.params.get('swift_site_config', None)
if site_cfg and os.path.exists(site_cfg):
lit_config.load_config(config, site_cfg)
raise SystemExit
lit_config.fatal("lit must be pointed at a build folder")
###
# name: The name of this test suite.
config.name = 'Swift'
# Tweak the environment appropriately for various platforms.
if platform.system() == 'Darwin':
# Prefer the latest version of the Xcode tools.
config.environment['TOOLCHAINS'] = 'default'
# testFormat: The test format to use to interpret tests.
config.test_format = lit.formats.ShTest(execute_external=True)
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.swift', '.ll', '.sil', '.gyb', '.m']
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
# subdirectories contain auxiliary inputs for various tests in their parent
# directories.
config.excludes = ['Inputs']
if lit_config.params.get('disable_unittests', None) is not None:
config.excludes += ['Unit']
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
# test_exec_root: The root path where tests should be run.
swift_obj_root = getattr(config, 'swift_obj_root', None)
# Set llvm_{src,obj}_root for use by others.
config.llvm_src_root = getattr(config, 'llvm_src_root', None)
config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
def append_to_env_path(directory):
config.environment['PATH'] = \
os.path.pathsep.join((directory, config.environment['PATH']))
# Tweak the PATH to include the tools dir and the scripts dir.
if swift_obj_root is not None:
llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
if not llvm_tools_dir:
lit_config.fatal('No LLVM tools dir set!')
append_to_env_path(llvm_tools_dir)
build_mode = lit_config.params.get('build_mode', '')
append_to_env_path(os.path.join(swift_obj_root, build_mode, 'bin'))
llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
if not llvm_libs_dir:
lit_config.fatal('No LLVM libs dir set!')
path = os.path.join(llvm_libs_dir,
config.environment.get('LD_LIBRARY_PATH',''))
config.environment['LD_LIBRARY_PATH'] = path
native_llvm_tools_path = lit_config.params.get('native_llvm_tools_path')
if native_llvm_tools_path is not None:
append_to_env_path(native_llvm_tools_path)
native_clang_tools_path = lit_config.params.get('native_clang_tools_path')
if native_clang_tools_path is not None:
append_to_env_path(native_clang_tools_path)
native_swift_tools_path = lit_config.params.get('native_swift_tools_path')
if native_swift_tools_path is not None:
append_to_env_path(native_swift_tools_path)
###
# Discover the Swift binaries to use.
def inferSwiftBinary(binaryName):
# Determine which executable to use.
envVarName = binaryName.upper().replace("-", "_")
execPath = os.getenv(envVarName)
# If the user set the variable in the environment, definitely use that and
# don't try to validate.
if execPath:
return execPath
# Otherwise look in the path.
PATH = config.environment['PATH']
execPath = lit.util.which(binaryName, PATH)
if execPath:
if not lit_config.quiet:
lit_config.note('using %s: %s' % (binaryName, execPath))
else:
msg = "couldn't find '%s' program, try setting %s in your environment"
lit_config.warning(msg % (binaryName, envVarName))
# Just substitute the plain executable name, so the run line remains
# reasonable.
execPath = binaryName
return execPath
if 'gmalloc' in lit_config.params:
config.environment['DYLD_INSERT_LIBRARIES'] = '/usr/lib/libgmalloc.dylib'
config.environment['MALLOC_LOG_FILE'] = '/dev/null'
config.available_features.add('gmalloc')
# Make inferSwiftBinary() available to be used later on.
config.inferSwiftBinary = inferSwiftBinary
config.swift = inferSwiftBinary('swift')
config.swiftc = inferSwiftBinary('swiftc')
config.swift_autolink_extract = inferSwiftBinary('swift-autolink-extract')
config.sil_opt = inferSwiftBinary('sil-opt')
config.sil_extract = inferSwiftBinary('sil-extract')
config.lldb_moduleimport_test = inferSwiftBinary('lldb-moduleimport-test')
config.swift_ide_test = inferSwiftBinary('swift-ide-test')
config.clang = inferSwiftBinary('clang')
config.llvm_link = inferSwiftBinary('llvm-link')
config.swift_llvm_opt = inferSwiftBinary('swift-llvm-opt')
config.gyb = os.path.join(config.swift_src_root, 'utils', 'gyb')
config.swift_lib_dir = os.path.join(os.path.dirname(os.path.dirname(config.swift)), 'lib')
if os.path.isabs(config.swift_autolink_extract):
config.available_features.add('swift-autolink-extract')
# Find the resource directory. Assume it's near the swift compiler if not set.
test_resource_dir = lit_config.params.get('test_resource_dir')
if test_resource_dir:
resource_dir_opt = ("-resource-dir %s" % test_resource_dir)
else:
test_resource_dir = os.path.join(config.swift_lib_dir, 'swift')
resource_dir_opt = ""
stdlib_resource_dir_opt = resource_dir_opt
lit_config.note('Using resource dir: ' + test_resource_dir)
# Parse the variant triple.
(run_cpu, run_vendor, run_os, run_vers) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups()
run_ptrsize = '64' if '64' in run_cpu else '32'
sdk_overlay_link_path = ""
sdk_overlay_linker_opt = ""
sdk_overlay_dir_opt = ""
test_sdk_overlay_dir = lit_config.params.get('test_sdk_overlay_dir', None)
if test_sdk_overlay_dir is not None:
sdk_overlay_dir_opt = ("-I %s" % os.path.join(test_sdk_overlay_dir, run_cpu))
sdk_overlay_link_path_dir = os.path.join(test_sdk_overlay_dir, run_cpu)
sdk_overlay_link_path = ("-L %s" % sdk_overlay_link_path_dir)
sdk_overlay_linker_opt = (
"-L %s -Xlinker -rpath -Xlinker %s" %
(sdk_overlay_link_path_dir, sdk_overlay_link_path_dir))
lit_config.note('Using SDK overlay dir: ' + test_sdk_overlay_dir)
resource_dir_opt += (" %s" % sdk_overlay_dir_opt)
test_options = os.environ.get('SWIFT_TEST_OPTIONS')
config.swift_test_options = ' ' + test_options if test_options else ''
clang_module_cache_path = tempfile.mkdtemp(prefix="swift-testsuite-clang-module-cache")
mcp_opt = "-module-cache-path %r" % clang_module_cache_path
clang_mcp_opt = "-fmodules-cache-path=%r" % clang_module_cache_path
lit_config.note("Using Clang module cache: " + clang_module_cache_path)
completion_cache_path = tempfile.mkdtemp(prefix="swift-testsuite-completion-cache")
ccp_opt = "-completion-cache-path %r" % completion_cache_path
lit_config.note("Using code completion cache: " + completion_cache_path)
config.substitutions.append( ('%mcp_opt', mcp_opt) )
config.substitutions.append( ('%swift_driver_plain', "%r" % config.swift) )
config.substitutions.append( ('%swiftc_driver_plain', "%r" % config.swiftc) )
config.substitutions.append( ('%swift_driver', "env SDKROOT= %r %s%s" % (config.swift, mcp_opt, config.swift_test_options)) )
config.substitutions.append( ('%swiftc_driver', "env SDKROOT= %r %s%s" % (config.swiftc, mcp_opt, config.swift_test_options)) )
config.substitutions.append( ('%sil-opt', "%r %s" % (config.sil_opt, mcp_opt)) )
config.substitutions.append( ('%sil-extract', "%r %s" % (config.sil_extract, mcp_opt)) )
config.substitutions.append( ('%lldb-moduleimport-test', "%r %s" % (config.lldb_moduleimport_test, mcp_opt)) )
config.substitutions.append( ('%swift-ide-test_plain', config.swift_ide_test) )
config.substitutions.append( ('%swift-ide-test', "%r %s %s" % (config.swift_ide_test, mcp_opt, ccp_opt)) )
config.substitutions.append( ('%llvm-link', config.llvm_link) )
config.substitutions.append( ('%swift-llvm-opt', config.swift_llvm_opt) )
# This must come after all substitutions containing "%swift".
config.substitutions.append(
('%swift', "%r -frontend %s -disable-objc-attr-requires-foundation-module%s"
% (config.swift, mcp_opt, config.swift_test_options)) )
config.clang_include_dir = \
os.path.join(os.path.dirname(os.path.dirname(config.swift)), 'include')
config.substitutions.append( ('%clang-include-dir', config.clang_include_dir) )
# FIXME: BEGIN -enable-source-import hackaround
config.substitutions.append(
('%clang-importer-sdk-path',
'%r/Inputs/clang-importer-sdk' %
(config.test_source_root) ) )
config.substitutions.append(
('%clang-importer-sdk-nosource',
'-sdk %r/Inputs/clang-importer-sdk ' %
(config.test_source_root) ) )
# FIXME: END -enable-source-import hackaround
config.substitutions.append(
('%clang-importer-sdk',
'-enable-source-import '
'-sdk %r/Inputs/clang-importer-sdk '
'-I %r/Inputs/clang-importer-sdk/swift-modules ' %
(config.test_source_root, config.test_source_root) ) )
config.substitutions.append( ('%clang_apinotes',
"%r -cc1apinotes" %
(config.clang)) )
# This must come after all substitutions containing "%clang".
# Note: %clang is the locally-built clang.
# To get Xcode's clang, use %target-clang.
config.substitutions.append( ('%clang',
"%r %r" %
(config.clang, clang_mcp_opt)) )
###
def disallow(execName):
warning = '''
echo '*** Do not use \'{0}\' in tests; use \'%''{0}\'. ***' &&
exit 1 && echo
'''
config.substitutions.append((' {0} '.format(execName),
warning.format(execName)))
disallow('swift')
disallow('swiftc')
disallow('swift_driver')
disallow('swiftc_driver')
disallow('sil-opt')
disallow('sil-extract')
disallow('lldb-moduleimport-test')
disallow('swift-ide-test')
disallow('clang')
config.substitutions.insert(0,
('%p',
'$(echo "*** Use %""S instead of %""p in the Swift test suite ***" >&2)'))
###
# Set available features we allow tests to conditionalize on.
if platform.system() != 'Windows':
config.available_features.add('crash-recovery')
# Add each available build target CPU as a feature.
for target in config.targets_to_build.split():
config.available_features.add(target)
# Add the run target CPU, OS, and pointer size as features.
config.available_features.add("CPU=" + run_cpu)
config.available_features.add("OS=" + run_os)
config.available_features.add("PTRSIZE=" + run_ptrsize)
if run_cpu == "i386" or run_cpu == "x86_64":
config.available_features.add("CPU=i386_or_x86_64")
if "optimized_stdlib" in config.available_features:
config.available_features.add("optimized_stdlib_" + run_cpu)
swift_test_mode = lit_config.params.get('swift_test_mode', 'optimize_none')
swift_execution_tests_extra_flags = ''
if swift_test_mode == 'optimize_none':
config.available_features.add("swift_test_mode_optimize_none")
# Add the cpu as a feature so we can selectively disable tests in an
# optimize mode for a cpu.
config.available_features.add("swift_test_mode_optimize_none_" + run_cpu)
swift_execution_tests_extra_flags = ''
elif swift_test_mode == 'optimize':
config.available_features.add("swift_test_mode_optimize")
# Add the cpu as a feature so we can selectively disable tests in an
# optimize mode for a cpu.
config.available_features.add("swift_test_mode_optimize_" + run_cpu)
swift_execution_tests_extra_flags = '-O'
elif swift_test_mode == 'optimize_unchecked':
# Add the cpu as a feature so we can selectively disable tests in an
# optimize mode for a cpu.
config.available_features.add("swift_test_mode_optimize_unchecked_" + run_cpu)
config.available_features.add("swift_test_mode_optimize_unchecked")
swift_execution_tests_extra_flags = '-Ounchecked'
else:
lit_config.fatal("Unknown test mode %r" % swift_test_mode)
# Only run the subset of tests that require 'executable_test'?
swift_run_only_tests = lit_config.params.get('run_only_tests', 'all')
if swift_run_only_tests != 'all':
config.available_features.add("executable_test")
config.limit_to_features.add(swift_run_only_tests)
else:
config.available_features.add("executable_test")
# Add substitutions for the run target triple, CPU, OS, and pointer size.
config.substitutions.append(('%target-triple', config.variant_triple))
config.substitutions.append(('%target-cpu', run_cpu))
config.substitutions.append(('%target-os', run_os))
config.substitutions.append(('%target-ptrsize', run_ptrsize))
# Enable Darwin SDK-dependent tests if we have an SDK.
# On Linux, assume that SDK path does not point to the Darwin SDK.
if config.variant_sdk != "":
config.substitutions.append(('%sdk', '"%s"' % config.variant_sdk))
# Enable interpreter-based tests on platforms where the interpreter is known to
# work.
if platform.system() == 'Darwin' and (run_os == 'macosx' or run_os == 'darwin'):
# Disable REPL tests if SDK overlay is not in the resource dir.
# <rdar://problem/16678410> Adding more libraries with -lfoo to REPL is broken
config.available_features.add('swift_interpreter')
config.available_features.add('swift_repl')
config.target_swiftmodule_name = "unknown.swiftmodule"
config.target_swiftdoc_name = "unknown.swiftdoc"
config.target_runtime = "unknown"
if run_vendor == 'apple':
config.available_features.add('objc_interop')
config.target_swiftmodule_name = run_cpu + ".swiftmodule"
config.target_swiftdoc_name = run_cpu + ".swiftdoc"
config.target_object_format = "macho"
config.target_runtime = "objc"
if 'arm' in run_cpu:
raise RuntimeError('Device tests are not currently supported.')
elif run_os == 'ios' or run_os == 'tvos' or run_os == 'watchos':
# iOS/TVOS simulator
if run_os == 'ios':
lit_config.note("Testing iOS simulator " + config.variant_triple)
xcrun_sdk_name = "iphonesimulator"
elif run_os == 'watchos':
lit_config.note("Testing watchOS simulator " + config.variant_triple)
xcrun_sdk_name = "watchsimulator"
else:
lit_config.note("Testing AppleTV simulator " + config.variant_triple)
xcrun_sdk_name = "appletvsimulator"
xcrun_prefix = (
"xcrun --toolchain XcodeDefault --sdk %s" %
(xcrun_sdk_name, ))
sdk_path = subprocess.check_output(
[ "xcrun", "--sdk", xcrun_sdk_name, "--show-sdk-path" ]).rstrip()
extra_frameworks_dir = os.path.join(
sdk_path, "..", "..", "..", "Developer", "Library", "Frameworks")
target_options = (
"-target %s %s %s" %
(config.variant_triple, resource_dir_opt, mcp_opt))
target_options_for_mock_sdk = (
"-target %s %s %s" %
(config.variant_triple, stdlib_resource_dir_opt, mcp_opt))
target_options_for_mock_sdk_after = sdk_overlay_dir_opt
target_cc_options = (
"-arch %s -m%s-simulator-version-min=%s %s" %
(run_cpu, run_os, run_vers, clang_mcp_opt))
config.target_cc_options = target_cc_options
config.target_build_swift = (
"%s %s %s -F %s %s %s %s" %
(xcrun_prefix, config.swiftc, target_options,
extra_frameworks_dir,
sdk_overlay_linker_opt, config.swift_test_options,
swift_execution_tests_extra_flags))
config.target_swift_frontend = (
"%s -frontend %s -sdk %s %s" %
(config.swiftc, target_options, config.variant_sdk,
config.swift_test_options))
subst_target_swift_frontend_mock_sdk = (
"%s -frontend %s -sdk %s %s" %
(config.swiftc, target_options_for_mock_sdk, config.variant_sdk,
config.swift_test_options))
config.target_swift_modulewrap = (
'%s -modulewrap -target %s' %
(config.swiftc, config.variant_triple))
subst_target_swift_frontend_mock_sdk_after = \
target_options_for_mock_sdk_after
config.target_clang = (
"%s clang++ %s" %
(xcrun_prefix, target_cc_options))
# FIXME: allow specification of simulator and version
#
# Note: don't pass '--adopt-pid' to sim. This can trigger a kernel
# panic.
# <rdar://problem/11806093> multithreaded 64-to-32 exec is broken
# (foundation tool launched with sim --adopt-pid occasionally
# segmentation faults)
config.target_run = (
"%s %s " %
(xcrun_prefix, get_simulator_command(run_os, xcrun_sdk_name)))
config.target_sil_opt = (
"%s %s %s" %
(xcrun_prefix, config.sil_opt, target_options))
config.target_swift_ide_test = (
"%s %s %s %s" %
(xcrun_prefix, config.swift_ide_test, target_options, ccp_opt))
subst_target_swift_ide_test_mock_sdk = (
"%s %s %s %s" %
(xcrun_prefix, config.swift_ide_test, target_options_for_mock_sdk, ccp_opt))
subst_target_swift_ide_test_mock_sdk_after = \
target_options_for_mock_sdk_after
config.target_swiftc_driver = (
"%s %s %s" %
(xcrun_prefix, config.swiftc, target_options))
(sw_vers_name, sw_vers_vers, sw_vers_build) = \
darwin_get_sdk_version(xcrun_sdk_name)
if (sw_vers_name == '' or sw_vers_vers == '' or sw_vers_build == ''):
lit_config.fatal('Could not get or decode sw_vers output. ' +
'Perhaps the simulator is not working.')
elif run_os == 'macosx':
# OS X
lit_config.note("Testing OS X " + config.variant_triple)
xcrun_sdk_name = "macosx"
xcrun_prefix = (
"xcrun --toolchain XcodeDefault --sdk %s " %
(xcrun_sdk_name, ))
sdk_path = subprocess.check_output(
[ "xcrun", "--sdk", xcrun_sdk_name, "--show-sdk-path" ]).rstrip()
extra_frameworks_dir = os.path.join(
sdk_path, "..", "..", "..", "Developer", "Library", "Frameworks")
target_options = (
"-target %s %s %s" %
(config.variant_triple, resource_dir_opt, mcp_opt))
target_options_for_mock_sdk = (
"-target %s %s %s" %
(config.variant_triple, stdlib_resource_dir_opt, mcp_opt))
target_options_for_mock_sdk_after = sdk_overlay_dir_opt
target_cc_options = (
"-arch %s -m%s-version-min=%s %s" %
(run_cpu, run_os, run_vers, clang_mcp_opt))
config.target_cc_options = target_cc_options
config.target_build_swift = (
"%s %s %s -F %s -Xlinker -rpath -Xlinker %s %s %s %s"
% (xcrun_prefix, config.swiftc, target_options,
extra_frameworks_dir, extra_frameworks_dir,
sdk_overlay_linker_opt, config.swift_test_options,
swift_execution_tests_extra_flags))
config.target_swift_frontend = (
"%s -frontend %s -sdk %s %s" %
(config.swiftc, target_options, config.variant_sdk,
config.swift_test_options))
subst_target_swift_frontend_mock_sdk = (
"%s -frontend %s -sdk %s %s" %
(config.swiftc, target_options_for_mock_sdk, config.variant_sdk,
config.swift_test_options))
config.target_swift_modulewrap = (
'%s -modulewrap -target %s' %
(config.swiftc, config.variant_triple))
subst_target_swift_frontend_mock_sdk_after = \
target_options_for_mock_sdk_after
config.target_clang = (
"%s clang++ %s" %
(xcrun_prefix, target_cc_options))
config.target_run = ""
if 'interpret' in lit_config.params:
target_run_base = (
xcrun_prefix + '%s %s -module-name main %s %s'
% (config.swift, target_options, config.swift_test_options,
swift_execution_tests_extra_flags))
config.target_run_simple_swift = (
"%s %%s" % (target_run_base))
config.target_run_stdlib_swift = (
"%s -Xfrontend -disable-access-control %%s" % (target_run_base))
config.available_features.add('interpret')
config.target_sil_opt = (
"%s %s %s" %
(xcrun_prefix, config.sil_opt, target_options))
config.target_swift_ide_test = (
"%s %s %s %s" %
(xcrun_prefix, config.swift_ide_test, target_options, ccp_opt))
subst_target_swift_ide_test_mock_sdk = (
"%s %s %s %s" %
(xcrun_prefix, config.swift_ide_test, target_options_for_mock_sdk, ccp_opt))
subst_target_swift_ide_test_mock_sdk_after = \
target_options_for_mock_sdk_after
config.target_swiftc_driver = (
"%s %s %s" %
(xcrun_prefix, config.swiftc, target_options))
(sw_vers_name, sw_vers_vers, sw_vers_build) = \
darwin_get_sw_vers()
else:
lit_config.fatal("Unknown Apple OS '" + run_os + "' " +
"(from " + config.variant_triple + ")")
lit_config.note(
'Running tests on %s version %s (%s)' %
(sw_vers_name, sw_vers_vers, sw_vers_build))
config.target_sdk_name = xcrun_sdk_name
config.target_ld = (
"%s ld -L%s" %
(xcrun_prefix, os.path.join(test_resource_dir, config.target_sdk_name)))
elif run_os == 'linux-gnu':
# Linux
lit_config.note("Testing Linux " + config.variant_triple)
config.target_object_format = "elf"
config.target_runtime = "native"
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
config.target_sdk_name = "linux"
config.target_build_swift = (
'%s -target %s %s %s %s %s'
% (config.swiftc, config.variant_triple, resource_dir_opt, mcp_opt,
config.swift_test_options, swift_execution_tests_extra_flags))
config.target_swift_frontend = (
'%s -frontend -target %s %s'
% (config.swift, config.variant_triple, resource_dir_opt))
subst_target_swift_frontend_mock_sdk = config.target_swift_frontend
subst_target_swift_frontend_mock_sdk_after = ""
config.target_run = ''
if 'interpret' in lit_config.params:
target_run_base = (
'%s -target %s %s %s -module-name main%s %s'
% (config.swift, config.variant_triple, resource_dir_opt,
mcp_opt, config.swift_test_options,
swift_execution_tests_extra_flags))
config.target_run_simple_swift = (
'%s %%s' % (target_run_base))
config.target_run_stdlib_swift = (
'%s -Xfrontend -disable-access-control %%s' % (target_run_base))
config.available_features.add('interpret')
config.target_sil_opt = (
'%s -target %s %s %s' %
(config.sil_opt, config.variant_triple, resource_dir_opt, mcp_opt))
config.target_swift_ide_test = (
'%s -target %s %s %s %s' %
(config.swift_ide_test, config.variant_triple, resource_dir_opt,
mcp_opt, ccp_opt))
subst_target_swift_ide_test_mock_sdk = config.target_swift_ide_test
subst_target_swift_ide_test_mock_sdk_after = ""
config.target_swiftc_driver = (
"%s -target %s %s %s" %
(config.swiftc, config.variant_triple, resource_dir_opt, mcp_opt))
config.target_swift_modulewrap = (
'%s -modulewrap -target %s' %
(config.swiftc, config.variant_triple))
config.target_clang = (
"clang++ -target %s %s" %
(config.variant_triple, clang_mcp_opt))
config.target_ld = (
"ld -L%s" %
(os.path.join(test_resource_dir, config.target_sdk_name)))
else:
lit_config.fatal("Don't know how to define target_run and "
"target_build_swift for platform " + config.variant_triple)
config.substitutions.append(("%target-sdk-name", config.target_sdk_name))
if not getattr(config, 'target_run_simple_swift', None):
config.target_run_simple_swift = (
'rm -rf %%t && mkdir -p %%t && '
'%s %s %%s -o %%t/a.out -module-name main && '
'%s %%t/a.out'
% (config.target_build_swift, mcp_opt, config.target_run))
config.target_run_stdlib_swift = (
'rm -rf %%t && mkdir -p %%t && '
'%s %s %%s -o %%t/a.out -module-name main '
'-Xfrontend -disable-access-control && '
'%s %%t/a.out'
% (config.target_build_swift, mcp_opt, config.target_run))
subst_target_jit_run = ""
if 'swift_interpreter' in config.available_features:
subst_target_jit_run = (
"%s -interpret %s" %
(config.target_swift_frontend, sdk_overlay_link_path))
subst_target_repl_run_simple_swift = ""
if 'swift_repl' in config.available_features:
subst_target_repl_run_simple_swift = (
"%s -repl %s < %%s 2>&1" %
(config.target_swift_frontend, sdk_overlay_link_path))
config.target_parse_verify_swift = (
'%s -parse -verify -disable-objc-attr-requires-foundation-module %%s'
% (config.target_swift_frontend, ))
config.target_sil_extract = (
'%s -target %s %s'
% (config.sil_extract, config.variant_triple, mcp_opt))
#
# When changing substitutions, update docs/Testing.rst.
#
config.substitutions.append(('%target-runtime', config.target_runtime))
config.substitutions.append(('%target-parse-verify-swift', config.target_parse_verify_swift))
config.substitutions.append(
('%target-swift-frontend\(mock-sdk:([^)]+)\)',
'%s \\1 %s' %
(subst_target_swift_frontend_mock_sdk,
subst_target_swift_frontend_mock_sdk_after)))
config.substitutions.append(('%target-swift-frontend', config.target_swift_frontend))
config.substitutions.append(('%target-run-simple-swift', config.target_run_simple_swift))
config.substitutions.append(('%target-run-stdlib-swift', config.target_run_stdlib_swift))
config.substitutions.append(('%target-repl-run-simple-swift', subst_target_repl_run_simple_swift))
config.substitutions.append(('%target-run', config.target_run))
config.substitutions.append(('%target-jit-run', subst_target_jit_run))
config.substitutions.append(('%target-build-swift', config.target_build_swift))
config.substitutions.append(('%target-clang', config.target_clang))
config.substitutions.append(('%target-ld', config.target_ld))
if hasattr(config, 'target_cc_options'):
config.substitutions.append(('%target-cc-options', config.target_cc_options))
config.substitutions.append(('%gyb', config.gyb))
config.substitutions.append(('%target-sil-opt', config.target_sil_opt))
config.substitutions.append(('%target-sil-extract', config.target_sil_extract))
config.substitutions.append(
('%target-swift-ide-test\(mock-sdk:([^)]+)\)',
'%s \\1 %s' %
(subst_target_swift_ide_test_mock_sdk,
subst_target_swift_ide_test_mock_sdk_after)))
config.substitutions.append(('%target-swift-ide-test', config.target_swift_ide_test))
config.substitutions.append(('%target-swiftc_driver', config.target_swiftc_driver))
if hasattr(config, 'target_swift_autolink_extract'):
config.available_features.add('autolink-extract')
config.substitutions.append(('%target-swift-autolink-extract',
config.target_swift_autolink_extract))
config.substitutions.append(('%target-swift-modulewrap',
config.target_swift_modulewrap))
platform_module_dir = os.path.join(test_resource_dir, '%target-sdk-name', run_cpu)
lit_config.note('Using platform module dir: ' + platform_module_dir)
if test_sdk_overlay_dir is not None:
platform_sdk_overlay_dir = os.path.join(test_sdk_overlay_dir, run_cpu)
else:
platform_sdk_overlay_dir = platform_module_dir
config.substitutions.insert(0, ('%platform-module-dir', platform_module_dir))
config.substitutions.insert(0, ('%platform-sdk-overlay-dir', platform_sdk_overlay_dir))
config.substitutions.append(('%target-swiftmodule-name', config.target_swiftmodule_name))
config.substitutions.append(('%target-swiftdoc-name', config.target_swiftdoc_name))
config.substitutions.append(('%target-object-format', config.target_object_format))