From dc8b440fe97adeb849231acbf8aa246920140977 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Thu, 9 Aug 2018 18:04:37 -0700 Subject: [PATCH] [infra] Follow-up for the incorrect extraction of WORKDIR from a Dockerfile (#1699). (#1702) * [infra] Follow-up for the incorrect extraction of WORKDIR from a Dockerfile (#1699). * Return an error if local checkout used with "WORKDIR /src". --- infra/helper.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/infra/helper.py b/infra/helper.py index 69555fc20..8ed61c405 100755 --- a/infra/helper.py +++ b/infra/helper.py @@ -297,7 +297,7 @@ def _env_to_docker_args(env_list): def _workdir_from_dockerfile(project_name): """Parse WORKDIR from the Dockerfile for the given project.""" - WORKDIR_REGEX = re.compile(r'\s*WORKDIR\s*(\$SRC/[^\s]+)') + WORKDIR_REGEX = re.compile(r'\s*WORKDIR\s*([^\s]+)') dockerfile_path = _get_dockerfile_path(project_name) with open(dockerfile_path) as f: @@ -312,7 +312,7 @@ def _workdir_from_dockerfile(project_name): if not os.path.isabs(workdir): workdir = os.path.join('/src', workdir) - return workdir + return os.path.normpath(workdir) return os.path.join('/src', project_name) @@ -433,10 +433,14 @@ def build_fuzzers(args): ['docker', 'run', '--rm', '-i', '--cap-add', 'SYS_PTRACE'] + _env_to_docker_args(env)) if args.source_path: + workdir = _workdir_from_dockerfile(args.project_name) + if workdir == '/src': + print('Cannot use local checkout with "WORKDIR /src".', file=sys.stderr) + return 1 + command += [ '-v', - '%s:%s' % (_get_absolute_path(args.source_path), - _workdir_from_dockerfile(args.project_name)), + '%s:%s' % (_get_absolute_path(args.source_path), workdir), ] command += [ '-v', '%s:/out' % project_out_dir, @@ -449,7 +453,7 @@ def build_fuzzers(args): try: subprocess.check_call(command) except subprocess.CalledProcessError: - print('fuzzers build failed.', file=sys.stderr) + print('Fuzzers build failed.', file=sys.stderr) return 1 # Patch MSan builds to use instrumented shared libraries.