<?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>9068</bug_id>
          
          <creation_ts>2016-02-05 11:48:23 +0000</creation_ts>
          <short_desc>Provide means to expand multiple variables in a string, in python functions,</short_desc>
          <delta_ts>2016-02-23 18:09:33 +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>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>9147</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>23 Feb 2016: RESOLVED/DUPLICATE</status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.1 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Igor Stoppa">igor.stoppa</reporter>
          <assigned_to name="Scott Rifenbark">srifenbark</assigned_to>
          <cc>bluelightning</cc>
    
    <cc>joshuagloe</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>srifenbark</cc>
          
          
          <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>58637</commentid>
    <comment_count>0</comment_count>
    <who name="Igor Stoppa">igor.stoppa</who>
    <bug_when>2016-02-05 11:48:23 +0000</bug_when>
    <thetext>With d.getVar(&apos;variable&apos;, expand=True) it is possible to get the full expansion of a variable.

However it&apos;s a bit inconvenient to do that, when using multiple variables.

Having something like:

expand(&quot;something1 ${Variable1} something2  ${Variable2} something3&quot;) to return

&quot;something1 somethingelse1 something2  somethingelse2 something3&quot;

would be much nicer and would avoid different implementations to pop up in recipes.

Ex. of possible implementation, still in python:

  def expand(item):
      item = str(item)
      
      while re.search(&apos;.*\$\{(.*)\}.*&apos;, item):
          match = re.search(&apos;.*\$\{(.*)\}.*&apos;, item)
          sub = d.getVar(match.group(1), expand=True)
          item = item.replace(&apos;${&apos; + match.group(1) + &apos;}&apos;, sub)
      return item

Taking this even further: provide a wrapper for executing shell commands that might use BB variables. Ex:

def run_command(cmd):
  check_call(expand(cmd).split())

These 2 enhancements would provide much more compact and readable python tasks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58639</commentid>
    <comment_count>1</comment_count>
    <who name="Igor Stoppa">igor.stoppa</who>
    <bug_when>2016-02-05 13:08:08 +0000</bug_when>
    <thetext>This feature would also open the door to the python equivalent of run_command:

def eval_command(cmd):
    eval(expand(cmd))

This doesn&apos;t look like a big improvement, but most likely some additional quoting/escaping is needed and it could be hidden here.

While eval is not particularly liked in many circles, it might make for some more concise/readable code, at least in some cases.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58897</commentid>
    <comment_count>2</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-02-11 15:40:58 +0000</bug_when>
    <thetext>We already have d.expand() which does what you describe, expand variables in a string. I do notice the manual fails to mention this however it is in common use in the codebase. We should note this in the manual, then resolve this.

Assigning to Scott to fix the manual.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59403</commentid>
    <comment_count>3</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-02-23 18:09:33 +0000</bug_when>
    <thetext>Hi, 

Paul filed a bug 9147 to deal with adding d.expand to the manual.  I have added that and Paul has reviewed and approved the change.  So the status of 9147 is RESOLVED.  

Since this bug appears to be documentation only... and it is assigned to me.  I am going to mark it off as RESOLVED/DUPLICATE.

I set the doc flag to &quot;no&quot; for this one.

If you care to see the change in the manual - see http://www.yoctoproject.org/docs/2.1/bitbake-user-manual/bitbake-user-manual.html#accessing-datastore-variables-using-python.

Scott

*** This bug has been marked as a duplicate of bug 9147 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>