@@ -30,7 +30,8 @@ def get_swiftpm_options(args):
30
30
swiftpm_args += ['--verbose' ]
31
31
32
32
if args .sanitize :
33
- swiftpm_args += ['--sanitize=%s' % args .sanitize ]
33
+ for san in args .sanitize :
34
+ swiftpm_args += ['--sanitize=%s' % san ]
34
35
35
36
if platform .system () != 'Darwin' :
36
37
swiftpm_args += [
@@ -44,6 +45,36 @@ def get_swiftpm_options(args):
44
45
45
46
return swiftpm_args
46
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
+
47
78
def main ():
48
79
parser = argparse .ArgumentParser (description = 'Build along with the Swift build-script.' )
49
80
def add_common_args (parser ):
@@ -52,7 +83,8 @@ def add_common_args(parser):
52
83
parser .add_argument ('--ninja-bin' , metavar = 'PATH' , help = 'ninja binary to use for testing' )
53
84
parser .add_argument ('--build-path' , metavar = 'PATH' , default = '.build' , help = 'build in the given path' )
54
85
parser .add_argument ('--configuration' , '-c' , default = 'debug' , help = 'build using configuration (release|debug)' )
55
- parser .add_argument ('--sanitize' , help = 'build using the given sanitizier (address|thread|undefined)' )
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' )
56
88
parser .add_argument ('--verbose' , '-v' , action = 'store_true' , help = 'enable verbose output' )
57
89
58
90
subparsers = parser .add_subparsers (title = 'subcommands' , dest = 'action' , metavar = 'action' )
@@ -64,6 +96,9 @@ def add_common_args(parser):
64
96
65
97
args = parser .parse_args (sys .argv [1 :])
66
98
99
+ if args .sanitize and args .sanitize_all :
100
+ assert False , 'cannot combine --sanitize with --sanitize-all'
101
+
67
102
# Canonicalize paths
68
103
args .package_path = os .path .abspath (args .package_path )
69
104
args .build_path = os .path .abspath (args .build_path )
@@ -74,32 +109,28 @@ def add_common_args(parser):
74
109
else :
75
110
swift_exec = 'swift'
76
111
77
- swiftpm_args = get_swiftpm_options ( args )
112
+ handle_invocation ( swift_exec , args )
78
113
79
- env = os .environ
80
- # Set the toolchain used in tests at runtime
81
- env ['INDEXSTOREDB_TOOLCHAIN_PATH' ] = args .toolchain
114
+ if args .sanitize_all :
115
+ base = args .build_path
82
116
83
- if args .ninja_bin :
84
- 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 )
85
121
86
- if args .sanitize == 'address' :
87
- # Workaround reports in Foundation.
88
- env ['ASAN_OPTIONS' ] = 'detect_leaks=false'
89
- if args .sanitize == 'undefined' :
90
- supp = os .path .join (args .package_path , 'Utilities' , 'ubsan_supressions.supp' )
91
- env ['UBSAN_OPTIONS' ] = 'halt_on_error=true,suppressions=%s' % supp
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 )
92
133
93
- if args .action == 'build' :
94
- swiftpm ('build' , swift_exec , swiftpm_args , env )
95
- elif args .action == 'test' :
96
- bin_path = swiftpm_bin_path (swift_exec , swiftpm_args , env )
97
- tests = os .path .join (bin_path , 'isdb-tests' )
98
- print ('Cleaning ' + tests )
99
- shutil .rmtree (tests , ignore_errors = True )
100
- swiftpm ('test' , swift_exec , swiftpm_args + ['--parallel' ], env )
101
- else :
102
- assert False , 'unknown action \' {}\' ' .format (args .action )
103
134
104
135
if __name__ == '__main__' :
105
136
main ()
0 commit comments