<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>8849</bug_id>
          
          <creation_ts>2015-12-22 10:44:31 +0000</creation_ts>
          <short_desc>do_rootfs error reporting of Python exceptions and variable expansion</short_desc>
          <delta_ts>2016-03-07 14:11:49 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>2.1</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.1 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Patrick Ohly">patrick.ohly</reporter>
          <assigned_to name="Markus Lehtonen">markus.lehtonen</assigned_to>
          <cc>cristina-danielax.agurida</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>richard.purdie</cc>
          
          <qa_contact name="Cristina Agurida">cristina-danielax.agurida</qa_contact>
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>57424</commentid>
    <comment_count>0</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2015-12-22 10:44:31 +0000</bug_when>
    <thetext>This issue is about two separate problems, triggered the same way, so I am only reporting this once.

Steps to reproduce:
* use current Poky master
* set up a normal build with oe-init-build-env
* add to local.conf one line:

INITRD = &quot;${@&apos;${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE}-${MACHINE}.cpio.gz&apos; if d.getVar(&apos;INITRD_IMAGE&apos;, True) else &apos;&apos;}&quot;

* bitbake core-image-minimal

Expected result:
* INITRD should be empty and building the image should succeed.

Actual result:
* Creating the image fails without any useful error description:

| NOTE: ###### Generate images #######
| NOTE: Executing mklibs_optimize_image ...
| DEBUG: Executing shell function mklibs_optimize_image
| DEBUG: Shell function mklibs_optimize_image finished
| NOTE: Executing prelink_image ...
| DEBUG: Executing shell function prelink_image
| Size before prelinking 6860.
| Size after prelinking 6948.
| DEBUG: Shell function prelink_image finished
| NOTE: The image creation groups are: [[&apos;ext4&apos;, &apos;tar&apos;]]
| DEBUG: Python function do_rootfs finished
| ERROR: Function failed: do_rootfs
ERROR: Task 7 (/work/poky/meta/recipes-core/images/core-image-minimal.bb, do_rootfs) failed with exit code &apos;1&apos;
NOTE: Tasks Summary: Attempted 2004 tasks of which 2003 didn&apos;t need to be rerun and 1 failed.

* There&apos;s a parse error for INITRD:

$ bitbake -e core-image-minimal | grep INITRD
...
# expansion of INITRD threw ExpansionError: Failure expanding variable INITRD, expression was ${@&apos;/tmp/test/tmp/deploy/images/qemux86/${INITRD_IMAGE}-qemux86.cpio.gz&apos; if d.getVar(&apos;INITRD_IMAGE&apos;, True) else &apos;&apos;} which triggered exception SyntaxError: EOL while scanning string literal (INITRD, line 1)

The parse error is also what breaks do_rootfs because INITRD gets expanded when writing the wic environment file.

-----------------------------------

My expectation regarding the INITRD expansion is that the expression above is evaluated as Python as-is (with ${INITRD_IMAGE} inside the first string); it is valid Python code.

I ran into this while working on a image creation class where INITRD must be set depending on the value of INITRD_IMAGE.

I did something similar in the OE-core image-vm.bbclass, but there I had set a default value INITRD_IMAGE and thus did not run into the problem. I&apos;m just not sure anymore whether setting a default for INITRD_IMAGE in an image class which might not even be in use is the right thing to do, so now I tried checking for a non-zero value with d.getVar().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57434</commentid>
    <comment_count>1</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2015-12-22 16:54:04 +0000</bug_when>
    <thetext>Another expected result:
* If there is an error like this, it should get logged.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58270</commentid>
    <comment_count>2</comment_count>
    <who name="Markus Lehtonen">markus.lehtonen</who>
    <bug_when>2016-01-27 13:35:20 +0000</bug_when>
    <thetext>I&apos;m not able to reproduce this. Neither on poky (master) nor oe-core (master). Do you still see this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58272</commentid>
    <comment_count>3</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-01-27 13:57:41 +0000</bug_when>
    <thetext>bitbake commit d80d39e73223a50fda0090784303d2c57167bb4c avoids the SyntaxError.

To reproduce the incomplete error reporting during a build, revert the commit above and try the original steps.

