cached build: Re-build for every sanitizer. (#12695)

This commit is contained in:
Oliver Chang 2024-11-07 15:19:31 +11:00 committed by GitHub
parent e3ccf897f8
commit ff5360419e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 33 deletions

View File

@ -442,7 +442,8 @@ def get_project_image_steps( # pylint: disable=too-many-arguments
config,
architectures=None,
experiment=False,
cache_image=None):
cache_image=None,
srcmap=True):
"""Returns GCB steps to build OSS-Fuzz project image."""
if architectures is None:
architectures = []
@ -459,29 +460,25 @@ def get_project_image_steps( # pylint: disable=too-many-arguments
steps.extend(get_pull_test_images_steps(config.test_image_suffix))
src_root = 'oss-fuzz' if not experiment else '.'
steps.append({
'name': 'ubuntu',
'args': ['bash', '-c', f'cat {src_root}/projects/{name}/Dockerfile'],
})
docker_build_step = get_docker_build_step([image],
os.path.join('projects', name),
src_root=src_root,
cache_image=cache_image)
steps.append(docker_build_step)
srcmap_step_id = get_srcmap_step_id()
steps.extend([{
'name': image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': [
'OSSFUZZ_REVISION=$REVISION_ID',
'FUZZING_LANGUAGE=%s' % language,
],
'id': srcmap_step_id
}])
if srcmap:
srcmap_step_id = get_srcmap_step_id()
steps.extend([{
'name': image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': [
'OSSFUZZ_REVISION=$REVISION_ID',
'FUZZING_LANGUAGE=%s' % language,
],
'id': srcmap_step_id
}])
if has_arm_build(architectures):
builder_name = 'buildxbuilder'

View File

@ -354,22 +354,19 @@ def get_build_steps_for_project(project,
timestamp = get_datetime_now().strftime('%Y%m%d%H%M')
# If we use caching, then we need to use the right name. We assume that
# there is only a single sanitizer.
if use_caching:
project.cached_sanitizer = project.sanitizers[0]
cache_image = project.cached_image
# For cached builds: the cache images are sanitizer-specific, so we need to
# do a rebuild prior to each compile.
build_steps = []
else:
cache_image = None
build_steps = build_lib.get_project_image_steps(
project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment,
cache_image=cache_image)
# Non-cached builds just use a single builder image to build all sanitizers.
build_steps = build_lib.get_project_image_steps(
project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment)
# Sort engines to make AFL first to test if libFuzzer has an advantage in
# finding bugs first since it is generally built first.
@ -379,6 +376,15 @@ def get_build_steps_for_project(project,
for sanitizer in sorted(project.sanitizers):
if use_caching and sanitizer in _CACHED_SANITIZERS:
project.cached_sanitizer = sanitizer
build_steps.extend(
build_lib.get_project_image_steps(
project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment,
cache_image=project.cached_image))
# Build x86_64 before i386.
for architecture in reversed(sorted(project.architectures)):

View File

@ -220,6 +220,15 @@ def run_experiment(project_name,
if use_cached_image:
project.cached_sanitizer = 'coverage'
steps.extend(
build_lib.get_project_image_steps(project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment,
cache_image=project.cached_image,
srcmap=False))
steps.append(
build_project.get_compile_step(project, build, env, config.parallel))