2626from licensedcode .detection import detect_licenses
2727from licensedcode .detection import LicenseDetectionFromResult
2828from licensedcode .detection import populate_matches_with_path
29+ from licensedcode .detection import use_referenced_license_expression
2930from licensedcode .spans import Span
3031from licensedcode import query
3132
@@ -93,6 +94,7 @@ def add_referenced_license_matches_for_package(resource, codebase):
9394 file_path = resource .path ,
9495 )
9596
97+ detections_added = []
9698 detection_modified = False
9799 license_match_mappings = license_detection_mapping ["matches" ]
98100 referenced_filenames = get_referenced_filenames (license_detection_object .matches )
@@ -106,16 +108,24 @@ def add_referenced_license_matches_for_package(resource, codebase):
106108 codebase = codebase ,
107109 )
108110
109- if not referenced_resource :
110- continue
111-
112- referenced_license_detections = referenced_resource .license_detections
111+ if referenced_resource and referenced_resource .license_detections :
112+ referenced_license_expression = combine_expressions (
113+ expressions = [
114+ detection ["license_expression" ]
115+ for detection in referenced_resource .license_detections
116+ ],
117+ )
118+ if not use_referenced_license_expression (
119+ referenced_license_expression = referenced_license_expression ,
120+ license_detection = license_detection_object ,
121+ ):
122+ continue
113123
114- if referenced_license_detections :
115124 modified = True
116125 detection_modified = True
126+ detections_added .extend (referenced_resource .license_detections )
117127 matches_to_extend = get_matches_from_detection_mappings (
118- license_detections = referenced_license_detections
128+ license_detections = referenced_resource . license_detections
119129 )
120130 # For LicenseMatches with different resources as origin, add the
121131 # resource path to these matches as origin info
@@ -142,7 +152,7 @@ def add_referenced_license_matches_for_package(resource, codebase):
142152 license_detection_mapping ["detection_log" ] = detection_log
143153 license_detection_mapping ["identifier" ] = get_new_identifier_from_detections (
144154 initial_detection = license_detection_mapping ,
145- detections_added = referenced_license_detections ,
155+ detections_added = detections_added ,
146156 license_expression = license_expression ,
147157 )
148158
@@ -223,7 +233,20 @@ def add_referenced_license_detection_from_package(resource, codebase):
223233 f'sibling_license_detections: { sibling_license_detections } '
224234 )
225235
236+ referenced_license_expression = combine_expressions (
237+ expressions = [
238+ detection ["license_expression" ]
239+ for detection in sibling_license_detections
240+ ],
241+ )
242+ if not use_referenced_license_expression (
243+ referenced_license_expression = referenced_license_expression ,
244+ license_detection = license_detection_object ,
245+ ):
246+ continue
247+
226248 for sibling_detection in sibling_license_detections :
249+
227250 modified = True
228251 detection_modified = True
229252 license_match_mappings .extend (sibling_detection ["matches" ])
@@ -239,6 +262,21 @@ def add_referenced_license_detection_from_package(resource, codebase):
239262 break
240263
241264 pkg_detections = codebase_package ["license_detections" ]
265+ if not pkg_detections :
266+ continue
267+
268+ referenced_license_expression = combine_expressions (
269+ expressions = [
270+ detection ["license_expression" ]
271+ for detection in pkg_detections
272+ ],
273+ )
274+ if not use_referenced_license_expression (
275+ referenced_license_expression = referenced_license_expression ,
276+ license_detection = license_detection_object ,
277+ ):
278+ continue
279+
242280 for pkg_detection in pkg_detections :
243281 modified = True
244282 detection_modified = True
0 commit comments