aboutsummaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-11-09 14:48:13 -0700
committerMartin Jansa <Martin.Jansa@gmail.com>2011-04-22 16:39:18 +0200
commit78810c941391ae4b155b02818193e971f0d5a7c0 (patch)
tree7ec69d177be87ea320a94fcf18faf55cce1d0810 /classes
parenta87337170a93fdb6c636c84e3cf1b2108964f863 (diff)
downloadopenembedded-78810c941391ae4b155b02818193e971f0d5a7c0.tar.gz
Implement variable typing
This implementation consists of two components: - oe.types python module, 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.types for pkg in oe.types.value("PACKAGES", d): bb.note("package: %s" % pkg) } LIBTOOL_HAS_SYSROOT = "yes" LIBTOOL_HAS_SYSROOT[type] = "boolean" python () { import oe.types assert(oe.types.value("LIBTOOL_HAS_SYSROOT", d) == True) } Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'classes')
-rw-r--r--classes/typecheck.bbclass12
1 files changed, 12 insertions, 0 deletions
diff --git a/classes/typecheck.bbclass b/classes/typecheck.bbclass
new file mode 100644
index 0000000000..646cd4eed2
--- /dev/null
+++ b/classes/typecheck.bbclass
@@ -0,0 +1,12 @@
+# Check types of bitbake configuration variables
+#
+# See oe.types for details.
+
+python check_types() {
+ import oe.types
+ if isinstance(e, bb.event.ConfigParsed):
+ for key in e.data.keys():
+ if e.data.getVarFlag(key, "type"):
+ oe.types.value(key, e.data)
+}
+addhandler check_types