It does not make the INITRD expansion work as expected, though, because it simply stops expanding. RP and I agreed that this would require more intrusive changes to bitbake&apos;s data_smart.py; there&apos;s no bug open for it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58490</commentid>
    <comment_count>4</comment_count>
    <who name="Markus Lehtonen">markus.lehtonen</who>
    <bug_when>2016-02-03 11:39:53 +0000</bug_when>
    <thetext>I tried reverting d80d39e73223a50fda0090784303d2c57167bb4c. Bitbake now seems to correctly exit with an error.

With the steps you described below, I get:

~/yocto/poky/build $ bitbake core-image-minimal
WARNING: Exception during build_dependencies for INITRD                                                                                     | ETA:  00:00:19
WARNING: Error during finalise of /home/marquiz/yocto/poky/meta/recipes-core/images/core-image-minimal-initramfs.bb
WARNING: Exception during build_dependencies for INITRD
WARNING: Error during finalise of /home/marquiz/yocto/poky/meta/recipes-core/images/core-image-minimal-mtdutils.bb
WARNING: Exception during build_dependencies for INITRD
WARNING: Error during finalise of /home/marquiz/yocto/poky/meta/recipes-core/images/core-image-base.bb
ERROR: ExpansionError during parsing /home/marquiz/yocto/poky/meta/recipes-core/images/core-image-minimal-initramfs.bb: Failure expanding variable INITRD, expression was ${@&apos;/home/marquiz/yocto/poky/build-8849.2/tmp/deploy/images/qemux86/${INITRD_IMAGE}-qemux86.cpio.gz&apos; if d.getVar(&apos;INITRD_IMAGE&apos;, True) else &apos;&apos;} which triggered exception SyntaxError: EOL while scanning string literal (INITRD, line 1)
WARNING: Exception during build_dependencies for INITRD
WARNING: Error during finalise of /home/marquiz/yocto/poky/meta/recipes-core/images/core-image-minimal-dev.bb
WARNING: Exception during build_dependencies for INITRD
WARNING: Error during finalise of /home/marquiz/yocto/poky/meta/recipes-core/images/core-image-minimal.bb

Summary: There were 10 WARNING messages shown.
Summary: There was 1 ERROR message shown, returning a non-zero exit code.



I submitted a patchset to fix the problem with INITRD variable parsing:
http://lists.openembedded.org/pipermail/bitbake-devel/2016-February/007005.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59063</commentid>
    <comment_count>5</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-02-16 08:42:14 +0000</bug_when>
    <thetext>I think the current bitbake behavior of not expanding this particular INITRD value is acceptable. It is more obvious than the previous EOL syntax error.

The error reporting also seems to be fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59065</commentid>
    <comment_count>6</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-02-16 08:53:52 +0000</bug_when>
    <thetext>Bitbake change d80d39e73223a50fda0090784303d2c57167bb4c  handles the first part of the issue here, the expansion errors no longer raise exceptions, the unexpanded value is just returned which is in keeping with the way the rest of bitbake works.

With the change to non-expanded python functions, the expression in question can be used as a function (anonyous or otherwise) and its only the inline version which would be more potentially problematic.

Fixing the inline python expansion would mean significant changes to the parsing code to properly handle all the different kinds of nested expressions and would come with a performance penalty. After discussion with Patrick, we both feel this wouldn&apos;t be worthwhile at this point.

The one piece I finally worried about was errors in the wicenv function not propagating.  I tested this with:

def foobar(d):
    bb.warn(&quot;Here 1&quot;)
    if d.getVar(&quot;BB_CURRENTTASK&quot;, True) == &quot;rootfs_wicenv&quot;:
        bb.warn(&quot;Here 2&quot;)
        raise bb.build.FuncFailed
    return &quot;&quot;

INITRD = &quot;${@foobar(d)}&quot;

which correctly fails during do_rootfs_wicenv, I suspect the recent task re-org there has helped improve the robustness of the error handling paths. I therefore believe this issue can be marked resolved.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59066</commentid>
    <comment_count>7</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-02-16 08:54:13 +0000</bug_when>
    <thetext>Resolved as fixed as per comments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59757</commentid>
    <comment_count>8</comment_count>
    <who name="Cristina Agurida">cristina-danielax.agurida</who>
    <bug_when>2016-03-07 14:11:49 +0000</bug_when>
    <thetext>Verified with master: bd3a1d5bddeab2b327055a61e85423303327fc09</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>