aboutsummaryrefslogtreecommitdiff
path: root/infra/helper.py
diff options
context:
space:
mode:
authorAbhishek Arya <inferno@chromium.org>2020-05-17 19:22:36 -0700
committerGitHub <noreply@github.com>2020-05-17 19:22:36 -0700
commit22443e5230085291a683dd536e7e84d881333a26 (patch)
tree05b7e9867ec25ac6f6aff7ee8b04b174dc4b29ed /infra/helper.py
parent1e83b88e95ac75364950d4b64a59a80beda229e9 (diff)
downloadoss-fuzz-22443e5230085291a683dd536e7e84d881333a26.tar.gz
Parse project language and use in infra/helper.py (#3834)
* Parse project language and use in infra/helper.py * Fix exception message.
Diffstat (limited to 'infra/helper.py')
-rwxr-xr-xinfra/helper.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/infra/helper.py b/infra/helper.py
index 7f34f1d10..150835d5d 100755
--- a/infra/helper.py
+++ b/infra/helper.py
@@ -56,6 +56,8 @@ CORPUS_BACKUP_URL_FORMAT = (
'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."""
@@ -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)
@@ -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,
@@ -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.')
@@ -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,
]