Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse project language and use in infra/helper.py #3834

Merged
merged 2 commits into from
May 18, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions infra/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
'gs://{project_name}-backup.clusterfuzz-external.appspot.com/corpus/'
'libFuzzer/{fuzz_target}/')

PROJECT_LANGUAGE_REGEX = re.compile(r'\s*language\s*:\s*([^\s]+)')


def main(): # pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
"""Get subcommand from program arguments and do it."""
Expand Down Expand Up @@ -284,6 +286,20 @@ def _get_work_dir(project_name=''):
return os.path.join(BUILD_DIR, 'work', project_name)


def _get_project_language(project_name):
"""Returns project language."""
project_yaml_path = os.path.join(OSS_FUZZ_DIR, 'projects', project_name,
'project.yaml')
with open(project_yaml_path) as file_handle:
content = file_handle.read()
for line in content.splitlines():
match = PROJECT_LANGUAGE_REGEX.match(line)
if match:
return match.group(1)

raise Exception('FUZZING_LANGUAGE not found in project.yaml.')


def _add_architecture_args(parser, choices=('x86_64', 'i386')):
"""Add common architecture args."""
parser.add_argument('--architecture', default='x86_64', choices=choices)
Expand Down Expand Up @@ -449,7 +465,7 @@ def build_image(args):
return 1


def build_fuzzers_impl( # pylint: disable=too-many-arguments
def build_fuzzers_impl( # pylint: disable=too-many-arguments,too-many-locals
project_name,
clean,
engine,
Expand All @@ -465,6 +481,7 @@ def build_fuzzers_impl( # pylint: disable=too-many-arguments

project_out_dir = _get_output_dir(project_name)
project_work_dir = _get_work_dir(project_name)
project_language = _get_project_language(project_name)

if clean:
print('Cleaning existing build artifacts.')
Expand All @@ -486,7 +503,7 @@ def build_fuzzers_impl( # pylint: disable=too-many-arguments
print('Keeping existing build artifacts as-is (if any).')
env = [
'FUZZING_ENGINE=' + engine,
'FUZZING_LANGUAGE=c++', # TODO: Replace with actual language.
'FUZZING_LANGUAGE=' + project_language,
'SANITIZER=' + sanitizer,
'ARCHITECTURE=' + architecture,
]
Expand Down