Failure expanding variable PN

Create issue
Issue #2 resolved
Francis Giraldeau created an issue

Hello, with Yocto 2.1, it seems that the signature of function getVar() changed, hence breaking the tutorial ch04.

$ bitbake -s
ERROR: ExpansionError during parsing /data/francis/bitbakeguide/ch04/build/../meta-tutorial/recipes-tutorial/first/first_0.1.bb: Failure expanding variable PN, expression was ${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[0] or 'defaultpkgname'} which triggered exception TypeError: getVar() takes at least 3 arguments (2 given)

I added "False" as a second argument, which is for "expand", and it works correctly.

diff --git a/ch04/meta-tutorial/conf/bitbake.conf b/ch04/meta-tutorial/conf/bitbake.conf
index c2ed926..e65de03 100644
--- a/ch04/meta-tutorial/conf/bitbake.conf
+++ b/ch04/meta-tutorial/conf/bitbake.conf
@@ -40,10 +40,10 @@ OVERRIDES = "local:${MACHINE}:${TARGET_OS}:${TARGET_ARCH}"
 P = "${PN}-${PV}"
 PERSISTENT_DIR = "${TMPDIR}/cache"
 PF = "${PN}-${PV}-${PR}"
-PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[0] or 'defaultpkgname'}"
-PR = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[2] or 'r0'}"
+PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
+PR = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[2] or 'r0'}"
 PROVIDES = ""
-PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[1] or '1.0'}"
+PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[1] or '1.0'}"
 RESUMECOMMAND = ""
 RESUMECOMMAND_wget = "/usr/bin/env wget -c -t 5 --passive-ftp -P ${DL_DIR} ${URI}"
 S = "${WORKDIR}/${P}"

