From 04395afc000489b7afbd30965cf484e38968afe6 Mon Sep 17 00:00:00 2001 From: Abhishek Arya Date: Mon, 30 Apr 2018 21:01:48 -0700 Subject: [PATCH] Clean artifacts in /out as part of build_fuzzers (#1384) (#1389) * Clean artifacts in /out as part of build_fuzzers. * Add prompt before build directory clean, also --no-clean option. --- infra/helper.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/infra/helper.py b/infra/helper.py index 4159ebeae..584eb3aed 100755 --- a/infra/helper.py +++ b/infra/helper.py @@ -71,6 +71,8 @@ def main(): build_fuzzers_parser.add_argument('project_name') build_fuzzers_parser.add_argument('source_path', help='path of local source', nargs='?') + build_fuzzers_parser.add_argument('--no-clean', action='store_true', + help='do not clean existing artifacts.') check_build_parser = subparsers.add_parser( 'check_build', help='Checks that fuzzers execute without errors.') @@ -298,11 +300,30 @@ def build_image(args): def build_fuzzers(args): """Build fuzzers.""" - project_name = args.project_name + no_clean = args.no_clean + if not no_clean: + y_or_n = raw_input( + 'WARNING: Remove existing build artifacts in /out ' + '(recommended if build config changed) ? (y/N): ') + no_clean = y_or_n.lower() != 'y' + project_name = args.project_name if not _build_image(args.project_name): return 1 + project_out_dir = os.path.join(BUILD_DIR, 'out', project_name) + if no_clean: + print('Keeping existing build artifacts as-is (if any).') + else: + print('Cleaning existing build artifacts.') + + # Clean old and possibly conflicting artifacts in project's out directory. + docker_run([ + '-v', '%s:/out' % project_out_dir, + '-t', 'gcr.io/oss-fuzz/%s' % project_name, + '/bin/bash', '-c', 'rm -rf /out/*' + ]) + env = [ 'FUZZING_ENGINE=' + args.engine, 'SANITIZER=' + args.sanitizer @@ -321,7 +342,7 @@ def build_fuzzers(args): '%s:/src/%s' % (_get_absolute_path(args.source_path), args.project_name) ] command += [ - '-v', '%s:/out' % os.path.join(BUILD_DIR, 'out', project_name), + '-v', '%s:/out' % project_out_dir, '-v', '%s:/work' % os.path.join(BUILD_DIR, 'work', project_name), '-t', 'gcr.io/oss-fuzz/%s' % project_name ]