<?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>10364</bug_id>
          
          <creation_ts>2016-10-04 02:27:13 +0000</creation_ts>
          <short_desc>Suggested documentation to clarify BitBake-style vs. regular Python functions and bb.build.exec_func()</short_desc>
          <delta_ts>2016-10-04 19:27:09 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>9</classification_id>
          <classification>Documentation</classification>
          <product>BitBake User Manual</product>
          <component>bitbake-manual</component>
          <version>2.2</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>04 Oct 2016: RESOLVED</status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.2 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>ulfalizer</reporter>
          <assigned_to name="Scott Rifenbark">srifenbark</assigned_to>
          <cc>bluelightning</cc>
    
    <cc>kergoth</cc>
    
    <cc>ross.burton</cc>
    
    <cc>sgw</cc>
    
    <cc>srifenbark</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Done (doc changes complete)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>66848</commentid>
    <comment_count>0</comment_count>
    <who name="">ulfalizer</who>
    <bug_when>2016-10-04 02:27:13 +0000</bug_when>
    <thetext>Hello Scott,

BitBake-style Python functions involved some pretty deep magic for me. Here&apos;s a
suggested new section to explain how they differ from regular Python functions.
It also demystifies bb.build.exec_func().

  3.5.4. Bitbake-Style Python Functions Versus Python Functions
  
  Listed below are some important differences between BitBake-style Python
  function and regular Python functions defined with &apos;def&apos;:
  
   * Only BitBake-style Python functions can be [tasks](3.6 Tasks).
   
   * Overrides and override-style operators can only be applied to
     BitBake-style Python functions.
  
   * Only regular Python functions can take arguments and return values.
  
   * Variable flags such as &apos;dirs&apos;, &apos;cleandirs&apos;, and &apos;lockfiles&apos; can only be
     used on BitBake-style Python functions.
  
   * BitBake-style Python functions generate a separate
     ${[T]}/run.&lt;function-name&gt;.&lt;pid&gt; script that is executed to run the
     function, and also generate a log file in ${T}/log.&lt;function-name&gt;.&lt;pid&gt; if
     they are executed as tasks.
  
     Regular Python functions execute &quot;inline&quot; and do not generate any files in
     ${T}.
  
   * Regular Python functions are called with the usual Python syntax.
     BitBake-style Python functions are usually tasks and are called directly by
     BitBake, but can also be called manually from Python code by using the
     bb.build.exec_func() function. Here is an example:
  
       bb.build.exec_func(&quot;my_bitbake_style_function&quot;, d)
  
     Note {
     bb.build.exec_func() can also be used to run shell functions from Python
     code. If you want to run a shell function before a Python function within
     the same task, you can use a parent Python function that calls both
     functions in turn with bb.build.exec_func().
     }
  
     To detect errors from functions executed with bb.build.exec_func(), you
     can catch the bb.build.FuncFailed exception. 
  
     Note {
     Functions in metadata (recipes and classes) should not themselves raise
     bb.build.FuncFailed. Rather, bb.build.FuncFailed should be viewed as a
     general indicator that the called function failed by raising an exception.
     For example, an exception raised by bb.fatal() will be caught inside
     bb.build.exec_func(), and a bb.build.FuncFailed will be raised in
     response.
     }
  
  Due to their simplicity, regular Python functions should be preferred over
  BitBake-style Python functions unless you need a feature specific to
  BitBake-style Python functions.
  
  Regular Python functions in metadata are a more recent invention than
  BitBake-style Python functions, and older code tends to use
  bb.build.exec_func() more often.


Cheers,
Ulf</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66849</commentid>
    <comment_count>1</comment_count>
    <who name="">ulfalizer</who>
    <bug_when>2016-10-04 02:30:50 +0000</bug_when>
    <thetext>As a small nit, there&apos;s both &quot;BitBake style&quot; and &quot;BitBake-style&quot; in the manual. Maybe that could be made consistent too.

Cheers,
Ulf</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66850</commentid>
    <comment_count>2</comment_count>
    <who name="">ulfalizer</who>
    <bug_when>2016-10-04 02:40:36 +0000</bug_when>
    <thetext>Another small nit... change

   * Variable flags such as &apos;dirs&apos;, &apos;cleandirs&apos;, and &apos;lockfiles&apos; can only be
     used on BitBake-style Python functions.

to

   * Variable flags such as &apos;dirs&apos;, &apos;cleandirs&apos;, and &apos;lockfiles&apos; can be used
     on BitBake-style Python functions, but not on regular Python functions.

That might make it clearer that they can be used on all BitBake-style Python
functions and not just on tasks.


Cheers,
Ulf</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66875</commentid>
    <comment_count>3</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-10-04 17:02:55 +0000</bug_when>
    <thetext>Ulf, 

See http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#bitbake-style-python-functions-versus-python-functions for the new section.

Regarding the BitBake Style / BitBake-Style controversy.... I made everything BitBake-Style.  There were just a few occurrences.  

Check things out.. 

thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66881</commentid>
    <comment_count>4</comment_count>
    <who name="">ulfalizer</who>
    <bug_when>2016-10-04 17:52:38 +0000</bug_when>
    <thetext>Looks good. just a few nits:

 * Maybe &quot;variable flags&quot; could be linkified in &quot;variable flags such as [dirs],
   [cleandirs], ...&quot; Seems a bit weird to start a sentence with a link, but
   whatever. :)

 * The &quot;linkification brackets&quot; accidentally got left in in ${[T]}/... in two
   places. Should be ${T}/..., and the first one could be linkified.

 * Maybe the first note makes things sound a bit more complicated than they
   are. Could we do this version instead?
     
     bb.build.exec_func() can also be used to run shell functions from Python
     code. If you want to run a shell function before a Python function within
     the same task, then you can use a parent helper Python function that
     starts by running the shell function with bb.build.exec_func() and then
     runs the Python code.

 * Maybe the final two paragraphs could be merged into one.

Thanks,
Ulf</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66884</commentid>
    <comment_count>5</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-10-04 19:21:26 +0000</bug_when>
    <thetext>Ulf, 

See http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#bitbake-style-python-functions-versus-python-functions for the changes.

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66885</commentid>
    <comment_count>6</comment_count>
    <who name="">ulfalizer</who>
    <bug_when>2016-10-04 19:24:26 +0000</bug_when>
    <thetext>Looks good to me!

Thanks,
Ulf</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66887</commentid>
    <comment_count>7</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-10-04 19:27:09 +0000</bug_when>
    <thetext>Thanks, 

Setting to RESOLVED and putting the doc flag to &quot;done.&quot;

Scott</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>