1# Copyright 2020 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Builds a specific OSS-Fuzz project's fuzzers for CI tools.""" 15import logging 16import sys 17 18import build_fuzzers 19import config_utils 20 21# pylint: disable=c-extension-no-member 22# pylint gets confused because of the relative import of cifuzz. 23 24logging.basicConfig( 25 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 26 level=logging.DEBUG) 27 28 29def build_fuzzers_entrypoint(): 30 """Builds OSS-Fuzz project's fuzzers for CI tools.""" 31 config = config_utils.BuildFuzzersConfig() 32 33 if config.dry_run: 34 # Sets the default return code on error to success. 35 returncode = 0 36 else: 37 # The default return code when an error occurs. 38 returncode = 1 39 40 if not build_fuzzers.build_fuzzers(config): 41 logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).', 42 config.commit_sha, config.pr_ref) 43 return returncode 44 45 return 0 46 47 48def main(): 49 """Builds OSS-Fuzz project's fuzzers for CI tools. 50 51 Note: The resulting fuzz target binaries of this build are placed in 52 the directory: ${GITHUB_WORKSPACE}/out 53 54 Required environment variables: 55 OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project. 56 GITHUB_REPOSITORY: The name of the Github repo that called this script. 57 GITHUB_SHA: The commit SHA that triggered this script. 58 GITHUB_EVENT_NAME: The name of the hook event that triggered this script. 59 GITHUB_EVENT_PATH: 60 The path to the file containing the POST payload of the webhook: 61 https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners 62 GITHUB_WORKSPACE: The shared volume directory where input artifacts are. 63 DRY_RUN: If true, no failures will surface. 64 SANITIZER: The sanitizer to use when running fuzzers. 65 66 Returns: 67 0 on success or nonzero on failure. 68 """ 69 return build_fuzzers_entrypoint() 70 71 72if __name__ == '__main__': 73 sys.exit(main()) 74