[oe] [RFC] [PATCH 1/2] Implement variable typing
Chris Larson
kergoth at gmail.com
Tue Nov 9 23:59:13 UTC 2010
On Tue, Nov 9, 2010 at 4:18 PM, Chris Larson <kergoth at gmail.com> wrote:
> 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)
> }
>
See https://github.com/kergoth/openembedded/compare/master...typing for the
current version, just reworked to decouple the types from the metadata to
make their unit testing a bit cleaner. Note that the __new__ use for Choice
and Regex is pretty ugly, really only using those classes as a container to
make setting the name and flags attributes on the callable less ugly :P
Comments welcome.
--
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
More information about the Openembedded-devel
mailing list