@@ -239,8 +239,14 @@ def exclude_file_in_yaml(path_to_find, yaml_files, license_missing_files, copyri
239239 excluded_path = []
240240 lic_present_path = []
241241 cop_present_path = []
242+ abnormal_yaml_files = {}
243+
242244 for file in yaml_files :
243- oss_items , _ = parsing_yml (file , path_to_find )
245+ oss_items , _ , err_reason = parsing_yml (file , path_to_find , False )
246+ # if oss_items is abnormal(empty or invalid)
247+ if not oss_items :
248+ abnormal_yaml_files [file ] = err_reason
249+
244250 for oss_item in oss_items :
245251 if oss_item .exclude :
246252 excluded_path .extend (get_path_in_yaml (oss_item ))
@@ -255,7 +261,7 @@ def exclude_file_in_yaml(path_to_find, yaml_files, license_missing_files, copyri
255261 license_missing_files = extract_files_in_path (lic_present_path , list (license_missing_files - set (files_with_exclude_removed )))
256262 copyright_missing_files = extract_files_in_path (cop_present_path , list (copyright_missing_files - set (files_with_exclude_removed )))
257263
258- return license_missing_files , copyright_missing_files
264+ return license_missing_files , copyright_missing_files , abnormal_yaml_files
259265
260266
261267def get_total_file_list (path_to_find , prj_report , exclude_files ):
@@ -266,12 +272,33 @@ def get_total_file_list(path_to_find, prj_report, exclude_files):
266272 return total_files_excluded
267273
268274
275+ def add_reason_to_file_name (oss_pkg_info_files , abnormal_yaml_files , path_to_find ):
276+ if not path_to_find .endswith ('/' ):
277+ path_to_find += '/'
278+
279+ for key , val in abnormal_yaml_files .items ():
280+ file_name = key .replace (path_to_find , '' , 1 )
281+ if file_name in oss_pkg_info_files :
282+ oss_pkg_info_files .remove (file_name )
283+ if val == "yaml_error" :
284+ file_name += " (Yaml format error)"
285+ elif val == "not_supported" :
286+ file_name += " (Not supported format)"
287+ elif val == "empty" :
288+ file_name += " (Empty)"
289+ else :
290+ file_name += " (Unknown error)"
291+ oss_pkg_info_files .append (file_name )
292+ return oss_pkg_info_files
293+
294+
269295def result_for_summary (path_to_find , oss_pkg_info_files , license_missing_files , copyright_missing_files ,
270296 prj_report , _result_log , _check_only_file_mode , file_to_check_list , error_items , exclude_files ):
271297 prechecker_compliant = False
272298 detected_lic = []
273299 missing_both_files = []
274300 file_total_num = ""
301+ abnormal_yaml_files = {}
275302
276303 if _check_only_file_mode :
277304 file_total_num = len (file_to_check_list )
@@ -286,12 +313,16 @@ def result_for_summary(path_to_find, oss_pkg_info_files, license_missing_files,
286313 if oss_pkg_info_files :
287314 oss_yaml_files = find_sbom_yaml_files (path_to_find )
288315 # Exclude files in yaml
289- license_missing_files , copyright_missing_files = exclude_file_in_yaml (path_to_find , oss_yaml_files ,
290- set (license_missing_files ) - set (oss_pkg_info_files ),
291- set (copyright_missing_files ) - set (oss_pkg_info_files ))
316+ license_missing_files , copyright_missing_files , abnormal_yaml_files \
317+ = exclude_file_in_yaml (path_to_find , oss_yaml_files ,
318+ set (license_missing_files ) - set (oss_pkg_info_files ),
319+ set (copyright_missing_files ) - set (oss_pkg_info_files ))
292320 # Subtract excluded files(untracked or ignored file)
293321 oss_pkg_info_files = list (set (oss_pkg_info_files ) - set (exclude_files ))
294322
323+ # Add invalid format to file name
324+ oss_pkg_info_files = add_reason_to_file_name (oss_pkg_info_files , abnormal_yaml_files , path_to_find )
325+
295326 if len (license_missing_files ) == 0 and len (copyright_missing_files ) == 0 :
296327 prechecker_compliant = True
297328
0 commit comments