Bug 9984

Summary: Suggested clarification of the '3.1.2. Variable Expansion' section
Product: [Documentation] BitBake User Manual Reporter: ulfalizer
Component: bitbake-manualAssignee: Scott Rifenbark <srifenbark>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: Medium CC: bluelightning, sgw, srifenbark
Version: 2.2   
Target Milestone: 2.2 M3   
Hardware: x86   
OS: Multiple   
Whiteboard: 01 August 2016: RESOLVED
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Done (doc changes complete)

Description ulfalizer 2016-07-20 09:21:07 UTC
Hello Scott,

I've seen people being confused about the behavior of '=' when variables in the right-hand side are changed after the assignment. Rewriting/expanding '3.1.2. Variable Expansion' as follows might help:

  3.1.2. Variable expansion
  
  Variables can reference the contents of other variables using a syntax that is
  similar to variable expansion in Bourne shells. The following assignments
  result in A containing "aval" and B evaluating to "preavalpost".
  
       A = "aval"
       B = "pre${A}post"
  
  Note {
  Unlike in Bourne shells, the curly braces are mandatory: Only ${FOO} and
  not $FOO is recognized as an expansion of FOO.
  }
  
  The '=' operator does not immediately expand variable references in the
  right-hand side. Instead, expansion is deferred until the variable assigned to
  is actually used. The result depends on the current values of the referenced
  variables. The example below should clarify this behavior:
  
       A = "${B} baz"
       B = "${C} bar"
       C = "foo"
       *At this point, ${A} equals "foo bar baz"
       C = "qux"
       *At this point, ${A} equals "qux bar baz"
       B = "norf"
       *At this point, ${A} equals "norf baz"
  
  Contrast this behavior with the ':=' (immediate variable expansion) operator,
  which is described below.
Comment 1 ulfalizer 2016-07-20 09:24:38 UTC
Hmm... was supposed to be *'s at the end too:

       A = "${B} baz"
       B = "${C} bar"
       C = "foo"
       *At this point, ${A} equals "foo bar baz"*
       C = "qux"
       *At this point, ${A} equals "qux bar baz"*
       B = "norf"
       *At this point, ${A} equals "norf baz"*
Comment 2 Scott Rifenbark 2016-07-21 16:53:26 UTC
Ulf, 

Here is the new section - http://www.yoctoproject.org/docs/2.2/bitbake-user-manual/bitbake-user-manual.html#variable-expansion.

Thanks, 
Scott
Comment 3 ulfalizer 2016-07-21 16:57:48 UTC
Looks good.

Thanks,
Ulf
Comment 4 ulfalizer 2016-07-21 17:30:54 UTC
Thought of one more thing that might be nice to add to the end of 3.1.11. Inline Python Variable Expansion:

Note {
Inline Python expressions work just like variable expansions insofar as the '=' and ':=' operators are concerned. Given the following assignment, <code>foo()</code> will be called each time FOO is expanded:

    FOO = "${@foo()}"

Contrast this with the following immediate assignment, where <code>foo()</code> is only called once, while the assignment is parsed:

    FOO := "${@foo()}"
}
Comment 6 ulfalizer 2016-07-21 18:12:15 UTC
Looks good to me.

Thanks,
Ulf
Comment 7 Scott Rifenbark 2016-07-21 18:17:44 UTC
Ulf, 

Closing the bug out. 

thanks,
Scott
Comment 8 ulfalizer 2016-08-01 21:54:43 UTC
Hello,

I noticed that this change (and maybe others too) disappeared from the BitBake User Manual. Was that an error?

Cheers,
Ulf
Comment 9 ulfalizer 2016-08-01 21:56:08 UTC
(In reply to comment #8)
> Hello,
> 
> I noticed that this change (and maybe others too) disappeared from the
> BitBake User Manual. Was that an error?
> 
> Cheers,
> Ulf

At least 9985 disappeared as well.
Comment 10 Scott Rifenbark 2016-08-01 22:23:40 UTC
Ulf, 

Ok - I was trying to sync up my working repo with the actual upstream bitbake repo, which holds the docs.  In doing so, I did a "git pull" and apparently the changes I had made have not been merged into the actual upstream yet (they will be as Richard Purdie gets to these but not always right away).  

I rebuilt the manual from my poky-contrib/srifenbark/bb-manual area and the changes are there... they are not lost.  Just not merged yet.  

You can check those links out again to verify.

Sorry.

Scott
Comment 11 ulfalizer 2016-08-01 22:27:48 UTC
(In reply to comment #10)
> Ulf, 
> 
> Ok - I was trying to sync up my working repo with the actual upstream
> bitbake repo, which holds the docs.  In doing so, I did a "git pull" and
> apparently the changes I had made have not been merged into the actual
> upstream yet (they will be as Richard Purdie gets to these but not always
> right away).  
> 
> I rebuilt the manual from my poky-contrib/srifenbark/bb-manual area and the
> changes are there... they are not lost.  Just not merged yet.  
> 
> You can check those links out again to verify.
> 
> Sorry.
> 
> Scott

OK, no worries. Just wanted to make sure they hadn't been accidentally deleted. Might've lead to a PITA later. :)

Cheers,
Ulf
Comment 12 Scott Rifenbark 2016-08-01 22:32:52 UTC
Ha - yes, it could have.