[oe] [RFC] Variable typing support

Chris Larson clarson at kergoth.com
Wed Dec 15 16:31:30 UTC 2010


Greetings,

I'd like to propose inclusion of some work I've done on a branch to implement
variable typing.  This implementation consists of three 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
- flags to mark up the variables with the appropriate types

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)
}

https://github.com/kergoth/openembedded/commit/c278cd7 shows the core
implementation, along with the description, which is shown above.
https://github.com/kergoth/openembedded/compare/master...typing shows
the changes I've done for it so far, including the python module,
variable type checking class, and examples of usage in both
bitbake.conf and classes.

Comments?  I'd love to hear what people think of this.  Note that the
main purpose of the type *checking* is to catch issues with user
configuration variables, as opposed to variables set by recipes or
classes, but of course the markup for the others is useful if one
wants to utilize oe.types in python code.
-- 
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