From 77d6eb33bc462d19b719b11a90cd69819d638d6d Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Tue, 21 Sep 2021 10:10:06 +1000 Subject: Helper fixes for external projects. (#6458) - Add ":v1" suffix to Dockerfile template. - Support relative paths for external project directories. --- infra/helper.py | 14 ++++++++------ infra/helper_test.py | 2 +- infra/templates.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/infra/helper.py b/infra/helper.py index ffadb17f..db9f76b6 100755 --- a/infra/helper.py +++ b/infra/helper.py @@ -86,8 +86,8 @@ class Project: build_integration_path=constants.DEFAULT_EXTERNAL_BUILD_INTEGRATION_PATH): self.is_external = is_external if self.is_external: - self.name = os.path.basename(os.path.abspath(project_name_or_path)) - self.path = project_name_or_path + self.path = os.path.abspath(project_name_or_path) + self.name = os.path.basename(self.path) self.build_integration_path = os.path.join(self.path, build_integration_path) else: @@ -137,15 +137,17 @@ class Project: def main(): # pylint: disable=too-many-branches,too-many-return-statements """Gets subcommand from program arguments and does it. Returns 0 on success 1 on error.""" - os.chdir(OSS_FUZZ_DIR) - if not os.path.exists(BUILD_DIR): - os.mkdir(BUILD_DIR) - logging.basicConfig(level=logging.INFO) parser = get_parser() args = parse_args(parser) + # Note: this has to happen after parse_args above as parse_args needs to know + # the original CWD for external projects. + os.chdir(OSS_FUZZ_DIR) + if not os.path.exists(BUILD_DIR): + os.mkdir(BUILD_DIR) + # We have different default values for `sanitizer` depending on the `engine`. # Some commands do not have `sanitizer` argument, so `hasattr` is necessary. if hasattr(args, 'sanitizer') and not args.sanitizer: diff --git a/infra/helper_test.py b/infra/helper_test.py index bb365037..951eba47 100644 --- a/infra/helper_test.py +++ b/infra/helper_test.py @@ -165,7 +165,7 @@ class ProjectTest(fake_filesystem_unittest.TestCase): def setUp(self): self.project_name = 'project' self.internal_project = helper.Project(self.project_name) - self.external_project_path = os.path.join('path', 'to', self.project_name) + self.external_project_path = os.path.join('/path', 'to', self.project_name) self.external_project = helper.Project(self.external_project_path, is_external=True) self.setUpPyfakefs() diff --git a/infra/templates.py b/infra/templates.py index 35a74825..9247285b 100755 --- a/infra/templates.py +++ b/infra/templates.py @@ -47,7 +47,7 @@ COPY build.sh $SRC/ """ EXTERNAL_DOCKER_TEMPLATE = """\ -FROM gcr.io/oss-fuzz-base/%(base_builder)s +FROM gcr.io/oss-fuzz-base/%(base_builder)s:v1 RUN apt-get update && apt-get install -y make autoconf automake libtool RUN COPY . $SRC/%(project_name)s WORKDIR %(project_name)s -- cgit v1.2.3