summaryrefslogtreecommitdiffstats
path: root/meta/classes/typecheck.bbclass
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-11-09 14:48:13 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-05-20 17:34:22 +0100
commite4921fda5b3a18c797acd267f2b1179ac032cd42 (patch)
treeb0a0df97faac10cbc8008e3db55cd81235b76379 /meta/classes/typecheck.bbclass
parent4f5209ce31f1cc7fc0c97453b5247640c07e7f31 (diff)
downloadpoky-e4921fda5b3a18c797acd267f2b1179ac032cd42.tar.gz
Implement variable typing (sync from OE)
This implementation consists of two components: - Type creation python modules, whose job it is to construct objects of the defined type for a given variable in the metadata - typecheck.bbclass, which iterates over all configuration variables with a type defined and uses oe.types to check the validity of the values This gives us a few benefits: - Automatic sanity checking of all configuration variables with a defined type - Avoid duplicating the "how do I make use of the value of this variable" logic between its users. For variables like PATH, this is simply a split(), for boolean variables, the duplication can result in confusing, or even mismatched semantics (is this 0/1, empty/nonempty, what?) - Make it easier to create a configuration UI, as the type information could be used to provide a better interface than a text edit box (e.g checkbox for 'boolean', dropdown for 'choice') This functionality is entirely opt-in right now. To enable the configuration variable type checking, simply INHERIT += "typecheck". Example of a failing type check: BAZ = "foo" BAZ[type] = "boolean" $ bitbake -p FATAL: BAZ: Invalid boolean value 'foo' $ Examples of leveraging oe.types in a python snippet: PACKAGES[type] = "list" python () { import oe.data for pkg in oe.data.typed_value("PACKAGES", d): bb.note("package: %s" % pkg) } LIBTOOL_HAS_SYSROOT = "yes" LIBTOOL_HAS_SYSROOT[type] = "boolean" python () { import oe.data assert(oe.data.typed_value("LIBTOOL_HAS_SYSROOT", d) == True) } (From OE-Core rev: a04ce490e933fc7534db33f635b025c25329c564) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/typecheck.bbclass')
-rw-r--r--meta/classes/typecheck.bbclass12
1 files changed, 12 insertions, 0 deletions
diff --git a/meta/classes/typecheck.bbclass b/meta/classes/typecheck.bbclass
new file mode 100644
index 0000000000..646cd4eed2
--- /dev/null
+++ b/meta/classes/typecheck.bbclass
@@ -0,0 +1,12 @@
1# Check types of bitbake configuration variables
2#
3# See oe.types for details.
4
5python check_types() {
6 import oe.types
7 if isinstance(e, bb.event.ConfigParsed):
8 for key in e.data.keys():
9 if e.data.getVarFlag(key, "type"):
10 oe.types.value(key, e.data)
11}
12addhandler check_types