From d8b0c77eaef631f79bc0dad295e9926d55ef33ff Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Mon, 24 May 2021 14:22:01 -0700 Subject: [CIFuzz] Support non-github action CI for external projects (#5824) This is incomplete for a few reasons. 1. It probably can't diff properly. 2. It assumes the project source should be put in /src/$PROJECT_NAME. --- infra/cifuzz/continuous_integration.py | 60 +++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) (limited to 'infra/cifuzz/continuous_integration.py') diff --git a/infra/cifuzz/continuous_integration.py b/infra/cifuzz/continuous_integration.py index b2e8af28..c90aca0b 100644 --- a/infra/cifuzz/continuous_integration.py +++ b/infra/cifuzz/continuous_integration.py @@ -69,6 +69,11 @@ class BaseCi: def get_ci(config): """Determines what kind of CI is being used and returns the object representing that system.""" + + if config.platform == config.Platform.EXTERNAL_GENERIC_CI: + # Non-OSS-Fuzz projects must bring their own source and their own build + # integration (which is relative to that source). + return ExternalGeneric(config) if config.platform == config.Platform.EXTERNAL_GITHUB: # Non-OSS-Fuzz projects must bring their own source and their own build # integration (which is relative to that source). @@ -132,7 +137,9 @@ class InternalGithub(GithubCiMixin, BaseCi): if not inferred_url or not image_repo_path: logging.error('Could not detect repo from project %s.', self.config.project_name) - return BuildPreparationResult(False, None, None) + return BuildPreparationResult(success=False, + image_repo_path=None, + repo_manager=None) git_workspace = os.path.join(self.config.workspace, 'storage') os.makedirs(git_workspace, exist_ok=True) @@ -147,7 +154,9 @@ class InternalGithub(GithubCiMixin, BaseCi): checkout_specified_commit(manager, self.config.pr_ref, self.config.commit_sha) - return BuildPreparationResult(True, image_repo_path, manager) + return BuildPreparationResult(success=True, + image_repo_path=image_repo_path, + repo_manager=manager) class InternalGeneric(BaseCi): @@ -167,10 +176,14 @@ class InternalGeneric(BaseCi): if not image_repo_path: logging.error('Could not detect repo from project %s.', self.config.project_name) - return BuildPreparationResult(False, None, None) + return BuildPreparationResult(success=False, + image_repo_path=None, + repo_manager=None) manager = repo_manager.RepoManager(self.config.project_src_path) - return BuildPreparationResult(True, image_repo_path, manager) + return BuildPreparationResult(success=True, + image_repo_path=image_repo_path, + repo_manager=manager) def get_diff_base(self): return 'origin...' @@ -191,6 +204,31 @@ def build_external_project_docker_image(project_name, project_src, return helper.docker_build(command) +class ExternalGeneric(BaseCi): + """CI implementation for generic CI for external (non-OSS-Fuzz) projects.""" + + def get_diff_base(self): + return 'origin...' + + def prepare_for_fuzzer_build(self): + logging.info('ExternalGeneric: preparing for fuzzer build.') + manager = repo_manager.RepoManager(self.config.project_src_path) + build_integration_abs_path = os.path.join( + manager.repo_dir, self.config.build_integration_path) + if not build_external_project_docker_image( + self.config.project_name, manager.repo_dir, build_integration_abs_path): + logging.error('Failed to build external project: %s.', + self.config.project_name) + return BuildPreparationResult(success=False, + image_repo_path=None, + repo_manager=None) + + image_repo_path = os.path.join('/src', self.config.project_repo_name) + return BuildPreparationResult(success=True, + image_repo_path=image_repo_path, + repo_manager=manager) + + class ExternalGithub(GithubCiMixin, BaseCi): """Class representing CI for a non-OSS-Fuzz project on Github Actions.""" @@ -212,12 +250,16 @@ class ExternalGithub(GithubCiMixin, BaseCi): checkout_specified_commit(manager, self.config.pr_ref, self.config.commit_sha) - build_integration_path = os.path.join(manager.repo_dir, - self.config.build_integration_path) + build_integration_abs_path = os.path.join( + manager.repo_dir, self.config.build_integration_path) if not build_external_project_docker_image( - self.config.project_name, manager.repo_dir, build_integration_path): + self.config.project_name, manager.repo_dir, build_integration_abs_path): logging.error('Failed to build external project.') - return BuildPreparationResult(False, None, None) + return BuildPreparationResult(success=False, + image_repo_path=None, + repo_manager=None) image_repo_path = os.path.join('/src', self.config.project_repo_name) - return BuildPreparationResult(True, image_repo_path, manager) + return BuildPreparationResult(success=True, + image_repo_path=image_repo_path, + repo_manager=manager) -- cgit v1.2.3