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
# Not incremental..
70
89
run ("{0} -c -O -emit-object {1}/XCTest/XCTest.swift -module-name XCTest -parse-as-library -emit-module "
71
90
"-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 ))
73
92
74
93
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 ))
75
94
@@ -95,7 +114,29 @@ def main():
95
114
cmd = ['cp' , os .path .join (build_dir , install_mod_doc ), os .path .join (module_path , install_mod_doc )]
96
115
subprocess .check_call (cmd )
97
116
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
+
99
140
note ('Done.' )
100
141
101
142
if __name__ == '__main__' :
0 commit comments