Skip to content

Commit ffa6dfb

Browse files
committed
[build_script] Add --test option to test on Linux
By passing `--test` to the build script, the lit regression tests are run. This allows the test suite to be run on Linux. Require the path to `FileCheck` be passed along as well.
1 parent 50ac705 commit ffa6dfb

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

build_script.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
# 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
1313
# 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"
1414

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__))
1621

1722
def note(msg):
1823
print("xctest-build: "+msg)
@@ -57,19 +62,33 @@ def main():
5762
action="store",
5863
dest="lib_path",
5964
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)
6076
args = parser.parse_args()
6177

6278
swiftc = os.path.abspath(args.swiftc)
6379
build_dir = os.path.abspath(args.build_dir)
6480
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+
6685
if not os.path.exists(build_dir):
6786
run("mkdir -p {}".format(build_dir))
6887

6988
# Not incremental..
7089
run("{0} -c -O -emit-object {1}/XCTest/XCTest.swift -module-name XCTest -parse-as-library -emit-module "
7190
"-emit-module-path {2}/XCTest.swiftmodule -o {2}/XCTest.o -force-single-frontend-invocation "
72-
"-module-link-name XCTest".format(swiftc, os.path.dirname(os.path.abspath(__file__)), build_dir))
91+
"-module-link-name XCTest".format(swiftc, SOURCE_DIR, build_dir))
7392

7493
run("clang {0}/XCTest.o -shared -o {0}/libXCTest.so -Wl,--no-undefined -Wl,-soname,libXCTest.so -L{1}/lib/swift/linux/ -lswiftGlibc -lswiftCore -lm".format(build_dir, swift_build_dir))
7594

@@ -95,7 +114,29 @@ def main():
95114
cmd = ['cp', os.path.join(build_dir, install_mod_doc), os.path.join(module_path, install_mod_doc)]
96115
subprocess.check_call(cmd)
97116

98-
117+
if args.test:
118+
# 1. We first compile every test fixture in Tests/Fixtures/Sources/.
119+
# The compiled executables are stored in Tests/Fixtures/Products/.
120+
tests_dir = os.path.join(SOURCE_DIR, 'Tests')
121+
fixtures_dir = os.path.join(tests_dir, 'Fixtures')
122+
fixture_products_dir = os.path.join(fixtures_dir, 'Products')
123+
fixture_sources_glob_dir = os.path.join(fixtures_dir, 'Sources', '*')
124+
for fixture_source_dir in glob.glob(fixture_sources_glob_dir):
125+
# Loop over every main.swift file in Tests/Fixtures/Sources/
126+
# and compile it using swiftc. The executables are output to
127+
# Tests/Fixtures/Products/.
128+
fixture_source = os.path.join(fixture_source_dir, 'main.swift')
129+
dest = os.path.join(
130+
fixture_products_dir,
131+
os.path.basename(fixture_source_dir))
132+
run("{0} {1} -o {2}".format(swiftc, fixture_source, dest))
133+
134+
# 2. lit is used across all platforms. It runs each
135+
# executable in Tests/Fixtures/Products/, comparing their
136+
# output to the annotated main.swift files.
137+
run("lit {0} -v --param native_llvm_tools_path={1}".format(
138+
tests_dir, args.native_llvm_tools_path))
139+
99140
note('Done.')
100141

101142
if __name__ == '__main__':

0 commit comments

Comments
 (0)