Skip to content

Commit

Permalink
Parse project language and use in infra/helper.py (#3834)
Browse files Browse the repository at this point in the history
* Parse project language and use in infra/helper.py

* Fix exception message.
  • Loading branch information
inferno-chromium authored May 18, 2020
1 parent 1e83b88 commit 22443e5
Showing 1 changed file with 19 additions and 2 deletions.
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('language attribute 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

0 comments on commit 22443e5

Please sign in to comment.