aboutsummaryrefslogtreecommitdiff
path: root/infra/build_specified_commit.py
diff options
context:
space:
mode:
authorOliver Chang <oliverchang@users.noreply.github.com>2020-04-23 10:49:22 +1000
committerGitHub <noreply@github.com>2020-04-23 10:49:22 +1000
commit22d254a44537d803168825f7f64dbeacb5f8f7a5 (patch)
treef54ef25576275c39cae7db94d0fc2cbc8eb10cf6 /infra/build_specified_commit.py
parent0c557971b2f047e91732a5a4384c2fd5d3042d22 (diff)
downloadoss-fuzz-22d254a44537d803168825f7f64dbeacb5f8f7a5.tar.gz
build_specified_commit: Make submodules work. (#3691)
Submodules weren't working correctly due to absolute paths being set. We add a step to turn those paths to relative after copying them to host.
Diffstat (limited to 'infra/build_specified_commit.py')
-rw-r--r--infra/build_specified_commit.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/infra/build_specified_commit.py b/infra/build_specified_commit.py
index 23b47eaad..30f4b43ca 100644
--- a/infra/build_specified_commit.py
+++ b/infra/build_specified_commit.py
@@ -30,6 +30,38 @@ import utils
BuildData = collections.namedtuple(
'BuildData', ['project_name', 'engine', 'sanitizer', 'architecture'])
+_GIT_DIR_MARKER = 'gitdir: '
+
+
+def _make_gitdirs_relative(src_dir):
+ """Make gitdirs relative."""
+ for root_dir, _, files in os.walk(src_dir):
+ for filename in files:
+ if filename != '.git':
+ continue
+
+ file_path = os.path.join(root_dir, filename)
+ with open(file_path) as handle:
+ lines = handle.readlines()
+
+ new_lines = []
+ for line in lines:
+ if line.startswith(_GIT_DIR_MARKER):
+ absolute_path = line[len(_GIT_DIR_MARKER):].strip()
+ current_dir = os.path.dirname(file_path)
+ # Rebase to /src rather than the host src dir.
+ base_dir = current_dir.replace(src_dir, '/src')
+ relative_path = os.path.relpath(absolute_path, base_dir)
+ logging.info('Replacing absolute submodule gitdir from %s to %s',
+ absolute_path, relative_path)
+
+ line = _GIT_DIR_MARKER + relative_path
+
+ new_lines.append(line)
+
+ with open(file_path, 'w') as handle:
+ handle.write('\n'.join(new_lines))
+
def copy_src_from_docker(project_name, host_dir):
"""Copy /src from docker to the host."""
@@ -46,7 +78,13 @@ def copy_src_from_docker(project_name, host_dir):
'/out',
]
helper.docker_run(docker_args)
- return os.path.join(host_dir, 'src')
+
+ # Submodules can have gitdir entries which point to absolute paths. Make them
+ # relative, as otherwise we can't do operations on the checkout on the host.
+ src_dir = os.path.join(host_dir, 'src')
+ _make_gitdirs_relative(src_dir)
+
+ return src_dir
def build_fuzzers_from_commit(commit, build_repo_manager, host_src_path,