From b4240d3aa133b8eefd253498e3f2cc321e24ab84 Mon Sep 17 00:00:00 2001 From: Tom Allsop Date: Fri, 4 Nov 2022 10:40:10 +0000 Subject: Added ASAN & UBSAN build options and Dockerfile for sanitized builds * Added SanitizerBuild.Dockerfile for running sanitized builds. * Added dependencies for bandit into SanitizerBuild.Dockerfile. * Added --sanitizer option to setup.py. * Added .bandit.yaml. Change-Id: I4dd41bc52790a1b7f17ffca556362e37860ab572 --- setup.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index a62cd22..92b3fb4 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,12 @@ argparser = argparse.ArgumentParser() argparser.add_argument( "--tensorflow_src_dir", help="TensorFlow source directory path", required=False ) +argparser.add_argument( + "--sanitizer", + help="Build using a sanitizer (choose from asan or ubsan)", + choices=["asan", "ubsan"], + required=False +) args, unknown = argparser.parse_known_args() sys.argv = [sys.argv[0]] + unknown @@ -51,21 +57,30 @@ class BazelBuildExtension(setuptools.command.build_ext.build_ext): ext.tensorflow_version, ) - self.spawn( - [ - "bazel", - "build", - "-c", - "opt", - # FIXME Some of the Bazel targets dependencies we use have - # a 'friends' visibility, check if our Bazel target can be added - # to the 'friends' list. - "--check_visibility=false", - "--override_repository=org_tensorflow=" - + os.path.abspath(tensorflow_src_dir), - ext.bazel_target, + commands = [ + "bazel", + "build" + ] + + if args.sanitizer: + commands += [ + "--config={}".format(args.sanitizer) ] - ) + + commands += [ + # FIXME Some of the Bazel targets dependencies we use have + # a 'friends' visibility, check if our Bazel target can be added + # to the 'friends' list. + "-c", + "opt", + "--check_visibility=false", + "--override_repository=org_tensorflow={}".format( + os.path.abspath(tensorflow_src_dir) + ), + ext.bazel_target + ] + + self.spawn(commands) shared_lib_dest_path = self.get_ext_fullpath(ext.name) shared_lib_dest_dir = os.path.dirname(shared_lib_dest_path) -- cgit v1.2.1