@@ -53,23 +53,13 @@ class BaseCi:
53
53
def __init__ (self , config ):
54
54
self .config = config
55
55
self .workspace = workspace_utils .Workspace (config )
56
+ self ._repo_dir = None
56
57
58
+ @property
57
59
def repo_dir (self ):
58
60
"""Returns the source repo path, if it has been checked out. None is
59
61
returned otherwise."""
60
- if not os .path .exists (self .workspace .repo_storage ):
61
- return None
62
-
63
- # Note: this assumes there is only one repo checked out here.
64
- listing = os .listdir (self .workspace .repo_storage )
65
- if len (listing ) != 1 :
66
- raise RuntimeError ('Invalid repo storage.' )
67
-
68
- repo_path = os .path .join (self .workspace .repo_storage , listing [0 ])
69
- if not os .path .isdir (repo_path ):
70
- raise RuntimeError ('Repo is not a directory.' )
71
-
72
- return repo_path
62
+ raise NotImplementedError ('Child class must implement method.' )
73
63
74
64
def prepare_for_fuzzer_build (self ):
75
65
"""Builds the fuzzer builder image and gets the source code we need to
@@ -152,6 +142,31 @@ def checkout_specified_commit(repo_manager_obj, pr_ref, commit_sha):
152
142
class GithubCiMixin :
153
143
"""Mixin for Github based CI systems."""
154
144
145
+ def __init__ (self , config ):
146
+ super ().__init__ (config )
147
+ # Unlike in other classes, here _repo_dir is the parent directory of the
148
+ # repo, not its actual directory.
149
+ self ._repo_dir = self .workspace .repo_storage
150
+
151
+ @property
152
+ def repo_dir (self ):
153
+ """Returns the source repo path, if it has been checked out. None is
154
+ returned otherwise."""
155
+ if not os .path .exists (self ._repo_dir ):
156
+ logging .warning ('Repo dir: %s does not exist.' , self ._repo_dir )
157
+ return None
158
+
159
+ # Note: this assumes there is only one repo checked out here.
160
+ listing = os .listdir (self ._repo_dir )
161
+ if len (listing ) != 1 :
162
+ raise RuntimeError ('Invalid repo directory.' )
163
+
164
+ repo_path = os .path .join (self ._repo_dir , listing [0 ])
165
+ if not os .path .isdir (repo_path ):
166
+ raise RuntimeError ('Repo is not a directory.' )
167
+
168
+ return repo_path
169
+
155
170
def get_diff_base (self ):
156
171
"""Returns the base to diff against with git to get the change under
157
172
test."""
@@ -217,6 +232,16 @@ class InternalGeneric(BaseCi):
217
232
"""Class representing CI for an OSS-Fuzz project on a CI other than Github
218
233
actions."""
219
234
235
+ def __init__ (self , config ):
236
+ super ().__init__ (config )
237
+ self ._repo_dir = config .project_src_path
238
+
239
+ @property
240
+ def repo_dir (self ):
241
+ """Returns the source repo path, if it has been checked out. None is
242
+ returned otherwise."""
243
+ return self ._repo_dir
244
+
220
245
def prepare_for_fuzzer_build (self ):
221
246
"""Builds the project builder image for an OSS-Fuzz project outside of
222
247
GitHub actions. Returns the repo_manager. Does not checkout source code
@@ -263,6 +288,16 @@ def build_external_project_docker_image(project_src, build_integration_path):
263
288
class ExternalGeneric (BaseCi ):
264
289
"""CI implementation for generic CI for external (non-OSS-Fuzz) projects."""
265
290
291
+ def __init__ (self , config ):
292
+ super ().__init__ (config )
293
+ self ._repo_dir = config .project_src_path
294
+
295
+ @property
296
+ def repo_dir (self ):
297
+ """Returns the source repo path, if it has been checked out. None is
298
+ returned otherwise."""
299
+ return self ._repo_dir
300
+
266
301
def get_diff_base (self ):
267
302
return 'origin...'
268
303
0 commit comments