Bug 9985 - Suggested clarification and motivation for the override-style operators
Summary: Suggested clarification and motivation for the override-style operators
Status: RESOLVED FIXED
Alias: None
Product: BitBake User Manual
Classification: Documentation
Component: bitbake-manual (show other bugs)
Version: 2.2
Hardware: x86 Multiple
: Medium normal
Target Milestone: 2.2 M3
Assignee: Scott Rifenbark
QA Contact:
URL:
Whiteboard: 01 August 2016: IN PROGRESS REVIEW
Depends on:
Blocks:
 
Reported: 2016-07-20 11:14 UTC by ulfalizer
Modified: 2016-08-01 22:31 UTC (History)
3 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-07-20 11:14:51 UTC
Hello,

I suspect the override-style operators (_append, _prepend, _remove) would be
much easier to understand if some motivation was given. The existing
descriptions are also vague in places.

I suggest the following changes:


Add to the end of '3.1.9. Removal (Override Style Syntax)':

  Like _append and _prepend, _remove is deferred until after parsing completes.


Add a new section '3.1.10 Motivation behind the override-style operations':

  An advantage of the override-style operations _append, _prepend, and _remove
  (compared to e.g. += and =+) is that they provide "guaranteed" operations.
  For example, consider a class foo.bbclass that needs to add the value "val"
  to the variable FOO, and a recipe that uses foo.bbclass as follows:
  
    inherit foo
  
    FOO = "initial"
  
  If foo.bbclass uses the '+=' operator, as follows, then the final value of
  FOO will be "initial", which is not what we want:
  
    FOO += "val"
  
  If on the other hand foo.bbclass uses the _append operator, as follows, then
  the final value of FOO will be "initial val", as intended:
  
    FOO_append = " val"
  
  Note {
  It is never necessary to use += together with _append. The following sequence
  of assignments will append "barbaz" to FOO:
  
    FOO_append = "bar"
    FOO_append = "baz"
  
  The only effect of changing the second assignment to
  
    FOO_append += "baz"
  
  is to add a space before "baz" in the appended value (due to how the +=
  operator works).
  }
  
  Another advantage of the override-style operations is that they can be
  combined with other overrides, as described in
  [3.2. Conditional Syntax (Overrides)].


In '3.2.3. Examples', change

  OVERRIDES = "foo"
  A = "Y"
  A_foo_append = "Z"
  A_foo_append += "X"

to

  OVERRIDES = "foo"
  A = "Y"
  A_foo_append = "Z"
  A_foo_append = "X"

and change

  ...leaving the variable set to "Z X"

to
  
  ...leaving the variable set to "ZX"

This avoids tricking people into thinking += is necessary when using _append. I
tested it out to make sure it was correct.

Cheers,
Ulf
Comment 2 ulfalizer 2016-07-21 18:10:54 UTC
A few nits, otherwise fine:

 - "...changing the second assignment in the previous example..." would be clearer as "...changing the second assignment in the previous example to use ':='..."

 - There's an ending parenthesis missing in "(due to how the '+=' operator works."

 - The following also needs to say "ZX" rather than "Z X". I missed that when I first went through it:

  Finally, applying the override for "foo" results in the conditional
  variable A becoming "Z X" (i.e. A is replaced with A_foo).

Thanks
Comment 3 Scott Rifenbark 2016-07-21 18:26:27 UTC
Here are the changes: 

 * http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#override-style-operation-advantages

 * http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#variable-interaction-worked-examples

I wondered about the second one.  I almost went ahead and changed it but figured if it was wrong you would catch it. 

Scott
Comment 4 ulfalizer 2016-07-21 18:29:30 UTC
You put too much trust in me. ;)

Looks good to me now.

Thanks.
Comment 5 Scott Rifenbark 2016-07-21 18:31:01 UTC
Thanks - closing out.
Comment 6 ulfalizer 2016-07-30 20:11:21 UTC
Ops... I made a typo:

  ...example to use ":=" would be to add...

should be

  ...example to use "+=" would be to add...
Comment 7 Scott Rifenbark 2016-08-01 18:56:39 UTC
Ulf, 

See the note in http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#override-style-operation-advantages for the fix.  I should have realized that had to change as well. 

Scott
Comment 8 ulfalizer 2016-08-01 22:02:11 UTC
Hello,

As mentioned in bug 9984, the changes for this bug disappeared. Other changes besides 9984 and 9985 might be affected too.

Cheers,
Ulf
Comment 9 Scott Rifenbark 2016-08-01 22:25:07 UTC
Check the link again for the change... Same explanation as the Bug 9984.

Scott
Comment 10 ulfalizer 2016-08-01 22:28:51 UTC
Looks good now!

Thanks,
Ulf
Comment 11 Scott Rifenbark 2016-08-01 22:31:27 UTC
Cool - setting doc flag to "done"