@@ -546,10 +546,13 @@ def build_license(self, mapping, scancode_licenses):
546546 # instead each part of the combo
547547 dejacode_special_composites = set ([
548548 'intel-bsd-special' ,
549+ #'newlib-subdirectory',
549550 ])
550- is_combo = key in dejacode_special_composites
551+ is_component_license = mapping .get ('is_component_license' ) or False
552+
553+ is_combo = is_component_license or key in dejacode_special_composites
551554 if is_combo :
552- if TRACE : print ('Skipping DejaCode combo license' , key )
555+ if TRACE : print ('Skipping DejaCode combo/component license' , key )
553556 return
554557
555558 deprecated = not mapping .get ('is_active' )
@@ -560,6 +563,13 @@ def build_license(self, mapping, scancode_licenses):
560563 standard_notice = mapping .get ('standard_notice' ) or ''
561564 standard_notice = clean_text (standard_notice )
562565
566+ spdx_license_key = mapping .get ('spdx_license_key' ) or None
567+ if deprecated :
568+ spdx_license_key = None
569+ else :
570+ if not spdx_license_key :
571+ spdx_license_key = f'LicenseRef-scancode-{ key } '
572+
563573 lic = License (
564574 key = key ,
565575 src_dir = self .original_dir ,
@@ -572,7 +582,7 @@ def build_license(self, mapping, scancode_licenses):
572582
573583 # FIXME: we may not want to carry notes over???
574584 # lic.notes = mapping.notes
575- spdx_license_key = mapping [ ' spdx_license_key' ] ,
585+ spdx_license_key = spdx_license_key ,
576586 text_urls = mapping ['text_urls' ].splitlines (False ),
577587 osi_url = mapping ['osi_url' ],
578588 faq_url = mapping ['faq_url' ],
@@ -805,8 +815,12 @@ def license_to_dict(lico):
805815}
806816
807817
808- def merge_licenses (scancode_license , external_license , updatable_attributes ,
809- from_spdx = False ):
818+ def merge_licenses (
819+ scancode_license ,
820+ external_license ,
821+ updatable_attributes ,
822+ from_spdx = False ,
823+ ):
810824 """
811825 Compare and update two License objects in-place given a sequence of
812826 `updatable_attributes`.
@@ -839,20 +853,21 @@ def update_external(_attrib, _sc_val, _ext_val):
839853 external_key = external_license .spdx_license_key
840854 if scancode_key != external_key :
841855 raise Exception (
842- f'Non mergeable licenses with different SPDX keys: scancode_license.spdx_license_key { scancode_key } <> external_license.spdx_license_key { external_key } '
856+ f'Non mergeable licenses with different SPDX keys: '
857+ 'scancode_license.spdx_license_key {scancode_key} <> '
858+ 'external_license.spdx_license_key {external_key}'
843859 )
844860 else :
845861 scancode_key = scancode_license .key
846862 external_key = external_license .key
847863 if scancode_key != external_key :
848- raise Exception ('Non mergeable licenses with different keys: %(scancode_key)s <> %(external_key)s' % locals ())
864+ raise Exception ('Non mergeable licenses with different keys: '
865+ '%(scancode_key)s <> %(external_key)s' % locals ())
849866
850- # if scancode_license.spdx_license_key != external_license.spdx_license_key:
851- # pass
852- # else:
853- # if TRACE:
854- # print('Merging licenses with different keys, but same SPDX key: %(scancode_key)s <> %(external_key)s' % locals())
855- # update_external('key', scancode_key, external_key)
867+ if scancode_license .spdx_license_key != external_license .spdx_license_key :
868+ if TRACE :
869+ print (f'Updating external SPDX key: from { external_license .spdx_license_key } to { scancode_license .spdx_license_key } ' )
870+ external_license .spdx_license_key = scancode_license .spdx_license_key
856871
857872 for attrib in updatable_attributes :
858873 scancode_value = getattr (scancode_license , attrib )
@@ -932,7 +947,11 @@ def update_external(_attrib, _sc_val, _ext_val):
932947
933948 # on difference, the other license wins
934949 if scancode_value != external_value :
935- update_scancode (attrib , scancode_value , external_value )
950+ # unless we have SPDX ids
951+ if attrib == 'spdx_license_key' and external_value .startswith ('LicenseRef-scancode' ):
952+ update_external (attrib , scancode_value , external_value )
953+ else :
954+ update_scancode (attrib , scancode_value , external_value )
936955 continue
937956
938957 return updated_scancode_attributes , updated_external_attributes
@@ -1065,16 +1084,20 @@ def synchronize_licenses(scancode_licenses, external_source, use_spdx_key=False,
10651084 print ('External license with different key:' , matching_key , 'and text matched to ScanCode key:' , matched_key )
10661085
10671086 if matched_key :
1068- print ('\n External license with different key and matched text to ScanCode :' , matching_key , ' matched to:' , matched_key )
1087+ print ('External license with different key:' , matching_key , 'and text matched to ScanCode key :' , matched_key )
10691088 if matched_key in unmatched_scancode_by_key :
10701089 del unmatched_scancode_by_key [matched_key ]
10711090
10721091 scancode_license = scancodes_by_key .get (matched_key )
1092+ if TRACE :
1093+ print ('scancode_license:' , matching_key , scancode_license )
10731094
10741095 scancode_updated , external_updated = merge_licenses (
1075- scancode_license , external_license ,
1076- external_source .updatable_attributes ,
1077- from_spdx = use_spdx_key )
1096+ scancode_license = scancode_license ,
1097+ external_license = external_license ,
1098+ updatable_attributes = external_source .updatable_attributes ,
1099+ from_spdx = use_spdx_key ,
1100+ )
10781101
10791102 if not scancode_updated and not external_updated :
10801103 if TRACE_DEEP : print ('License attributes are identical:' , matching_key )
0 commit comments