3131import sys
3232import tempfile
3333import urllib .request
34- import yaml
3534
3635import constants
3736import templates
@@ -126,44 +125,40 @@ def _get_base_runner_image(args, debug=False):
126125# pylint: disable=too-many-lines
127126
128127
128+ def _get_yaml_value (yaml_path , key ):
129+ """Manually parses a YAML file to find the value of a given key."""
130+ if not os .path .exists (yaml_path ):
131+ return None
132+
133+ with open (yaml_path ) as f :
134+ for line in f :
135+ if line .strip ().startswith (key + ':' ):
136+ try :
137+ return line .split (':' , 1 )[1 ].strip ()
138+ except IndexError :
139+ continue
140+ return None
141+
142+
129143class Project :
130- """Class representing a project that is in OSS-Fuzz or an external project
131- (ClusterFuzzLite user)."""
132-
133- def __init__ (
134- self ,
135- project_name_or_path ,
136- is_external = False ,
137- build_integration_path = constants .DEFAULT_EXTERNAL_BUILD_INTEGRATION_PATH ):
138- self .is_external = is_external
139- if self .is_external :
140- self .path = os .path .abspath (project_name_or_path )
141- self .name = os .path .basename (self .path )
142- self .build_integration_path = os .path .join (self .path ,
143- build_integration_path )
144- else :
145- self .name = project_name_or_path
146- self .path = os .path .join (OSS_FUZZ_DIR , 'projects' , self .name )
147- self .build_integration_path = self .path
144+ """Project class."""
148145
149- @property
150- def dockerfile_path (self ):
151- """Returns path to the project Dockerfile."""
152- return os .path .join (self .build_integration_path , 'Dockerfile' )
146+ def __init__ (self , project_path , name = None , workdir = OSS_FUZZ_DIR ):
147+ if not name :
148+ name = os .path .basename (project_path )
149+
150+ self .name = name
151+ self .path = project_path
152+ self .workdir = workdir
153153
154154 @property
155155 def language (self ):
156156 """Returns project language."""
157157 project_yaml_path = os .path .join (self .build_integration_path ,
158158 'project.yaml' )
159- if not os .path .exists (project_yaml_path ):
160- logger .warning ('No project.yaml. Assuming c++.' )
161- return constants .DEFAULT_LANGUAGE
162-
163- with open (project_yaml_path ) as file_handle :
164- config = yaml .safe_load (file_handle )
165- if config and 'language' in config :
166- return config ['language' ]
159+ language = _get_yaml_value (project_yaml_path , 'language' )
160+ if language :
161+ return language
167162
168163 logger .warning ('Language not specified in project.yaml. Assuming c++.' )
169164 return constants .DEFAULT_LANGUAGE
@@ -173,15 +168,8 @@ def base_os_version(self):
173168 """Returns the project's base OS version."""
174169 project_yaml_path = os .path .join (self .build_integration_path ,
175170 'project.yaml' )
176- if not os .path .exists (project_yaml_path ):
177- return 'legacy'
178-
179- with open (project_yaml_path ) as file_handle :
180- config = yaml .safe_load (file_handle )
181- version = 'legacy'
182- if config and 'base_os_version' in config :
183- version = config ['base_os_version' ]
184- return version
171+ version = _get_yaml_value (project_yaml_path , 'base_os_version' )
172+ return version or 'legacy'
185173
186174 @property
187175 def coverage_extra_args (self ):
0 commit comments