|
| 1 | +import os |
| 2 | +import platform |
| 3 | +import tempfile |
| 4 | + |
| 5 | +import lit |
| 6 | + |
| 7 | +# Set up lit config. |
| 8 | +config.name = 'SwiftXCTestFunctionalTests' |
| 9 | +config.test_format = lit.formats.ShTest(execute_external=False) |
| 10 | +config.suffixes = ['.swift'] |
| 11 | + |
| 12 | +# Set up the substitutions used by the functional test suite. |
| 13 | + |
| 14 | +# First, our tests need a way to compile source files into |
| 15 | +# executables that are linked against swift-corelibs-xctest. |
| 16 | +# We'll provide one via the %swiftc substitution. |
| 17 | +# |
| 18 | +# Linux tests are run after swift-corelibs-xctest is installed |
| 19 | +# in the Swift library path, so we only need the path to `swiftc` |
| 20 | +# in order to compile. |
| 21 | +def _getenv(name): |
| 22 | + value = os.getenv(name, None) |
| 23 | + if value is None: |
| 24 | + lit_config.fatal( |
| 25 | + 'Environment variable ${} is not set.\n' |
| 26 | + '$SWIFT_EXEC, $SDKROOT, $BUILT_PRODUCTS_DIR, $PLATFORM_NAME, and ' |
| 27 | + '$MACOSX_DEPLOYMENT_TARGET must all be set for lit tests to ' |
| 28 | + 'run.'.format(name)) |
| 29 | + return value |
| 30 | + |
| 31 | +swift_exec = [_getenv('SWIFT_EXEC')] |
| 32 | + |
| 33 | +if platform.system() == 'Darwin': |
| 34 | + # On OS X, we need to make sure swiftc references the |
| 35 | + # proper SDK, has a deployment target set, and more... |
| 36 | + # Here we rely on environment variables, produced by xcodebuild. |
| 37 | + sdk_root = _getenv('SDKROOT') |
| 38 | + built_products_dir = _getenv('BUILT_PRODUCTS_DIR') |
| 39 | + platform_name = _getenv('PLATFORM_NAME') |
| 40 | + deployment_target = _getenv('MACOSX_DEPLOYMENT_TARGET') |
| 41 | + |
| 42 | + target = '{}-apple-{}{}'.format( |
| 43 | + platform.machine(), platform_name, deployment_target) |
| 44 | + swift_exec.extend([ |
| 45 | + '-sdk', sdk_root, |
| 46 | + '-target', target, |
| 47 | + '-L', built_products_dir, |
| 48 | + '-I', built_products_dir, |
| 49 | + '-F', built_products_dir, |
| 50 | + '-Xlinker', '-rpath', |
| 51 | + '-Xlinker', built_products_dir]) |
| 52 | + |
| 53 | +# Having prepared the swiftc command, we set the substitution. |
| 54 | +config.substitutions.append(('%{swiftc}', ' '.join(swift_exec))) |
| 55 | + |
| 56 | +# Add the %built_tests_dir substitution, which is a temporary |
| 57 | +# directory used to store built files. |
| 58 | +built_tests_dir = tempfile.mkdtemp() |
| 59 | +config.substitutions.append(('%{built_tests_dir}', built_tests_dir)) |
| 60 | + |
| 61 | +# Add the %test_output substitution, which is a temporary file |
| 62 | +# used to store test output. |
| 63 | +test_output = tempfile.mkstemp()[1] |
| 64 | +config.substitutions.append(('%{test_output}', test_output)) |
| 65 | + |
| 66 | +# Add the %xctest_checker substitution, which is a Python script |
| 67 | +# can be used to compare the actual XCTest output to the expected |
| 68 | +# output. |
| 69 | +xctest_checker = os.path.join( |
| 70 | + os.path.dirname(os.path.abspath(__file__)), |
| 71 | + 'xctest_checker', |
| 72 | + 'xctest_checker.py') |
| 73 | +config.substitutions.append(('%{xctest_checker}', xctest_checker)) |
0 commit comments