summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@intel.com>2011-12-31 13:06:39 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-01-24 11:54:15 +0000
commitb68ea543603c35f4e3519d358e0d1e1e24bd5851 (patch)
tree8f914c8b559cdf09bb78ea45331934d3650cf85b /meta/classes
parent127d1fd1c2771e732f7b8b8699352e855a308cae (diff)
downloadpoky-b68ea543603c35f4e3519d358e0d1e1e24bd5851.tar.gz
license.bbclass: add support for LICENSE_FLAGS
LICENSE_FLAGS are a per-recipe replacement for the COMMERCIAL_LICENSE mechanism. In the COMMERCIAL_LICENSE mechanism, any package name mentioned in the global COMMERCIAL_LICENSE list is 'blacklisted' from being included in an image. To allow the blacklisted package into the image, the corresponding packages need to be removed from the COMMERCIAL_LICENSE list. This mechanism relies on a global list defined in default-distrovars.inc. The LICENSE_FLAGS mechanism essentially implements the same thing but turns the global blacklist into a per-recipe whitelist. Any recipe can optionally define one or more 'license flags'; if defined, each of the license flags defined for a recipe must have matching entries in a global LICENSE_FLAGS_WHITELIST variable. The definition of 'matching' is simple, but there are a couple things users need to know in order to correctly and effectively use it. Before we test a flag against the whitelist, we append _${PN} to it, thus automatically making each LICENSE_FLAG recipe-specific. We then try to match that string against the whitelist. So if the user specifies LICENSE_FLAGS = 'commercial' for recipe 'foo', the string 'commercial_foo' should be specified in the whitelist in order for it to match. However, the user can also broaden the match by putting any '_'-separated beginning subset of a LICENSE_FLAG in the whitelist, which will also match e.g. simply specifying 'commercial' in the whitelist would match any expanded LICENSE_FLAG starting with 'commercial' such as 'commercial_foo' and 'commercial_bar' which are the strings that would have been automatically generated if those recipes had simply specified LICENSE_FLAGS = 'commercial' This allows for a range of specificity for the items in the whitelist, from more general to perfectly specific. So users have the choice of exhaustively enumerating each license flag in the whitelist to allow only those specific recipes into the image, or of using a more general string to pick up anything matching just the first component(s). Note that this scheme works even if the flag already has _pn appended - the extra _pn is redundant, but doesn't affect the outcome e.g. a license flag of 'commercial_1.2_foo' would turn into 'commercial_1.2_foo_foo' and would match both the general 'commercial' and the specific 'commercial_1.2_foo' as expected (it would also match commercial_1.2_foo_foo' and 'commercial_1.2', which don't make much sense as far as something a user would think of specifying in the whitelist). For a versioned string, the user could instead specify 'commercial_foo_1.2', which would turn into 'commercial_foo_1.2_foo', but which would as expected allow the user to pick up this package along with anything else 'commercial' by specifying 'commercial' in the whitelist, or anything with a 'commercial_foo' license regardless of version by using 'commercial_foo' in the whitelist, or 'commercial_foo_1.1' to be completely specific about package and version. The current behavior of COMMERCIAL_LICENSE is replicated as mentioned above by having the current set of COMMERCIAL_LICENSE flags implemented using LICENSE_FLAGS = "commercial". That being the case, the current COMMERCIAL_LICENSE can equivalently be specified in the new scheme by putting the below in local.conf: # This is a list of packages that require a commercial license to ship # product. If shipped as part of an image these packages may have # implications so they are disabled by default. To enable them, # un-comment the below as appropriate. #LICENSE_FLAGS_WHITELIST = "commercial_gst-fluendo-mp3 \ # commercial_gst-openmax \ # commercial_gst-plugins-ugly \ # commercial_lame \ # commercial_libmad \ # commercial_libomxil \ # commercial_mpeg2dec \ # commercial_qmmp" The above allows all of the current COMMERCIAL_LICENSE packages in - to disallow a particular package from appearing in the image, simply remove it from the whitelist. To allow them all in, you could also specify LICENSE_FLAGS_WHITELIST = "commercial". (From OE-Core rev: a2760661b8c7a4a1b6f2e556853b3a9ae38cbcb5) Signed-off-by: Tom Zanussi <tom.zanussi@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-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}"