|
12 | 12 | # Here is a nice way to invoke this script if you are building locally, and Swift is installed at /, and you want to install XCTest back there
|
13 | 13 | # sudo ./build_script.py --swiftc="/usr/bin/swiftc" --build-dir="/tmp/XCTest_build" --swift-build-dir="/usr" --library-install-path="/usr/lib/swift/linux" --module-install-path="/usr/lib/swift/linux/x86_64"
|
14 | 14 |
|
15 |
| -import os, subprocess, argparse |
| 15 | +import argparse |
| 16 | +import glob |
| 17 | +import os |
| 18 | +import subprocess |
| 19 | + |
| 20 | +SOURCE_DIR = os.path.dirname(os.path.abspath(__file__)) |
16 | 21 |
|
17 | 22 | def note(msg):
|
18 | 23 | print("xctest-build: "+msg)
|
@@ -57,19 +62,33 @@ def main():
|
57 | 62 | action="store",
|
58 | 63 | dest="lib_path",
|
59 | 64 | default=None)
|
| 65 | + parser.add_argument("--test", |
| 66 | + help="whether to run tests after building", |
| 67 | + action="store_true", |
| 68 | + dest="test", |
| 69 | + default=False) |
| 70 | + parser.add_argument("--native-llvm-tools-path", |
| 71 | + help="location of built LLVM binaries, specifically FileCheck", |
| 72 | + metavar="PATH", |
| 73 | + action="store", |
| 74 | + dest="native_llvm_tools_path", |
| 75 | + default=None) |
60 | 76 | args = parser.parse_args()
|
61 | 77 |
|
62 | 78 | swiftc = os.path.abspath(args.swiftc)
|
63 | 79 | build_dir = os.path.abspath(args.build_dir)
|
64 | 80 | swift_build_dir = os.path.abspath(args.swift_build_dir)
|
65 |
| - |
| 81 | + if args.test: |
| 82 | + assert args.native_llvm_tools_path is not None, \ |
| 83 | + '--native-llvm-tools-path must be specified when using --test' |
| 84 | + |
66 | 85 | if not os.path.exists(build_dir):
|
67 | 86 | run("mkdir -p {}".format(build_dir))
|
68 | 87 |
|
69 | 88 | sourceFiles = ["XCTest.swift", "XCTestCaseProvider.swift", "XCTestCase.swift", "XCTAssert.swift"]
|
70 | 89 | sourcePaths = []
|
71 | 90 | for file in sourceFiles:
|
72 |
| - sourcePaths.append("{0}/XCTest/{1}".format(os.path.dirname(os.path.abspath(__file__)), file)) |
| 91 | + sourcePaths.append("{0}/XCTest/{1}".format(SOURCE_DIR, file)) |
73 | 92 |
|
74 | 93 | # Not incremental..
|
75 | 94 | run("{0} -c -O -emit-object {1} -module-name XCTest -parse-as-library -emit-module "
|
@@ -100,7 +119,29 @@ def main():
|
100 | 119 | cmd = ['cp', os.path.join(build_dir, install_mod_doc), os.path.join(module_path, install_mod_doc)]
|
101 | 120 | subprocess.check_call(cmd)
|
102 | 121 |
|
103 |
| - |
| 122 | + if args.test: |
| 123 | + # 1. We first compile every test fixture in Tests/Fixtures/Sources/. |
| 124 | + # The compiled executables are stored in Tests/Fixtures/Products/. |
| 125 | + tests_dir = os.path.join(SOURCE_DIR, 'Tests') |
| 126 | + fixtures_dir = os.path.join(tests_dir, 'Fixtures') |
| 127 | + fixture_products_dir = os.path.join(fixtures_dir, 'Products') |
| 128 | + fixture_sources_glob_dir = os.path.join(fixtures_dir, 'Sources', '*') |
| 129 | + for fixture_source_dir in glob.glob(fixture_sources_glob_dir): |
| 130 | + # Loop over every main.swift file in Tests/Fixtures/Sources/ |
| 131 | + # and compile it using swiftc. The executables are output to |
| 132 | + # Tests/Fixtures/Products/. |
| 133 | + fixture_source = os.path.join(fixture_source_dir, 'main.swift') |
| 134 | + dest = os.path.join( |
| 135 | + fixture_products_dir, |
| 136 | + os.path.basename(fixture_source_dir)) |
| 137 | + run("{0} {1} -o {2}".format(swiftc, fixture_source, dest)) |
| 138 | + |
| 139 | + # 2. lit is used across all platforms. It runs each |
| 140 | + # executable in Tests/Fixtures/Products/, comparing their |
| 141 | + # output to the annotated main.swift files. |
| 142 | + run("lit {0} -v --param native_llvm_tools_path={1}".format( |
| 143 | + tests_dir, args.native_llvm_tools_path)) |
| 144 | + |
104 | 145 | note('Done.')
|
105 | 146 |
|
106 | 147 | if __name__ == '__main__':
|
|
0 commit comments