20 May 2011 18:40
Chris Larson : Implement variable typing (sync from OE)
Module: openembedded-core.git Branch: master Commit: a04ce490e933fc7534db33f635b025c25329c564 URL: http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=a04ce490e933fc7534db33f635b025c25329c564 Author: Chris Larson <chris_larson@...> Date: Tue Nov 9 14:48:13 2010 -0700 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) } Signed-off-by: Chris Larson <chris_larson@...> --- meta/classes/base.bbclass | 1 + meta/classes/typecheck.bbclass | 12 +++++ meta/lib/oe/data.py | 13 +++++ meta/lib/oe/maketype.py | 100 ++++++++++++++++++++++++++++++++++++++ meta/lib/oe/test_types.py | 62 ++++++++++++++++++++++++ meta/lib/oe/types.py | 104 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 292 insertions(+), 0 deletions(-) Diff: http://git.openembedded.org/?p=openembedded-core.git/?a=commitdiff;h=a04ce490e933fc7534db33f635b025c25329c564
RSS Feed