mirror of https://github.com/google/oss-fuzz.git
Parse project language and use in infra/helper.py (#3834)
* Parse project language and use in infra/helper.py * Fix exception message.
This commit is contained in:
parent
1e83b88e95
commit
22443e5230
|
@ -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,
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue