Skip to content

[build-script] Add --sanitize option #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 58 additions & 16 deletions Utilities/build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def get_swiftpm_options(args):
if args.verbose:
swiftpm_args += ['--verbose']

if args.sanitize:
for san in args.sanitize:
swiftpm_args += ['--sanitize=%s' % san]

if platform.system() != 'Darwin':
swiftpm_args += [
# Dispatch headers
Expand All @@ -41,6 +45,36 @@ def get_swiftpm_options(args):

return swiftpm_args


def handle_invocation(swift_exec, args):
swiftpm_args = get_swiftpm_options(args)

env = os.environ
# Set the toolchain used in tests at runtime
env['INDEXSTOREDB_TOOLCHAIN_PATH'] = args.toolchain

if args.ninja_bin:
env['NINJA_BIN'] = args.ninja_bin

if args.sanitize and 'address' in args.sanitize:
# Workaround reports in Foundation: https://bugs.swift.org/browse/SR-12551
env['ASAN_OPTIONS'] = 'detect_leaks=false'
if args.sanitize and 'undefined' in args.sanitize:
supp = os.path.join(args.package_path, 'Utilities', 'ubsan_supressions.supp')
env['UBSAN_OPTIONS'] = 'halt_on_error=true,suppressions=%s' % supp

if args.action == 'build':
swiftpm('build', swift_exec, swiftpm_args, env)
elif args.action == 'test':
bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, env)
tests = os.path.join(bin_path, 'isdb-tests')
print('Cleaning ' + tests)
shutil.rmtree(tests, ignore_errors=True)
swiftpm('test', swift_exec, swiftpm_args + ['--parallel'], env)
else:
assert False, 'unknown action \'{}\''.format(args.action)


def main():
parser = argparse.ArgumentParser(description='Build along with the Swift build-script.')
def add_common_args(parser):
Expand All @@ -49,6 +83,8 @@ def add_common_args(parser):
parser.add_argument('--ninja-bin', metavar='PATH', help='ninja binary to use for testing')
parser.add_argument('--build-path', metavar='PATH', default='.build', help='build in the given path')
parser.add_argument('--configuration', '-c', default='debug', help='build using configuration (release|debug)')
parser.add_argument('--sanitize', action='append', help='build using the given sanitizer(s) (address|thread|undefined)')
parser.add_argument('--sanitize-all', action='store_true', help='build using every available sanitizer in sub-directories of build path')
parser.add_argument('--verbose', '-v', action='store_true', help='enable verbose output')

subparsers = parser.add_subparsers(title='subcommands', dest='action', metavar='action')
Expand All @@ -60,6 +96,9 @@ def add_common_args(parser):

args = parser.parse_args(sys.argv[1:])

if args.sanitize and args.sanitize_all:
assert False, 'cannot combine --sanitize with --sanitize-all'

# Canonicalize paths
args.package_path = os.path.abspath(args.package_path)
args.build_path = os.path.abspath(args.build_path)
Expand All @@ -70,25 +109,28 @@ def add_common_args(parser):
else:
swift_exec = 'swift'

swiftpm_args = get_swiftpm_options(args)
handle_invocation(swift_exec, args)

env = os.environ
# Set the toolchain used in tests at runtime
env['INDEXSTOREDB_TOOLCHAIN_PATH'] = args.toolchain
if args.sanitize_all:
base = args.build_path

if args.ninja_bin:
env['NINJA_BIN'] = args.ninja_bin
print('=== %s indexstore-db with asan ===' % args.action)
args.sanitize = ['address']
args.build_path = os.path.join(base, 'test-asan')
handle_invocation(swift_exec, args)

print('=== %s indexstore-db with tsan ===' % args.action)
args.sanitize = ['thread']
args.build_path = os.path.join(base, 'test-tsan')
handle_invocation(swift_exec, args)

# Linux ubsan disabled: https://bugs.swift.org/browse/SR-12550
if platform.system() != 'Linux':
print('=== %s indexstore-db with ubsan ===' % args.action)
args.sanitize = ['undefined']
args.build_path = os.path.join(base, 'test-ubsan')
handle_invocation(swift_exec, args)

if args.action == 'build':
swiftpm('build', swift_exec, swiftpm_args, env)
elif args.action == 'test':
bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, env)
tests = os.path.join(bin_path, 'isdb-tests')
print('Cleaning ' + tests)
shutil.rmtree(tests, ignore_errors=True)
swiftpm('test', swift_exec, swiftpm_args + ['--parallel'], env)
else:
assert False, 'unknown action \'{}\''.format(args.action)

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions Utilities/ubsan_supressions.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alignment:mdb.c