Skip to content

Commit 10bafd6

Browse files
committed
[build-script] Add support for passing into swift -DSWIFT_RUNTIME_USE_SANITIZERS flag.
1 parent c28ce15 commit 10bafd6

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

utils/build-script

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,8 +1867,11 @@ details of the setups of other systems or automated environments.""")
18671867
action=arguments.action.optional_bool)
18681868
parser.add_argument(
18691869
"--enable-tsan",
1870-
help="enable Thread Sanitizer",
1870+
help="enable Thread Sanitizer for swift tools",
18711871
action=arguments.action.optional_bool)
1872+
parser.add_argument(
1873+
"--enable-tsan-runtime",
1874+
help="enable Thread Sanitizer on the swift runtime")
18721875
parser.add_argument(
18731876
"--clang-compiler-version",
18741877
help="string that indicates a compiler version for Clang",

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,19 @@
1414

1515

1616
class Swift(product.Product):
17-
pass
17+
18+
def __init__(self, args, toolchain, source_dir, build_dir):
19+
product.Product.__init__(self, args, toolchain, source_dir,
20+
build_dir)
21+
# Add any runtime sanitizer arguments.
22+
self.cmake_options.extend(self._compute_runtime_use_sanitizer())
23+
24+
25+
def _compute_runtime_use_sanitizer(self):
26+
sanitizer_list = []
27+
if self.args.enable_tsan_runtime:
28+
sanitizer_list += ['Thread']
29+
if len(sanitizer_list) == 0:
30+
return []
31+
return ["-DSWIFT_RUNTIME_USE_SANITIZERS=%s" % \
32+
";".join(sanitizer_list)]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# tests/products/test_swift.py ----------------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
# ----------------------------------------------------------------------------
11+
12+
import argparse
13+
import os
14+
import platform
15+
import shutil
16+
import sys
17+
import tempfile
18+
import unittest
19+
try:
20+
# py2
21+
from StringIO import StringIO
22+
except ImportError:
23+
# py3
24+
from io import StringIO
25+
26+
from swift_build_support import shell
27+
from swift_build_support import xcrun
28+
from swift_build_support.products import Swift
29+
from swift_build_support.toolchain import host_toolchain
30+
from swift_build_support.workspace import Workspace
31+
32+
33+
class SwiftTestCase(unittest.TestCase):
34+
35+
def setUp(self):
36+
# Setup workspace
37+
tmpdir1 = os.path.realpath(tempfile.mkdtemp())
38+
tmpdir2 = os.path.realpath(tempfile.mkdtemp())
39+
os.makedirs(os.path.join(tmpdir1, 'swift'))
40+
41+
self.workspace = Workspace(source_root=tmpdir1,
42+
build_root=tmpdir2)
43+
44+
# Setup toolchain
45+
self.toolchain = host_toolchain()
46+
self.toolchain.cc = '/path/to/cc'
47+
self.toolchain.cxx = '/path/to/cxx'
48+
49+
# Setup args
50+
self.args = argparse.Namespace(
51+
enable_tsan_runtime=False,
52+
darwin_deployment_version_osx="10.9")
53+
54+
# Setup shell
55+
shell.dry_run = True
56+
self._orig_stdout = sys.stdout
57+
self._orig_stderr = sys.stderr
58+
self.stdout = StringIO()
59+
self.stderr = StringIO()
60+
sys.stdout = self.stdout
61+
sys.stderr = self.stderr
62+
63+
def tearDown(self):
64+
shutil.rmtree(self.workspace.build_root)
65+
shutil.rmtree(self.workspace.source_root)
66+
sys.stdout = self._orig_stdout
67+
sys.stderr = self._orig_stderr
68+
shell.dry_run = False
69+
self.workspace = None
70+
self.toolchain = None
71+
self.args = None
72+
73+
def test_swift_runtime_tsan(self):
74+
self.args.enable_tsan_runtime = True
75+
swift = Swift(
76+
args=self.args,
77+
toolchain=self.toolchain,
78+
source_dir='/path/to/src',
79+
build_dir='/path/to/build')
80+
self.assertEqual(swift.cmake_options, ['-DSWIFT_RUNTIME_USE_SANITIZERS=Thread'])

0 commit comments

Comments
 (0)