[yocto] Error while trying to read environment variable from a recipe file

Paul Eggleton paul.eggleton at linux.intel.com
Tue Feb 10 03:47:36 PST 2015


On Tuesday 10 February 2015 10:24:45 Bipnesh, Abhinav wrote:
> Hi All,
> 
> I was trying to read some of the environment variables from a recipe file
> using below python code
> 
> PACKAGES = "{TEST_PACKAGE}"

Problem #1 - if you are attempting to refer to the value of the
TEST_PACKAGE variable, you need ${TEST_PACKAGE} not {TEST_PACKAGE}.

> python __anonymous () {
>     packages = []
>     buildScriptVersion = os.environ['MajorVersion'] + "." +
> os.environ['MinorVersion'] buildID = os.environ['BuildID']
>     buildOffSet = os.environ['BuildOffsetNum']
>     buildNum = int(buildID) - int(buildOffSet)
>     if buildNum <= 0:
>         buildNum = 1
>     Num = os.environ['Num']
>     version = buildScriptVersion + "." + sprintNum + "." + str(buildNum)
>     packageName = "test-" + version
>     d.setVar("TEST_PACKAGE", " ".join(packages))
> }
> 
> But while running I am getting below error
> 
> 0001:def __anon_29__test_bb(d):
>      0002:    packages = []
> *** 0003:    buildScriptVersion = os.environ['MajorVersion'] + "." +
> os.environ['MinorVersion'] 0004:    buildID = os.environ['BuildID']
>      0005:    buildOffSet = os.environ['BuildOffsetNum']
>      0006:    buildNum = int(buildID) - int(buildOffSet)
>      0007:    if buildNum <= 0:
> File: '/usr/lib64/python2.7/UserDict.py', lineno: 23, function: __getitem__
>      0019:        if key in self.data:
>      0020:            return self.data[key]
>      0021:        if hasattr(self.__class__, "__missing__"):
>      0022:            return self.__class__.__missing__(self, key)
> *** 0023:        raise KeyError(key)
>      0024:    def __setitem__(self, key, item): self.data[key] = item
>      0025:    def __delitem__(self, key): del self.data[key]
>      0026:    def clear(self): self.data.clear()
>      0027:    def copy(self):
> Exception: KeyError: 'MajorVersion'
> 
> So any thoughts to fix this issue. As we need to have a package name with
> such variable which will be set in the environment at run time.

The environment available within the build is sanitised, only certain
variables are allowed through by default. There are a couple of alternatives
for working around this - whitelist the variable through, or access it via
BB_ORIGENV:

http://www.yoctoproject.org/docs/current/bitbake-user-manual/bitbake-user-manual.html#passing-information-into-the-build-task-environment

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre



More information about the yocto mailing list