Bug 10296

Summary: Suggested documentation on using overrides with functions
Product: [Documentation] BitBake User Manual Reporter: ulfalizer
Component: bitbake-manualAssignee: Scott Rifenbark <srifenbark>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: bluelightning, sgw, srifenbark
Version: 2.2   
Target Milestone: 2.2 M4   
Hardware: x86   
OS: Multiple   
Whiteboard: 22 Sept 2016: RESOLVED
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Done (doc changes complete)

Description ulfalizer 2016-09-17 03:15:11 UTC
Hello,

There doesn't seem to be any documentation that explicitly mentions that you
can append and prepend to functions. I suggest the following changes:

Add this to the end of '3.1.8. Appending and Prepending (Override Style
Syntax)':

  It is also possible to append and prepend to shell functions and
  BitBake-style Python functions. See
  [3.5.1. Shell Functions] and [3.5.2. BitBake Style Python Functions] for
  examples of how to do this.


Add this to the end of '3.5.1. Shell Functions':

  Overrides and override-style operators like "_append" and "_prepend" can also
  be applied to shell functions. Most commonly, this would be used in a
  .bbappend to modify functions in the main recipe. It can also be used to
  modify functions inherited from classes.
  
  As an example, consider the following snippet:

    do_foo() {
        bbplain first
        fn
    }
    
    fn_prepend() {
        bbplain second
    }
    
    fn() {
        bbplain third
    }
    
    do_foo_append() {
        bbplain fourth
    }

  The output from do_foo would be the following:

    recipename do_foo: first
    recipename do_foo: second
    recipename do_foo: third
    recipename do_foo: fourth

  Note {
  Overrides and override-style operators can be applied to any shell function,
  not just
  [tasks](http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#tasks).
  }

  'bitbake -e recipename' can be used to view the final assembled function
  after all overrides have been applied.


Add this to the end of '3.5.2. BitBake Style Python Functions':

  Like with shell functions, overrides and override-style operators can also be
  applied to BitBake-style Python functions. As an example, consider the
  following snippet:

    python do_foo_prepend() {
        bb.plain("first")
    }
    
    python do_foo() {
        bb.plain("second")
    }
    
    python do_foo_append() {
        bb.plain("third")
    }

  The output from do_foo would be the following:

    recipename do_foo: first
    recipename do_foo: second
    recipename do_foo: third

  'bitbake -e recipename' can be used to view the final assembled function
  after all overrides have been applied.


Cheers,
Ulf
Comment 1 Scott Rifenbark 2016-09-21 22:35:11 UTC
Ulf, 

See http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#appending-and-prepending-override-style-syntax for the change to the "Appending and Prepending (Override Style Syntax)" section.

See http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#shell-functions for the addition to the "Shell Functions" section.

See http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#bitbake-style-python-functions for the change to the "BitBake Style Python Functions" section.

thanks, 
Scott
Comment 2 ulfalizer 2016-09-22 05:17:45 UTC
Maybe

  Running do_foo prints the following

sounds a bit better than

  The output from do_foo results in the following

(in both places where it appears).

Looks good to me otherwise.

Thanks,
Ulf
Comment 3 Scott Rifenbark 2016-09-22 23:28:43 UTC
Got it. 

See http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#shell-functions and http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#bitbake-style-python-functions.

I am going to set the bug to RESOLVED and put the doc flag into "done."

Thanks,
Scott