<?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>10668</bug_id>
          
          <creation_ts>2016-11-15 20:15:34 +0000</creation_ts>
          <short_desc>shell parser fails when using &amp; for background processes</short_desc>
          <delta_ts>2017-11-28 17:02:00 +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>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>https://patchwork.openembedded.org/series/3987/</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.3 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Patrick Ohly">patrick.ohly</reporter>
          <assigned_to name="Patrick Ohly">patrick.ohly</assigned_to>
          <cc>jose.perez.carranza</cc>
    
    <cc>oscarx.lopez.arandas</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>ross.burton</cc>
          
          <qa_contact name="oscar lopez arandas">oscarx.lopez.arandas</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>68335</commentid>
    <comment_count>0</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-11-15 20:15:34 +0000</bug_when>
    <thetext>I was trying to do some simple parallel processing in a shell function when I noticed that codeparser.py has a problem with parsing the &amp; 

To reproduce with poky rev 9b1bd29ea99aa:

diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index 3cff08e..c5545f5 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -53,7 +53,7 @@ if test &quot;x`echo $GROUPADD_PARAM | tr -d &apos;[:space:]&apos;`&quot; != &quot;x&quot;; then
        opts=`echo &quot;$GROUPADD_PARAM&quot; | cut -d &apos;;&apos; -f 1 | sed -e &apos;s#[ \t]*$##&apos;`
        remaining=`echo &quot;$GROUPADD_PARAM&quot; | cut -d &apos;;&apos; -f 2- | sed -e &apos;s#[ \t]*$##&apos;`
        while test &quot;x$opts&quot; != &quot;x&quot;; do
-               perform_groupadd &quot;$SYSROOT&quot; &quot;$OPT $opts&quot;
+               perform_groupadd &quot;$SYSROOT&quot; &quot;$OPT $opts&quot; &amp; wait $!
                if test &quot;x$opts&quot; = &quot;x$remaining&quot;; then
                        break
                fi

Set up a build dir, run bitbake -g core-image-minimal =&gt;

WARNING: /work/poky/meta/recipes-support/user-creation/xuser-account_0.1.bb: Exception during build_dependencies for useradd_preinst
WARNING: /work/poky/meta/recipes-support/user-creation/xuser-account_0.1.bb: Error during finalise of /work/poky/meta/recipes-support/user-creation/xuser-account_0.1.bb
ERROR: Unable to parse /work/poky/meta/recipes-support/user-creation/xuser-account_0.1.bb
Traceback (most recent call last):
  File &quot;/work/poky/bitbake/lib/bb/codeparser.py&quot;, line 400, in ShellParser.process_tokens(tokens=[(&apos;if_clause&apos;, &lt;bb.pysh.pyshyacc.IfCond object at 0x7fb480963390&gt;)]):
                 if more_tokens:
    &gt;                self.process_tokens(more_tokens)
     
  File &quot;/work/poky/bitbake/lib/bb/codeparser.py&quot;, line 400, in ShellParser.process_tokens(tokens=&lt;itertools.chain object at 0x7fb480949278&gt;):
                 if more_tokens:
    &gt;                self.process_tokens(more_tokens)
     
  File &quot;/work/poky/bitbake/lib/bb/codeparser.py&quot;, line 400, in ShellParser.process_tokens(tokens=[(&apos;while_clause&apos;, &lt;bb.pysh.pyshyacc.WhileLoop object at 0x7fb480949518&gt;)]):
                 if more_tokens:
    &gt;                self.process_tokens(more_tokens)
     
  File &quot;/work/poky/bitbake/lib/bb/codeparser.py&quot;, line 400, in ShellParser.process_tokens(tokens=&lt;itertools.chain object at 0x7fb480446668&gt;):
                 if more_tokens:
    &gt;                self.process_tokens(more_tokens)
     
  File &quot;/work/poky/bitbake/lib/bb/codeparser.py&quot;, line 393, in ShellParser.process_tokens(tokens=[[(&apos;pipeline&apos;, &lt;bb.pysh.pyshyacc.Pipeline object at 0x7fb480949c88&gt;)]]):
             for token in tokens:
    &gt;            name, value = token
                 try:
ValueError: need more than 1 value to unpack


&quot;token&quot; in this case happened to be a list containing a tuple with the two expected values. Here&apos;s a crude patch which avoids the problem:

diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py
index 25938d6..41484ec 100644
--- a/bitbake/lib/bb/codeparser.py
+++ b/bitbake/lib/bb/codeparser.py
@@ -390,7 +390,14 @@ class ShellParser():
         }
 
         for token in tokens:
-            name, value = token
+            try:
+                name, value = token
+            except ValueError:
+                if isinstance(token, list) and len(token) == 1:
+                    bb.warn(&apos;Unexpected token (need list or tuple with two entries): %s&apos; % token)
+                    name, value = token[0]
+                else:
+                    bb.fatal(&apos;Cannot split %s into name and value (need list or tuple with two entries)&apos; % token)
             try:
                 more_tokens, words = token_handlers[name](value)
             except KeyError:

But to me that looks like a workaround. The root cause is probably in the code which generated the token(s).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68355</commentid>
    <comment_count>1</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-11-16 09:06:39 +0000</bug_when>
    <thetext>Handling a shell command like
 echo foo | sed -u &apos;s/^/bar: /&apos; &amp; wait $!
required a slightly more complex workaround. In that case, the offending token is a list of three tuples.

Here&apos;s the updated workaround which handles that. Changing indention makes it fairly large. The basic idea is that if a token is a list, process_token_list will be called recursively for the members of that list.

diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py
index 41484ec..8673b77 100644
--- a/bitbake/lib/bb/codeparser.py
+++ b/bitbake/lib/bb/codeparser.py
@@ -389,25 +389,24 @@ class ShellParser():
             &quot;case_clause&quot;: case_clause,
         }
 
-        for token in tokens:
-            try:
+        def process_token_list(tokens):
+            for token in tokens:
+                if isinstance(token, list):
+                    process_token_list(token)
+                    continue
                 name, value = token
-            except ValueError:
-                if isinstance(token, list) and len(token) == 1:
-                    bb.warn(&apos;Unexpected token (need list or tuple with two entries): %s&apos; % token)
-                    name, value = token[0]
-                else:
-                    bb.fatal(&apos;Cannot split %s into name and value (need list or tuple with two entries)&apos; % token)
-            try:
-                more_tokens, words = token_handlers[name](value)
-            except KeyError:
-                raise NotImplementedError(&quot;Unsupported token type &quot; + name)
+                try:
+                    more_tokens, words = token_handlers[name](value)
+                except KeyError:
+                    raise NotImplementedError(&quot;Unsupported token type &quot; + name)
+
+                if more_tokens:
+                    self.process_tokens(more_tokens)
 
-            if more_tokens:
-                self.process_tokens(more_tokens)
+                if words:
+                    self.process_words(words)
 
-            if words:
-                self.process_words(words)
+        process_token_list(tokens)
 
     def process_words(self, words):
         &quot;&quot;&quot;Process a set of &apos;words&apos; in pyshyacc parlance, which includes</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68416</commentid>
    <comment_count>2</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-11-17 16:56:23 +0000</bug_when>
    <thetext>I&apos;ll post my preliminary patch on the bitbake mailing list and ask for help there.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68906</commentid>
    <comment_count>3</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2016-12-07 16:55:40 +0000</bug_when>
    <thetext>Merged in bitbake d18a74de9ac75ba32f84c40620ca9d47c1ef96a3.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78373</commentid>
    <comment_count>4</comment_count>
    <who name="oscar lopez arandas">oscarx.lopez.arandas</who>
    <bug_when>2017-11-28 17:02:00 +0000</bug_when>
    <thetext>to reproduce with poky rev 2.3.1 rc2 6bd890d9e011014cf323e61267f8b256949d44aa
the issue this resolved.

Set up a build dir, run bitbake -g core-image-minimal  =&gt;
 
oscar@oscar:~/quemux/build$ bitbake -g core-image-minimal
Parsing recipes: 100% |######################################################################################################################| Time: 0:00:25
Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 48 skipped, 0 masked, 0 errors.
NOTE: There are 5 recipes to be removed from sysroot x86_64, removing...
NOTE: There are 1 recipes to be removed from sysroot allarch, removing...
NOTE: There are 5 recipes to be removed from sysroot i586, removing...
NOTE: There are 7 recipes to be removed from sysroot qemux86, removing...
NOTE: Resolving any missing task queue dependencies
NOTE: PN build list saved to &apos;pn-buildlist&apos;
NOTE: Task dependencies saved to &apos;task-depends.dot&apos;
NOTE: Flatened recipe dependencies saved to &apos;recipe-depends.dot&apos;
oscar@oscar:~/quemux/build$</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>