Comments (10)

  1. Harald Achitz repo owner

    Hi Francis,
    thanks a lot for your report!
    This is interesting. The 2.1 bitbake documentation does not mention a change in the data store API, getVar still takes 2 arguments, where the second one is defaulted to False, see bitbake 2.1 docu datastore
    So I am unsure why this is required, I will have to investigate this later today or tomorrow,
    I have to admit that until now I did not update and test the tutorial to version 2.1, but I guess I will have to do this now, so it might become weekend until I am done.

  2. Francis Giraldeau reporter

    It turns out that base.bbclass is also affected by this change

    diff --git a/ch04/meta-tutorial/classes/base.bbclass b/ch04/meta-tutorial/classes/base.bbclass
    index 0972d69..71d9ec1 100644
    --- a/ch04/meta-tutorial/classes/base.bbclass
    +++ b/ch04/meta-tutorial/classes/base.bbclass
    @@ -43,7 +43,7 @@ python do_showdata() {
            bb.data.emit_env(sys.__stdout__, d, True)
            # emit the metadata which isnt valid shell
            for e in bb.data.keys(d):
    -               if d.getVarFlag(e, 'python'):
    +               if d.getVarFlag(e, 'python', False):
                            bb.plain("\npython %s () {\n%s}" % (e, d.getVar(e, True)))
     }
    
    @@ -52,7 +52,7 @@ do_listtasks[nostamp] = "1"
     python do_listtasks() {
            import sys
            for e in bb.data.keys(d):
    -               if d.getVarFlag(e, 'task'):
    +               if d.getVarFlag(e, 'task', False):
                            bb.plain("%s" % e)
     }
    
  3. Harald Achitz repo owner

    Hi Francis,
    are you using possible python3, its maybe default on the latest Ubuntu.
    python3 is not supported by Yocto, see the Yocto documentation required-git-tar-and-python-versions.
    I am just asking because the d.getVarFlag, like the d.getVar mentioned earlier, does also default the expand flag, so it seems a bit strange that you have to provide it explicit.

  4. Francis Giraldeau reporter

    Sorry, I did not refreshed the page before posting the second comment ;-)

    I saw that the bitbake documentation was updated:

    69b69193 bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml (Richard Purdie   2015-06-18 15:14:19 +0100 309)      PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
    

    Ref: http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml#n330

    Could it be possible the python code does not define the default value for the expand argument?

    bitbake/lib/bb/data_smart.py:
    
        def getVar(self, var, expand, noweakdefault=False, parsing=False):
            return self.getVarFlag(var, "_content", expand, noweakdefault, parsing)
    

    Thanks!

  5. Francis Giraldeau reporter

    I do have both Python 2 and 3 on my system, but the default one is Python 2.

    $ python --version
    Python 2.7.10
    
  6. Harald Achitz repo owner

    Ok, thanks for the info Francis!
    I will have to check this later on my build box with the latest yocto and bitbake version.

  7. Harald Achitz repo owner

    Hi Francis

    I have a problem to reproduce this using the latest yocto download YP Core - Krogoth 2.1

    setup the environment as written in chapter 3 ,

      export bitbake_root_dir=~/tmp/yocto/poky-krogoth-15.0.0/bitbake
      export PATH=$bitbake_root_dir/bin:$PATH
      export PYTHONPATH=$bitbake_root_dir/lib:$PYHTONPATH
    

    bitbake is this,

    [a4z@x230 build]$ which bitbake
    ~/tmp/yocto/poky-krogoth-15.0.0/bitbake/bin/bitbake
    

    I am cloning the bbTutor repository, change into the ch04 directory,
    create the build/conf/bblayers.conf as written in the tutorial

    [a4z@x230 build]$ pwd
    /home/a4z/tmp/yocto/bbTutor/ch04/build
    [a4z@x230 build]$ tree ../
    ../
    ├── build
    │   └── conf
    │       └── bblayers.conf
    └── meta-tutorial
        ├── classes
        │   └── base.bbclass
        └── conf
            ├── bitbake.conf
            └── layer.conf
    
    5 directories, 4 files
    [a4z@x230 build]$ bitbake --version
    BitBake Build Tool Core version 1.30.0
    [a4z@x230 build]$ bitbake -vvvD
    Nothing to do.  Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.
    DEBUG: Removed the following variables from the environment: HISTTIMEFORMAT, LC_NUMERIC, HISTFILE, IMSETTINGS_MODULE, GNOME_DESKTOP_SESSION_ID, LC_MEASUREMENT, LESSOPEN, LC_PAPER, QT_IM_MODULE, XDG_SEAT, XDG_VTNR, WINDOWPATH, LANG, XAUTHORITY, SESSION_MANAGER, LC_MONETARY, HISTSIZE, RBENV_SHELL, WINDOWID, IMSETTINGS_INTEGRATE_DESKTOP, GPG_AGENT_INFO, HISTFILESIZE, PYTHONUSERBASE, USERNAME, XDG_SESSION_DESKTOP, XDG_RUNTIME_DIR, PYTHONPATH, SSH_AUTH_SOCK, VTE_VERSION, GDMSESSION, XMODIFIERS, XDG_MENU_PREFIX, XDG_CURRENT_DESKTOP, XDG_SESSION_ID, DBUS_SESSION_BUS_ADDRESS, _, DESKTOP_SESSION, DISPLAY, OLDPWD, HOSTNAME, GDM_LANG, HISTCONTROL, SHLVL, MAIL, LC_TIME, LS_COLORS
    DEBUG: Inheriting /home/a4z/tmp/yocto/bbTutor/ch04/meta-tutorial/classes/base.bbclass (from configuration INHERITs:0)
    DEBUG: Clearing SRCREV cache due to cache policy of: clear
    DEBUG: Using cache in '/home/a4z/tmp/yocto/bbTutor/ch04/build/tmp/cache/local_file_checksum_cache.dat'
    DEBUG: Using cache in '/home/a4z/tmp/yocto/bbTutor/ch04/build/tmp/cache/bb_codeparser.dat'
    DEBUG: Features set [3] (was [3])
    DEBUG: Base environment change, triggering reparse
    DEBUG: Inheriting /home/a4z/tmp/yocto/bbTutor/ch04/meta-tutorial/classes/base.bbclass (from configuration INHERITs:0)
    DEBUG: Clearing SRCREV cache due to cache policy of: clear
    DEBUG: Using cache in '/home/a4z/tmp/yocto/bbTutor/ch04/build/tmp/cache/local_file_checksum_cache.dat'
    DEBUG: Using cache in '/home/a4z/tmp/yocto/bbTutor/ch04/build/tmp/cache/bb_codeparser.dat'
    [a4z@x230 build]$ bitbake -s
    ERROR: no recipe files to build, check your BBPATH and BBFILES?
    
    Summary: There was 1 ERROR message shown, returning a non-zero exit code.
    

    even the output of bitbake -s is OK, even if that's at this point not part of the tutorial, but this error is expected.

    I am running the stuff on a RHEL 7 with Python 2.7.5

    is it possible that your PYTHONPATH was set incorrect, can you give me some more info that helps me to reproduce the problem?

  8. Harald Achitz repo owner

    fixed in in the last commit

    also removed cache files in earlier commits that seemed to be by mistake in the git repo which made this problem not appear in my local chapter 4 example.

    Thanks Francis Giraldeau and some Anonymous person (#3) for reporting the problem.

  9. Harald Achitz repo owner

    I hope all occurrences are updated in the samples, if you find further problems with this issue, please reopen or file a new one. Thanks!

  10. Log in to comment