summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/license.bbclass63
1 files changed, 63 insertions, 0 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 4b98e29916..10a937b10c 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -282,6 +282,69 @@ def incompatible_license(d,dont_want_license):
282 return True 282 return True
283 return False 283 return False
284 284
285
286def check_license_flags(d):
287 """
288 This function checks if a recipe has any LICENSE_FLAGs that
289 aren't whitelisted.
290
291 If it does, it returns the first LICENSE_FLAG missing from the
292 whitelist, or all the LICENSE_FLAGs if there is no whitelist.
293
294 If everything is is properly whitelisted, it returns None.
295 """
296
297 def license_flag_matches(flag, whitelist, pn):
298 """
299 Return True if flag matches something in whitelist, None if not.
300
301 Before we test a flag against the whitelist, we append _${PN}
302 to it. We then try to match that string against the
303 whitelist. This covers the normal case, where we expect
304 LICENSE_FLAGS to be a simple string like 'commercial', which
305 the user typically matches exactly in the whitelist by
306 explicitly appending the package name e.g 'commercial_foo'.
307 If we fail the match however, we then split the flag across
308 '_' and append each fragment and test until we either match or
309 run out of fragments.
310 """
311 flag_pn = ("%s_%s" % (flag, pn))
312 for candidate in whitelist:
313 if flag_pn == candidate:
314 return True
315
316 flag_cur = ""
317 flagments = flag_pn.split("_")
318 flagments.pop() # we've already tested the full string
319 for flagment in flagments:
320 if flag_cur:
321 flag_cur += "_"
322 flag_cur += flagment
323 for candidate in whitelist:
324 if flag_cur == candidate:
325 return True
326 return False
327
328 def all_license_flags_match(license_flags, whitelist):
329 """ Return first unmatched flag, None if all flags match """
330 pn = d.getVar('PN', True)
331 split_whitelist = whitelist.split()
332 for flag in license_flags.split():
333 if not license_flag_matches(flag, split_whitelist, pn):
334 return flag
335 return None
336
337 license_flags = d.getVar('LICENSE_FLAGS', True)
338 if license_flags:
339 whitelist = d.getVar('LICENSE_FLAGS_WHITELIST', True)
340 if not whitelist:
341 return license_flags
342 unmatched_flag = all_license_flags_match(license_flags, whitelist)
343 if unmatched_flag:
344 return unmatched_flag
345 return None
346
347
285SSTATETASKS += "do_populate_lic" 348SSTATETASKS += "do_populate_lic"
286do_populate_lic[sstate-name] = "populate-lic" 349do_populate_lic[sstate-name] = "populate-lic"
287do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}" 350do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}"