|
| 1 | +# -*- Python -*- |
| 2 | + |
| 3 | +import platform |
| 4 | +import os |
| 5 | +import subprocess |
| 6 | + |
| 7 | +import lit.formats |
| 8 | + |
| 9 | +# Configuration file for the 'lit' test runner. |
| 10 | + |
| 11 | +def which(command, paths = None): |
| 12 | + """which(command, [paths]) - Look up the given command in the paths string |
| 13 | + (or the PATH environment variable, if unspecified).""" |
| 14 | + |
| 15 | + if paths is None: |
| 16 | + paths = os.environ.get('PATH','') |
| 17 | + |
| 18 | + # Check for absolute match first. |
| 19 | + if os.path.exists(command): |
| 20 | + return command |
| 21 | + |
| 22 | + # Would be nice if Python had a lib function for this. |
| 23 | + if not paths: |
| 24 | + paths = os.defpath |
| 25 | + |
| 26 | + # Get suffixes to search. |
| 27 | + pathext = os.environ.get('PATHEXT', '').split(os.pathsep) |
| 28 | + |
| 29 | + # Search the paths... |
| 30 | + for path in paths.split(os.pathsep): |
| 31 | + for ext in pathext: |
| 32 | + p = os.path.join(path, command + ext) |
| 33 | + if os.path.exists(p): |
| 34 | + return p |
| 35 | + |
| 36 | + return None |
| 37 | + |
| 38 | +### |
| 39 | +# Retrieve expected values from lit.site.cfg |
| 40 | + |
| 41 | +srcroot = os.path.dirname(os.path.abspath(__file__)) |
| 42 | +srcroot = os.path.normpath(srcroot) |
| 43 | + |
| 44 | +### |
| 45 | +# Basic Configuration Parameters |
| 46 | + |
| 47 | +# name: The name of this test suite. |
| 48 | +config.name = 'swift-package-tests' |
| 49 | + |
| 50 | +# testFormat: The test format to use to interpret tests. |
| 51 | +config.test_format = lit.formats.ShTest(execute_external = False) |
| 52 | + |
| 53 | +# suffixes: A list of file extensions to treat as test files. |
| 54 | +# |
| 55 | +# We override this in specific subdirectories to change what we test. |
| 56 | +config.suffixes = [".txt", ".py"] |
| 57 | + |
| 58 | +# excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 59 | +# subdirectories contain auxiliary inputs for various tests in their parent |
| 60 | +# directories. |
| 61 | +config.excludes = ['Inputs'] |
| 62 | + |
| 63 | +# test_source_root: The root path where tests are located. |
| 64 | +config.test_source_root = os.path.join(srcroot) |
| 65 | + |
| 66 | +# test_source_root: The root path where tests are executing. |
| 67 | +config.test_exec_root = "/tmp/swift-package-tests" |
| 68 | + |
| 69 | +# We don't make use of this yet. |
| 70 | +# |
| 71 | +# FIXME: This is pretty compiler specific and probably should just be ripped out |
| 72 | +# of lit. |
| 73 | +config.target_triple = None |
| 74 | + |
| 75 | +# On Darwin, always push SDKROOT in the environment. |
| 76 | +# |
| 77 | +# FIXME: Eventually, when we use xcrun to launch the toolchain items, this |
| 78 | +# should go away. |
| 79 | +if platform.system() == "Darwin": |
| 80 | + config.environment["SDKROOT"] = subprocess.check_output( |
| 81 | + ["xcrun", "--sdk", "macosx", "--show-sdk-path"]).strip() |
| 82 | + |
| 83 | +### |
| 84 | + |
| 85 | +# Use features like this in lit: |
| 86 | +# # REQUIRES: platform=<platform> |
| 87 | +# where <platform> is Linux or Darwin |
| 88 | +# Add a platform feature. |
| 89 | +config.available_features.add("platform="+platform.system()) |
| 90 | + |
| 91 | +# Check if 'pexpect' is available. |
| 92 | +have_pexpect = False |
| 93 | +try: |
| 94 | + import pexpect |
| 95 | + have_pexpect = True |
| 96 | +except ImportError as e: |
| 97 | + pass |
| 98 | +if have_pexpect: |
| 99 | + config.available_features.add("have-pexpect") |
| 100 | +else: |
| 101 | + lit_config.note("'pexpect' module unavailable, skipping related tests") |
| 102 | + |
| 103 | +# For tests that need access to the outside world, let them know if |
| 104 | +# that's possible |
| 105 | +if lit_config.params.get("have-network"): |
| 106 | + config.available_features.add("have-network") |
| 107 | + |
| 108 | +### |
| 109 | + |
| 110 | +# Get the package path. |
| 111 | +package_path = lit_config.params.get("package-path") |
| 112 | +if package_path is None: |
| 113 | + lit_config.fatal("'--param package-path=PATH' is required") |
| 114 | +package_path = os.path.abspath(package_path) |
| 115 | +# if platform.system() == "Darwin": |
| 116 | +# package_path = os.path.join(package_path, "Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") |
| 117 | +lit_config.note("testing package: %r" % (package_path,)) |
| 118 | + |
| 119 | +# Find the path to FileCheck. We just pick any one out of the build directory. |
| 120 | +swift_build_path = os.path.join(srcroot, "..", "build") |
| 121 | +filecheck_path = lit_config.params.get("filecheck") |
| 122 | +if filecheck_path is None: |
| 123 | + for variant in os.listdir(swift_build_path): |
| 124 | + variant_path = os.path.join(swift_build_path, variant) |
| 125 | + for tree in os.listdir(variant_path): |
| 126 | + if tree.startswith("llvm-"): |
| 127 | + path = os.path.join(variant_path, tree, "bin", "FileCheck") |
| 128 | + if os.path.exists(path): |
| 129 | + filecheck_path = path |
| 130 | + break |
| 131 | +if filecheck_path is None: |
| 132 | + lit_config.fatal("unable to locate FileCheck, '--param filecheck=PATH' is required") |
| 133 | + |
| 134 | +# Use the default Swift src layout if swiftpm is not provided as a |
| 135 | +# param |
| 136 | +swiftpm_srcdir = lit_config.params.get("swiftpm-srcdir") |
| 137 | +if swiftpm_srcdir is None: |
| 138 | + swiftpm_srcdir = os.path.join(srcroot, "..", "swiftpm") |
| 139 | +if os.path.exists(swiftpm_srcdir): |
| 140 | + config.available_features.add("have-swiftpm") |
| 141 | + config.substitutions.append( ('%{swiftpm_srcdir}', swiftpm_srcdir) ) |
| 142 | + |
| 143 | +# Find the tools we need. |
| 144 | +lit_config.note("testing using 'FileCheck': %r" % (filecheck_path,)) |
| 145 | + |
| 146 | +swift_path = os.path.join(package_path, "usr", "bin", "swift") |
| 147 | +lit_config.note("testing using 'swift': %r" % (swift_path,)) |
| 148 | + |
| 149 | +swiftc_path = os.path.join(package_path, "usr", "bin", "swiftc") |
| 150 | +lit_config.note("testing using 'swiftc': %r" % (swiftc_path,)) |
| 151 | + |
| 152 | +lldb_path = os.path.join(package_path, "usr", "bin", "lldb") |
| 153 | +lit_config.note("testing using 'lldb': {}".format(lldb_path)) |
| 154 | + |
| 155 | +# Verify they exist. |
| 156 | +if not os.path.exists(swift_path): |
| 157 | + lit_config.fatal("swift does not exist!") |
| 158 | +if not os.path.exists(swiftc_path): |
| 159 | + lit_config.fatal("swiftc does not exist!") |
| 160 | +if not os.path.exists(filecheck_path): |
| 161 | + lit_config.fatal("filecheck does not exist!") |
| 162 | +if not os.path.exists(lldb_path): |
| 163 | + lit_config.fatal("lldb does not exist!") |
| 164 | + |
| 165 | +# Define our supported substitutions. |
| 166 | +config.substitutions.append( ('%{lldb}', lldb_path) ) |
| 167 | +config.substitutions.append( ('%{swift}', swift_path) ) |
| 168 | +config.substitutions.append( ('%{swiftc}', swiftc_path) ) |
| 169 | +config.substitutions.append( ('%{FileCheck}', filecheck_path) ) |
| 170 | + |
| 171 | +### |
| 172 | + |
| 173 | +# Protected against unquoted use of substitutions. |
| 174 | +for name in ('swift-build', 'FileCheck'): |
| 175 | + config.substitutions.append((' {0} '.format(name), |
| 176 | + ' unquoted-command-name-{0} '.format(name))) |
0 commit comments