示例#1
0
def _build(
        config: Dict,
        config_name: str,
        timeout_seconds: int = GCB_BUILD_TIMEOUT) -> new_process.ProcessResult:
    """Submit build to GCB."""
    with tempfile.NamedTemporaryFile() as config_file:
        yaml_utils.write(config_file.name, config)
        logger.debug('Using build configuration: %s' % config)

        config_arg = '--config=%s' % config_file.name
        machine_type_arg = '--machine-type=%s' % GCB_MACHINE_TYPE

        # Use "s" suffix to denote seconds.
        timeout_arg = '--timeout=%ds' % timeout_seconds

        command = [
            'gcloud',
            'builds',
            'submit',
            str(utils.ROOT_DIR),
            config_arg,
            timeout_arg,
            machine_type_arg,
        ]

        # Don't write to stdout to make concurrent building faster. Otherwise
        # writing becomes the bottleneck.
        result = new_process.execute(command,
                                     write_to_stdout=False,
                                     kill_children=True,
                                     timeout=timeout_seconds)
        build_utils.store_build_logs(config_name, result)
    return result
示例#2
0
def main():
    """Write base-images build spec when run from command line."""
    image_templates = yaml_utils.read(
        os.path.join(ROOT_DIR, 'docker', 'image_types.yaml'))
    base_images_spec = create_cloudbuild_spec(
        {'base-image': image_templates['base-image']}, build_base_images=True)
    base_images_spec_file = os.path.join(ROOT_DIR, 'docker', 'gcb',
                                         'base-images.yaml')
    yaml_utils.write(base_images_spec_file, base_images_spec)
示例#3
0
def create_oss_fuzz_yaml(project, fuzz_target, commit, commit_date,
                         benchmark_dir):
    """Create the benchmark.yaml file in |benchmark_dir| based on the values
    from |project|, |fuzz_target|, |commit| and |commit_date|."""
    yaml_filename = os.path.join(benchmark_dir, 'benchmark.yaml')
    config = {
        'project': project,
        'fuzz_target': fuzz_target,
        'commit': commit,
        'commit_date': commit_date,
    }
    yaml_utils.write(yaml_filename, config)
示例#4
0
def set_up_fuzzer_config_files(fuzzer_configs):
    """Write configurations specified by |fuzzer_configs| to yaml files that
    will be used to store configurations."""
    if not fuzzer_configs:
        raise Exception('Need to provide either a list of fuzzers or '
                        'a list of fuzzer configs.')
    fuzzer_config_dir = os.path.join(CONFIG_DIR, 'fuzzer-configs')
    filesystem.recreate_directory(fuzzer_config_dir)
    for fuzzer_config in fuzzer_configs:
        # Validate the fuzzer yaml attributes e.g. fuzzer, env, etc.
        validate_fuzzer_config(fuzzer_config)
        config_file_name = os.path.join(fuzzer_config_dir,
                                        get_full_fuzzer_name(fuzzer_config))
        yaml_utils.write(config_file_name, fuzzer_config)
示例#5
0
def _add_build_arguments_to_config(base: str, fuzzer: str) -> str:
    """If there are fuzzer-specific arguments, make a config file with them."""
    fuzzer_config = fuzzer_config_utils.get_by_variant_name(fuzzer)
    if 'build_arguments' not in fuzzer_config:
        return base

    # TODO(mbarbella): Rather than rewrite yaml files, use the GCB API.
    args = fuzzer_config['build_arguments']
    config = yaml_utils.read(base)
    for step in config['steps']:
        if 'id' in step and step['id'] in BUILDER_STEP_IDS:
            # Append additional flags before the final argument.
            step['args'] = step['args'][:-1] + args + [step['args'][-1]]

    new_config_path = os.path.join(CONFIG_DIR, 'builds', fuzzer + '.yaml')
    filesystem.create_directory(os.path.dirname(new_config_path))
    yaml_utils.write(new_config_path, config)
    return new_config_path