@@ -29,6 +29,10 @@ def get_swiftpm_options(args):
29
29
if args .verbose :
30
30
swiftpm_args += ['--verbose' ]
31
31
32
+ if args .sanitize :
33
+ for san in args .sanitize :
34
+ swiftpm_args += ['--sanitize=%s' % san ]
35
+
32
36
if platform .system () != 'Darwin' :
33
37
swiftpm_args += [
34
38
# Dispatch headers
@@ -41,6 +45,36 @@ def get_swiftpm_options(args):
41
45
42
46
return swiftpm_args
43
47
48
+
49
+ def handle_invocation (swift_exec , args ):
50
+ swiftpm_args = get_swiftpm_options (args )
51
+
52
+ env = os .environ
53
+ # Set the toolchain used in tests at runtime
54
+ env ['INDEXSTOREDB_TOOLCHAIN_PATH' ] = args .toolchain
55
+
56
+ if args .ninja_bin :
57
+ env ['NINJA_BIN' ] = args .ninja_bin
58
+
59
+ if args .sanitize and 'address' in args .sanitize :
60
+ # Workaround reports in Foundation: https://bugs.swift.org/browse/SR-12551
61
+ env ['ASAN_OPTIONS' ] = 'detect_leaks=false'
62
+ if args .sanitize and 'undefined' in args .sanitize :
63
+ supp = os .path .join (args .package_path , 'Utilities' , 'ubsan_supressions.supp' )
64
+ env ['UBSAN_OPTIONS' ] = 'halt_on_error=true,suppressions=%s' % supp
65
+
66
+ if args .action == 'build' :
67
+ swiftpm ('build' , swift_exec , swiftpm_args , env )
68
+ elif args .action == 'test' :
69
+ bin_path = swiftpm_bin_path (swift_exec , swiftpm_args , env )
70
+ tests = os .path .join (bin_path , 'isdb-tests' )
71
+ print ('Cleaning ' + tests )
72
+ shutil .rmtree (tests , ignore_errors = True )
73
+ swiftpm ('test' , swift_exec , swiftpm_args + ['--parallel' ], env )
74
+ else :
75
+ assert False , 'unknown action \' {}\' ' .format (args .action )
76
+
77
+
44
78
def main ():
45
79
parser = argparse .ArgumentParser (description = 'Build along with the Swift build-script.' )
46
80
def add_common_args (parser ):
@@ -49,6 +83,8 @@ def add_common_args(parser):
49
83
parser .add_argument ('--ninja-bin' , metavar = 'PATH' , help = 'ninja binary to use for testing' )
50
84
parser .add_argument ('--build-path' , metavar = 'PATH' , default = '.build' , help = 'build in the given path' )
51
85
parser .add_argument ('--configuration' , '-c' , default = 'debug' , help = 'build using configuration (release|debug)' )
86
+ parser .add_argument ('--sanitize' , action = 'append' , help = 'build using the given sanitizer(s) (address|thread|undefined)' )
87
+ parser .add_argument ('--sanitize-all' , action = 'store_true' , help = 'build using every available sanitizer in sub-directories of build path' )
52
88
parser .add_argument ('--verbose' , '-v' , action = 'store_true' , help = 'enable verbose output' )
53
89
54
90
subparsers = parser .add_subparsers (title = 'subcommands' , dest = 'action' , metavar = 'action' )
@@ -60,6 +96,9 @@ def add_common_args(parser):
60
96
61
97
args = parser .parse_args (sys .argv [1 :])
62
98
99
+ if args .sanitize and args .sanitize_all :
100
+ assert False , 'cannot combine --sanitize with --sanitize-all'
101
+
63
102
# Canonicalize paths
64
103
args .package_path = os .path .abspath (args .package_path )
65
104
args .build_path = os .path .abspath (args .build_path )
@@ -70,25 +109,28 @@ def add_common_args(parser):
70
109
else :
71
110
swift_exec = 'swift'
72
111
73
- swiftpm_args = get_swiftpm_options ( args )
112
+ handle_invocation ( swift_exec , args )
74
113
75
- env = os .environ
76
- # Set the toolchain used in tests at runtime
77
- env ['INDEXSTOREDB_TOOLCHAIN_PATH' ] = args .toolchain
114
+ if args .sanitize_all :
115
+ base = args .build_path
78
116
79
- if args .ninja_bin :
80
- env ['NINJA_BIN' ] = args .ninja_bin
117
+ print ('=== %s indexstore-db with asan ===' % args .action )
118
+ args .sanitize = ['address' ]
119
+ args .build_path = os .path .join (base , 'test-asan' )
120
+ handle_invocation (swift_exec , args )
121
+
122
+ print ('=== %s indexstore-db with tsan ===' % args .action )
123
+ args .sanitize = ['thread' ]
124
+ args .build_path = os .path .join (base , 'test-tsan' )
125
+ handle_invocation (swift_exec , args )
126
+
127
+ # Linux ubsan disabled: https://bugs.swift.org/browse/SR-12550
128
+ if platform .system () != 'Linux' :
129
+ print ('=== %s indexstore-db with ubsan ===' % args .action )
130
+ args .sanitize = ['undefined' ]
131
+ args .build_path = os .path .join (base , 'test-ubsan' )
132
+ handle_invocation (swift_exec , args )
81
133
82
- if args .action == 'build' :
83
- swiftpm ('build' , swift_exec , swiftpm_args , env )
84
- elif args .action == 'test' :
85
- bin_path = swiftpm_bin_path (swift_exec , swiftpm_args , env )
86
- tests = os .path .join (bin_path , 'isdb-tests' )
87
- print ('Cleaning ' + tests )
88
- shutil .rmtree (tests , ignore_errors = True )
89
- swiftpm ('test' , swift_exec , swiftpm_args + ['--parallel' ], env )
90
- else :
91
- assert False , 'unknown action \' {}\' ' .format (args .action )
92
134
93
135
if __name__ == '__main__' :
94
136
main ()
0 commit comments