Search code examples
pythonlinuxbashyocto

Variable expansion in bitbake recipes


folks.

I've been studying yocto building process and I noticed the usage of the following structure:

PN = "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"

I know that ${} means variable expansion and grep command showed that the function "vars_from_file" is located at bitbake/lib/bb/parse/__init__.py.

I would like to understand how this variable expansion works, so I explored bitbake files and found out that:

  • oe-init-build-env calls oe-buildenv-internal, and the last one sets PYTHONPATH to bitbake/lib.

  • I'm infering that bitbake uses PYTHONPATH to search for the function vars_from_file

What I have not understood are:

  • the meaning of the symbol "@" in the variable expansion;
  • if bitbake uses PYTHONPATH to search for the function, why did not pass the absolute path ${@bb.parse.__init__.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'} instead of "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
  • Is this type of variable expansion applied only in bitbake?. I searched in gnu website, and there is not the application of "@" in the beginning of the structures.

Can someone help me understand them?


Solution

  • The @ symbol, is used bit bitbake for inline python variable expansion, and it basically states that you'd be calling a function and expanding its result, usually assigning it to a variable, in your case:

    PN = "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
    

    Its assigning to PN (package name) the result of the function vars_from_file coming from the bitbake python module parse, located at bitbake/lib/bb/parse/

    Like any other Python module, it automatically loads init.py and has access to those functions when imported.

    Whats special about these functions is that they've got access to bitbake's data dictionary, called "d".

    AFAIC this IS specific to bitbake.