Skip to content

Instantly share code, notes, and snippets.

@kergoth
Last active September 29, 2015 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/1590028 to your computer and use it in GitHub Desktop.
Save kergoth/1590028 to your computer and use it in GitHub Desktop.
INCOMPATIBLE_LICENSE ?= ""
LICENSE_PRIORITY = "\
MIT \
LGPL-2.0 LGPL-2.1 \
GPL-2.0 GPL-2.0 \
* \
LGPL-3.0 GPL-3.0 \
Proprietary CLOSED \
${INCOMPATIBLE_LICENSE} \
"
LICENSE_PRIORITY[doc] = "Space separated list of licenses in priority order, \
highest to lowest, with '*' being the catchall for any licenses not listed"
PRIORITIZED_LICENSE = "${@prioritized_license(LICENSE, LICENSE_PRIORITY, d.getVarFlags('SPDXLICENSEMAP'))}"
PRIORITIZED_LICENSE[doc] = "Flattened version of the license, obeying specified license priorities"
def prioritized_license(licensestr, prioritystr, licensemap):
priorities = prioritystr.split()
priorities.reverse()
baseline = priorities.index('*')
def get_license_priority(one_license):
if one_license in priorities:
return priorities.index(one_license) - baseline
else:
return baseline
def prioritized_license_choice(alpha, beta):
alpha = [licensemap.get(l, l) for l in alpha]
beta = [licensemap.get(l, l) for l in beta]
alpha_weight = sum(get_license_priority(a) for a in alpha)
beta_weight = sum(get_license_priority(b) for b in beta)
if alpha_weight > beta_weight:
return alpha
else:
return beta
try:
flattened = oe.license.flattened_licenses(licensestr, prioritized_license_choice)
except oe.license.LicenseError as exc:
bb.warn("Error processing license: %s" % exc)
return licensestr
else:
return ' '.join(flattened)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment