Skip to content
Snippets Groups Projects
Commit 5147869a authored by Walter Lozano's avatar Walter Lozano
Browse files

generate_bom: Improve path prefix


In order to provide a more reliable path prefix and have additional
information regarding it, improve its calculation

Signed-off-by: default avatarWalter Lozano <walter.lozano@collabora.com>
parent f6780daf
No related branches found
No related tags found
1 merge request!530generate_bom: Rework scanning to improve reliability
......@@ -228,17 +228,21 @@ class BomGenerator():
# Used to get the path_prefix which should be removed before try to match
# with the information in the copyright file
# By doing this the chance of picking a default license is reduced
def get_path_prefix(self, copyright_info, units):
def get_path_prefix_and_depth(self, copyright_info, units):
path_depth = self.get_copyright_path_depth(copyright_info)
depths = path_depth.get_depths()
for pd_key in reversed(depths):
for un in units:
for p in path_depth.get_paths(pd_key):
path_prefix_len = un['file_path'].find('/' + p + '/')
if un['file_path'].startswith(p + '/'):
return ('', pd_key)
else:
path_prefix_len = un['file_path'].find('/' + p + '/')
if path_prefix_len != -1:
return un['file_path'][:path_prefix_len + 1]
return ''
return (un['file_path'][:path_prefix_len + 1], pd_key)
return ('', -1)
def scan_rust_unit(self, f_dir, f_src, copyright_info, out_licenses, out_copyright):
# Rust files only have one compilation unit for the entire
......@@ -292,7 +296,7 @@ class BomGenerator():
return {'binary_name': binary_name, 'binary_licenses': [NO_LICENSE_REPORT_FOUND], 'sources': sources}
self.preprocess_unit(units)
path_prefix = self.get_path_prefix(package_copyright_files.primary_copyright, units)
(path_prefix, depth) = self.get_path_prefix_and_depth(package_copyright_files.primary_copyright, units)
for un in units:
file_copyright_info = package_copyright_files.find_copyright_for_path(un['comp_name'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment