aboutsummaryrefslogtreecommitdiff
path: root/infra/helper.py
diff options
context:
space:
mode:
authorOliver Chang <oliverchang@users.noreply.github.com>2020-06-10 17:12:28 +1000
committerGitHub <noreply@github.com>2020-06-10 17:12:28 +1000
commit4a51ecb61f80d955685615001846c545b2229368 (patch)
tree8127cdf8eae706fd97a6d1e487f80f06ea6c435e /infra/helper.py
parent778d61c291ab5829640c5689b4c1a92ac8abd2db (diff)
downloadoss-fuzz-4a51ecb61f80d955685615001846c545b2229368.tar.gz
build_specified_commit: Handle build.sh which are part of upstream repo. (#3932)
This is a best effort attempt to parse the relevant copy command from the Dockerfile. Also add a main function to build_specified_commit to make it easier to test.
Diffstat (limited to 'infra/helper.py')
-rwxr-xr-xinfra/helper.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/infra/helper.py b/infra/helper.py
index 668f31d0b..22c81984d 100755
--- a/infra/helper.py
+++ b/infra/helper.py
@@ -363,13 +363,8 @@ def _env_to_docker_args(env_list):
WORKDIR_REGEX = re.compile(r'\s*WORKDIR\s*([^\s]+)')
-def _workdir_from_dockerfile(project_name):
- """Parse WORKDIR from the Dockerfile for the given project."""
- dockerfile_path = get_dockerfile_path(project_name)
-
- with open(dockerfile_path) as file_handle:
- lines = file_handle.readlines()
-
+def workdir_from_lines(lines, default='/src'):
+ """Get the WORKDIR from the given lines."""
for line in reversed(lines): # reversed to get last WORKDIR.
match = re.match(WORKDIR_REGEX, line)
if match:
@@ -381,7 +376,17 @@ def _workdir_from_dockerfile(project_name):
return os.path.normpath(workdir)
- return os.path.join('/src', project_name)
+ return default
+
+
+def _workdir_from_dockerfile(project_name):
+ """Parse WORKDIR from the Dockerfile for the given project."""
+ dockerfile_path = get_dockerfile_path(project_name)
+
+ with open(dockerfile_path) as file_handle:
+ lines = file_handle.readlines()
+
+ return workdir_from_lines(lines, default=os.path.join('/src', project_name))
def docker_run(run_args, print_output=True):