diff --git a/scripts/generate_bom.py b/scripts/generate_bom.py index 0291f4780a79c74e12d25f197f2cb1280059449d..c32af0e9fa35182eb0c1400a10739767dfb3a0c5 100755 --- a/scripts/generate_bom.py +++ b/scripts/generate_bom.py @@ -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'])