Bug 10364 - Suggested documentation to clarify BitBake-style vs. regular Python functions and bb.build.exec_func()
Summary: Suggested documentation to clarify BitBake-style vs. regular Python functions...
Status: RESOLVED FIXED
Alias: None
Product: BitBake User Manual
Classification: Documentation
Component: bitbake-manual (show other bugs)
Version: 2.2
Hardware: x86 Multiple
: Undecided normal
Target Milestone: 2.2 M4
Assignee: Scott Rifenbark
QA Contact:
URL:
Whiteboard: 04 Oct 2016: RESOLVED
Depends on:
Blocks:
 
Reported: 2016-10-04 02:27 UTC by ulfalizer
Modified: 2016-10-04 19:27 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Done (doc changes complete)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ulfalizer 2016-10-04 02:27:13 UTC
Hello Scott,

BitBake-style Python functions involved some pretty deep magic for me. Here'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 'def':
  
   * 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 'dirs', 'cleandirs', and 'lockfiles' can only be
     used on BitBake-style Python functions.
  
   * BitBake-style Python functions generate a separate
     ${[T]}/run.<function-name>.<pid> script that is executed to run the
     function, and also generate a log file in ${T}/log.<function-name>.<pid> if
     they are executed as tasks.
  
     Regular Python functions execute "inline" 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("my_bitbake_style_function", 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
Comment 1 ulfalizer 2016-10-04 02:30:50 UTC
As a small nit, there's both "BitBake style" and "BitBake-style" in the manual. Maybe that could be made consistent too.

Cheers,
Ulf
Comment 2 ulfalizer 2016-10-04 02:40:36 UTC
Another small nit... change

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

to

   * Variable flags such as 'dirs', 'cleandirs', and 'lockfiles' 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
Comment 3 Scott Rifenbark 2016-10-04 17:02:55 UTC
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
Comment 4 ulfalizer 2016-10-04 17:52:38 UTC
Looks good. just a few nits:

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

 * The "linkification brackets" 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
Comment 6 ulfalizer 2016-10-04 19:24:26 UTC
Looks good to me!

Thanks,
Ulf
Comment 7 Scott Rifenbark 2016-10-04 19:27:09 UTC
Thanks, 

Setting to RESOLVED and putting the doc flag to "done."

Scott