61
61
LOCAL_BUILD_LOG_PATH = '/workspace/build.log'
62
62
BUILD_SUCCESS_MARKER = '/workspace/build.succeeded'
63
63
64
+ _CACHED_IMAGE = ('us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/'
65
+ '{name}-ofg-cached-{sanitizer}' )
66
+ _CACHED_SANITIZERS = ('address' , 'coverage' )
67
+
64
68
65
69
@dataclass
66
70
class Config :
@@ -163,6 +167,8 @@ def __init__(self, name, project_yaml, dockerfile):
163
167
else :
164
168
self .main_repo = ''
165
169
170
+ self .cached_sanitizer = None
171
+
166
172
@property
167
173
def sanitizers (self ):
168
174
"""Returns processed sanitizers."""
@@ -172,8 +178,14 @@ def sanitizers(self):
172
178
@property
173
179
def image (self ):
174
180
"""Returns the docker image for the project."""
181
+ if self .cached_sanitizer :
182
+ return self .cached_image (self .cached_sanitizer )
183
+
175
184
return f'gcr.io/{ build_lib .IMAGE_PROJECT } /{ self .name } '
176
185
186
+ def cached_image (self , sanitizer ):
187
+ return _CACHED_IMAGE .format (name = self .name , sanitizer = sanitizer )
188
+
177
189
178
190
def get_last_step_id (steps ):
179
191
"""Returns the id of the last step in |steps|."""
@@ -313,30 +325,37 @@ def get_build_steps( # pylint: disable=too-many-locals, too-many-statements, to
313
325
project_yaml ,
314
326
dockerfile ,
315
327
config ,
316
- additional_env = None ):
328
+ additional_env = None ,
329
+ use_caching = False ):
317
330
"""Returns build steps for project."""
318
331
319
332
project = Project (project_name , project_yaml , dockerfile )
320
-
321
333
if project .disabled :
322
334
logging .info ('Project "%s" is disabled.' , project .name )
323
335
return []
324
336
325
337
timestamp = get_datetime_now ().strftime ('%Y%m%d%H%M' )
326
- build_steps = build_lib .get_project_image_steps (
327
- project .name ,
328
- project .image ,
329
- project .fuzzing_language ,
330
- config = config ,
331
- architectures = project .architectures ,
332
- experiment = config .experiment )
338
+ if use_caching :
339
+ # Use cached built image.
340
+ build_steps = []
341
+ else :
342
+ build_steps = build_lib .get_project_image_steps (
343
+ project .name ,
344
+ project .image ,
345
+ project .fuzzing_language ,
346
+ config = config ,
347
+ architectures = project .architectures ,
348
+ experiment = config .experiment )
333
349
334
350
# Sort engines to make AFL first to test if libFuzzer has an advantage in
335
351
# finding bugs first since it is generally built first.
336
352
for fuzzing_engine in sorted (project .fuzzing_engines ):
337
353
# Sort sanitizers and architectures so order is determinisitic (good for
338
354
# tests).
339
355
for sanitizer in sorted (project .sanitizers ):
356
+ if use_caching and sanitizer in _CACHED_SANITIZERS :
357
+ project .cached_sanitizer = sanitizer
358
+
340
359
# Build x86_64 before i386.
341
360
for architecture in reversed (sorted (project .architectures )):
342
361
build = Build (fuzzing_engine , sanitizer , architecture )
0 commit comments