6

What does the different assignment types mean in bitbake recipe scripts, such as:

 BB_NUMBER_THREADS  ?=  "${@oe.utils.cpu_count()}"
 PARALLEL_MAKE  ?=  "-j ${@oe.utils.cpu_count()}"
 MACHINE    ??= "qemux86"

What of above is analogous to Ruby's bb_number_threads ||= 'something'?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Frankie_Fomalhaut
  • 331
  • 1
  • 2
  • 7

2 Answers2

14

As per this section of Bitbake manual

?= is:

You can use the "?=" operator to achieve a "softer" assignment for a variable. This type of assignment allows you to define a variable if it is undefined when the statement is parsed, but to leave the value alone if the variable has a value. Here is an example:

A ?= "aval"

If A is set at the time this statement is parsed, the variable retains its value. However, if A is not set, the variable is set to "aval".

??= is:

It is possible to use a "weaker" assignment than in the previous section by using the "??=" operator. This assignment behaves identical to "?=" except that the assignment is made at the end of the parsing process rather than immediately. Consequently, when multiple "??=" assignments exist, the last one is used. Also, any "=" or "?=" assignment will override the value set with "??=". Here is an example:

 A ??= "somevalue"
 A ??= "someothervalue"

If A is set before the above statements are parsed, the variable retains its value. If A is not set, the variable is set to "someothervalue".

Again, this assignment is a "lazy" or "weak" assignment because it does not occur until the end of the parsing process.

Frankie_Fomalhaut
  • 331
  • 1
  • 2
  • 7
0

Short and crisp explaination would be:

IF A is not set before and

A ?= aval A ?= difval

at the end of the parsing, the value of A will be aval.

Simple rule about ?= : The first set value will be used.


IF A is not set before and

A ?= aval A ??= difval

OR

A = aval A ??= difval

at the end of the parsing, the value of A will stay aval

Simple rule about ??=: = & ?= overwrite ??=


IF A is not set before and

A ??= aval A ??= difval

at the end of the parsing, the value of A will be difval

Simple rule about ??=: last set value by ??= will be considered.

divyesh
  • 1
  • 1