bitbake-user-manual-metadata.rst 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. ====================
  2. Syntax and Operators
  3. ====================
  4. BitBake files have their own syntax. The syntax has similarities to
  5. several other languages but also has some unique features. This section
  6. describes the available syntax and operators as well as provides
  7. examples.
  8. Basic Syntax
  9. ============
  10. This section provides some basic syntax examples.
  11. Basic Variable Setting
  12. ----------------------
  13. The following example sets ``VARIABLE`` to "value". This assignment
  14. occurs immediately as the statement is parsed. It is a "hard"
  15. assignment. VARIABLE = "value" As expected, if you include leading or
  16. trailing spaces as part of an assignment, the spaces are retained:
  17. VARIABLE = " value" VARIABLE = "value " Setting ``VARIABLE`` to "" sets
  18. it to an empty string, while setting the variable to " " sets it to a
  19. blank space (i.e. these are not the same values). VARIABLE = "" VARIABLE
  20. = " "
  21. You can use single quotes instead of double quotes when setting a
  22. variable's value. Doing so allows you to use values that contain the
  23. double quote character: VARIABLE = 'I have a " in my value'
  24. .. note::
  25. Unlike in Bourne shells, single quotes work identically to double
  26. quotes in all other ways. They do not suppress variable expansions.
  27. Modifying Existing Variables
  28. ----------------------------
  29. Sometimes you need to modify existing variables. Following are some
  30. cases where you might find you want to modify an existing variable:
  31. - Customize a recipe that uses the variable.
  32. - Change a variable's default value used in a ``*.bbclass`` file.
  33. - Change the variable in a ``*.bbappend`` file to override the variable
  34. in the original recipe.
  35. - Change the variable in a configuration file so that the value
  36. overrides an existing configuration.
  37. Changing a variable value can sometimes depend on how the value was
  38. originally assigned and also on the desired intent of the change. In
  39. particular, when you append a value to a variable that has a default
  40. value, the resulting value might not be what you expect. In this case,
  41. the value you provide might replace the value rather than append to the
  42. default value.
  43. If after you have changed a variable's value and something unexplained
  44. occurs, you can use BitBake to check the actual value of the suspect
  45. variable. You can make these checks for both configuration and recipe
  46. level changes:
  47. - For configuration changes, use the following: $ bitbake -e This
  48. command displays variable values after the configuration files (i.e.
  49. ``local.conf``, ``bblayers.conf``, ``bitbake.conf`` and so forth)
  50. have been parsed.
  51. .. note::
  52. Variables that are exported to the environment are preceded by the
  53. string "export" in the command's output.
  54. - For recipe changes, use the following: $ bitbake recipe -e \| grep
  55. VARIABLE=" This command checks to see if the variable actually makes
  56. it into a specific recipe.
  57. Line Joining
  58. ------------
  59. Outside of `functions <#functions>`__, BitBake joins any line ending in
  60. a backslash character ("\") with the following line before parsing
  61. statements. The most common use for the "\" character is to split
  62. variable assignments over multiple lines, as in the following example:
  63. FOO = "bar \\ baz \\ qaz" Both the "\" character and the newline
  64. character that follow it are removed when joining lines. Thus, no
  65. newline characters end up in the value of ``FOO``.
  66. Consider this additional example where the two assignments both assign
  67. "barbaz" to ``FOO``: FOO = "barbaz" FOO = "bar\\ baz"
  68. .. note::
  69. BitBake does not interpret escape sequences like "\n" in variable
  70. values. For these to have an effect, the value must be passed to some
  71. utility that interprets escape sequences, such as
  72. printf
  73. or
  74. echo -n
  75. .
  76. Variable Expansion
  77. ------------------
  78. Variables can reference the contents of other variables using a syntax
  79. that is similar to variable expansion in Bourne shells. The following
  80. assignments result in A containing "aval" and B evaluating to
  81. "preavalpost". A = "aval" B = "pre${A}post"
  82. .. note::
  83. Unlike in Bourne shells, the curly braces are mandatory: Only
  84. ${FOO}
  85. and not
  86. $FOO
  87. is recognized as an expansion of
  88. FOO
  89. .
  90. The "=" operator does not immediately expand variable references in the
  91. right-hand side. Instead, expansion is deferred until the variable
  92. assigned to is actually used. The result depends on the current values
  93. of the referenced variables. The following example should clarify this
  94. behavior: A = "${B} baz" B = "${C} bar" C = "foo" \*At this point, ${A}
  95. equals "foo bar baz"\* C = "qux" \*At this point, ${A} equals "qux bar
  96. baz"\* B = "norf" \*At this point, ${A} equals "norf baz"\* Contrast
  97. this behavior with the `immediate variable
  98. expansion <#immediate-variable-expansion>`__ operator (i.e. ":=").
  99. If the variable expansion syntax is used on a variable that does not
  100. exist, the string is kept as is. For example, given the following
  101. assignment, ``BAR`` expands to the literal string "${FOO}" as long as
  102. ``FOO`` does not exist. BAR = "${FOO}"
  103. Setting a default value (?=)
  104. ----------------------------
  105. You can use the "?=" operator to achieve a "softer" assignment for a
  106. variable. This type of assignment allows you to define a variable if it
  107. is undefined when the statement is parsed, but to leave the value alone
  108. if the variable has a value. Here is an example: A ?= "aval" If ``A`` is
  109. set at the time this statement is parsed, the variable retains its
  110. value. However, if ``A`` is not set, the variable is set to "aval".
  111. .. note::
  112. This assignment is immediate. Consequently, if multiple "?="
  113. assignments to a single variable exist, the first of those ends up
  114. getting used.
  115. Setting a weak default value (??=)
  116. ----------------------------------
  117. It is possible to use a "weaker" assignment than in the previous section
  118. by using the "??=" operator. This assignment behaves identical to "?="
  119. except that the assignment is made at the end of the parsing process
  120. rather than immediately. Consequently, when multiple "??=" assignments
  121. exist, the last one is used. Also, any "=" or "?=" assignment will
  122. override the value set with "??=". Here is an example: A ??= "somevalue"
  123. A ??= "someothervalue" If ``A`` is set before the above statements are
  124. parsed, the variable retains its value. If ``A`` is not set, the
  125. variable is set to "someothervalue".
  126. Again, this assignment is a "lazy" or "weak" assignment because it does
  127. not occur until the end of the parsing process.
  128. Immediate variable expansion (:=)
  129. ---------------------------------
  130. The ":=" operator results in a variable's contents being expanded
  131. immediately, rather than when the variable is actually used: T = "123" A
  132. := "test ${T}" T = "456" B := "${T} ${C}" C = "cval" C := "${C}append"
  133. In this example, ``A`` contains "test 123", even though the final value
  134. of ``T`` is "456". The variable ``B`` will end up containing "456
  135. cvalappend". This is because references to undefined variables are
  136. preserved as is during (immediate)expansion. This is in contrast to GNU
  137. Make, where undefined variables expand to nothing. The variable ``C``
  138. contains "cvalappend" since ``${C}`` immediately expands to "cval".
  139. .. _appending-and-prepending:
  140. Appending (+=) and prepending (=+) With Spaces
  141. ----------------------------------------------
  142. Appending and prepending values is common and can be accomplished using
  143. the "+=" and "=+" operators. These operators insert a space between the
  144. current value and prepended or appended value.
  145. These operators take immediate effect during parsing. Here are some
  146. examples: B = "bval" B += "additionaldata" C = "cval" C =+ "test" The
  147. variable ``B`` contains "bval additionaldata" and ``C`` contains "test
  148. cval".
  149. .. _appending-and-prepending-without-spaces:
  150. Appending (.=) and Prepending (=.) Without Spaces
  151. -------------------------------------------------
  152. If you want to append or prepend values without an inserted space, use
  153. the ".=" and "=." operators.
  154. These operators take immediate effect during parsing. Here are some
  155. examples: B = "bval" B .= "additionaldata" C = "cval" C =. "test" The
  156. variable ``B`` contains "bvaladditionaldata" and ``C`` contains
  157. "testcval".
  158. Appending and Prepending (Override Style Syntax)
  159. ------------------------------------------------
  160. You can also append and prepend a variable's value using an override
  161. style syntax. When you use this syntax, no spaces are inserted.
  162. These operators differ from the ":=", ".=", "=.", "+=", and "=+"
  163. operators in that their effects are applied at variable expansion time
  164. rather than being immediately applied. Here are some examples: B =
  165. "bval" B_append = " additional data" C = "cval" C_prepend = "additional
  166. data " D = "dval" D_append = "additional data" The variable ``B``
  167. becomes "bval additional data" and ``C`` becomes "additional data cval".
  168. The variable ``D`` becomes "dvaladditional data".
  169. .. note::
  170. You must control all spacing when you use the override syntax.
  171. It is also possible to append and prepend to shell functions and
  172. BitBake-style Python functions. See the "`Shell
  173. Functions <#shell-functions>`__" and "`BitBake-Style Python
  174. Functions <#bitbake-style-python-functions>`__ sections for examples.
  175. .. _removing-override-style-syntax:
  176. Removal (Override Style Syntax)
  177. -------------------------------
  178. You can remove values from lists using the removal override style
  179. syntax. Specifying a value for removal causes all occurrences of that
  180. value to be removed from the variable.
  181. When you use this syntax, BitBake expects one or more strings.
  182. Surrounding spaces and spacing are preserved. Here is an example: FOO =
  183. "123 456 789 123456 123 456 123 456" FOO_remove = "123" FOO_remove =
  184. "456" FOO2 = " abc def ghi abcdef abc def abc def def" FOO2_remove = "
  185. \\ def \\ abc \\ ghi \\ " The variable ``FOO`` becomes
  186. "  789 123456    " and ``FOO2`` becomes "     abcdef      ".
  187. Like "_append" and "_prepend", "_remove" is applied at variable
  188. expansion time.
  189. Override Style Operation Advantages
  190. -----------------------------------
  191. An advantage of the override style operations "_append", "_prepend", and
  192. "_remove" as compared to the "+=" and "=+" operators is that the
  193. override style operators provide guaranteed operations. For example,
  194. consider a class ``foo.bbclass`` that needs to add the value "val" to
  195. the variable ``FOO``, and a recipe that uses ``foo.bbclass`` as follows:
  196. inherit foo FOO = "initial" If ``foo.bbclass`` uses the "+=" operator,
  197. as follows, then the final value of ``FOO`` will be "initial", which is
  198. not what is desired: FOO += "val" If, on the other hand, ``foo.bbclass``
  199. uses the "_append" operator, then the final value of ``FOO`` will be
  200. "initial val", as intended: FOO_append = " val"
  201. .. note::
  202. It is never necessary to use "+=" together with "_append". The
  203. following sequence of assignments appends "barbaz" to
  204. FOO
  205. :
  206. ::
  207. FOO_append = "bar"
  208. FOO_append = "baz"
  209. The only effect of changing the second assignment in the previous
  210. example to use "+=" would be to add a space before "baz" in the
  211. appended value (due to how the "+=" operator works).
  212. Another advantage of the override style operations is that you can
  213. combine them with other overrides as described in the "`Conditional
  214. Syntax (Overrides) <#conditional-syntax-overrides>`__" section.
  215. Variable Flag Syntax
  216. --------------------
  217. Variable flags are BitBake's implementation of variable properties or
  218. attributes. It is a way of tagging extra information onto a variable.
  219. You can find more out about variable flags in general in the "`Variable
  220. Flags <#variable-flags>`__" section.
  221. You can define, append, and prepend values to variable flags. All the
  222. standard syntax operations previously mentioned work for variable flags
  223. except for override style syntax (i.e. "_prepend", "_append", and
  224. "_remove").
  225. Here are some examples showing how to set variable flags: FOO[a] = "abc"
  226. FOO[b] = "123" FOO[a] += "456" The variable ``FOO`` has two flags:
  227. ``[a]`` and ``[b]``. The flags are immediately set to "abc" and "123",
  228. respectively. The ``[a]`` flag becomes "abc 456".
  229. No need exists to pre-define variable flags. You can simply start using
  230. them. One extremely common application is to attach some brief
  231. documentation to a BitBake variable as follows: CACHE[doc] = "The
  232. directory holding the cache of the metadata."
  233. Inline Python Variable Expansion
  234. --------------------------------
  235. You can use inline Python variable expansion to set variables. Here is
  236. an example: DATE = "${@time.strftime('%Y%m%d',time.gmtime())}" This
  237. example results in the ``DATE`` variable being set to the current date.
  238. Probably the most common use of this feature is to extract the value of
  239. variables from BitBake's internal data dictionary, ``d``. The following
  240. lines select the values of a package name and its version number,
  241. respectively: PN =
  242. "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or
  243. 'defaultpkgname'}" PV =
  244. "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[1] or
  245. '1.0'}"
  246. .. note::
  247. Inline Python expressions work just like variable expansions insofar
  248. as the "=" and ":=" operators are concerned. Given the following
  249. assignment,
  250. foo()
  251. is called each time
  252. FOO
  253. is expanded:
  254. ::
  255. FOO = "${@foo()}"
  256. Contrast this with the following immediate assignment, where
  257. foo()
  258. is only called once, while the assignment is parsed:
  259. ::
  260. FOO := "${@foo()}"
  261. For a different way to set variables with Python code during parsing,
  262. see the "`Anonymous Python Functions <#anonymous-python-functions>`__"
  263. section.
  264. Unsetting variables
  265. -------------------
  266. It is possible to completely remove a variable or a variable flag from
  267. BitBake's internal data dictionary by using the "unset" keyword. Here is
  268. an example: unset DATE unset do_fetch[noexec] These two statements
  269. remove the ``DATE`` and the ``do_fetch[noexec]`` flag.
  270. Providing Pathnames
  271. -------------------
  272. When specifying pathnames for use with BitBake, do not use the tilde
  273. ("~") character as a shortcut for your home directory. Doing so might
  274. cause BitBake to not recognize the path since BitBake does not expand
  275. this character in the same way a shell would.
  276. Instead, provide a fuller path as the following example illustrates:
  277. BBLAYERS ?= " \\ /home/scott-lenovo/LayerA \\ "
  278. Exporting Variables to the Environment
  279. ======================================
  280. You can export variables to the environment of running tasks by using
  281. the ``export`` keyword. For example, in the following example, the
  282. ``do_foo`` task prints "value from the environment" when run: export
  283. ENV_VARIABLE ENV_VARIABLE = "value from the environment" do_foo() {
  284. bbplain "$ENV_VARIABLE" }
  285. .. note::
  286. BitBake does not expand
  287. $ENV_VARIABLE
  288. in this case because it lacks the obligatory
  289. {}
  290. . Rather,
  291. $ENV_VARIABLE
  292. is expanded by the shell.
  293. It does not matter whether ``export ENV_VARIABLE`` appears before or
  294. after assignments to ``ENV_VARIABLE``.
  295. It is also possible to combine ``export`` with setting a value for the
  296. variable. Here is an example: export ENV_VARIABLE = "variable-value" In
  297. the output of ``bitbake -e``, variables that are exported to the
  298. environment are preceded by "export".
  299. Among the variables commonly exported to the environment are ``CC`` and
  300. ``CFLAGS``, which are picked up by many build systems.
  301. Conditional Syntax (Overrides)
  302. ==============================
  303. BitBake uses :term:`OVERRIDES` to control what
  304. variables are overridden after BitBake parses recipes and configuration
  305. files. This section describes how you can use ``OVERRIDES`` as
  306. conditional metadata, talks about key expansion in relationship to
  307. ``OVERRIDES``, and provides some examples to help with understanding.
  308. Conditional Metadata
  309. --------------------
  310. You can use ``OVERRIDES`` to conditionally select a specific version of
  311. a variable and to conditionally append or prepend the value of a
  312. variable.
  313. .. note::
  314. Overrides can only use lower-case characters. Additionally,
  315. underscores are not permitted in override names as they are used to
  316. separate overrides from each other and from the variable name.
  317. - *Selecting a Variable:* The ``OVERRIDES`` variable is a
  318. colon-character-separated list that contains items for which you want
  319. to satisfy conditions. Thus, if you have a variable that is
  320. conditional on “arm”, and “arm” is in ``OVERRIDES``, then the
  321. “arm”-specific version of the variable is used rather than the
  322. non-conditional version. Here is an example: OVERRIDES =
  323. "architecture:os:machine" TEST = "default" TEST_os = "osspecific"
  324. TEST_nooverride = "othercondvalue" In this example, the ``OVERRIDES``
  325. variable lists three overrides: "architecture", "os", and "machine".
  326. The variable ``TEST`` by itself has a default value of "default". You
  327. select the os-specific version of the ``TEST`` variable by appending
  328. the "os" override to the variable (i.e.\ ``TEST_os``).
  329. To better understand this, consider a practical example that assumes
  330. an OpenEmbedded metadata-based Linux kernel recipe file. The
  331. following lines from the recipe file first set the kernel branch
  332. variable ``KBRANCH`` to a default value, then conditionally override
  333. that value based on the architecture of the build: KBRANCH =
  334. "standard/base" KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
  335. KBRANCH_qemumips = "standard/mti-malta32" KBRANCH_qemuppc =
  336. "standard/qemuppc" KBRANCH_qemux86 = "standard/common-pc/base"
  337. KBRANCH_qemux86-64 = "standard/common-pc-64/base" KBRANCH_qemumips64
  338. = "standard/mti-malta64"
  339. - *Appending and Prepending:* BitBake also supports append and prepend
  340. operations to variable values based on whether a specific item is
  341. listed in ``OVERRIDES``. Here is an example: DEPENDS = "glibc
  342. ncurses" OVERRIDES = "machine:local" DEPENDS_append_machine = "
  343. libmad" In this example, ``DEPENDS`` becomes "glibc ncurses libmad".
  344. Again, using an OpenEmbedded metadata-based kernel recipe file as an
  345. example, the following lines will conditionally append to the
  346. ``KERNEL_FEATURES`` variable based on the architecture:
  347. KERNEL_FEATURES_append = " ${KERNEL_EXTRA_FEATURES}"
  348. KERNEL_FEATURES_append_qemux86=" cfg/sound.scc cfg/paravirt_kvm.scc"
  349. KERNEL_FEATURES_append_qemux86-64=" cfg/sound.scc
  350. cfg/paravirt_kvm.scc"
  351. - *Setting a Variable for a Single Task:* BitBake supports setting a
  352. variable just for the duration of a single task. Here is an example:
  353. FOO_task-configure = "val 1" FOO_task-compile = "val 2" In the
  354. previous example, ``FOO`` has the value "val 1" while the
  355. ``do_configure`` task is executed, and the value "val 2" while the
  356. ``do_compile`` task is executed.
  357. Internally, this is implemented by prepending the task (e.g.
  358. "task-compile:") to the value of
  359. :term:`OVERRIDES` for the local datastore of the
  360. ``do_compile`` task.
  361. You can also use this syntax with other combinations (e.g.
  362. "``_prepend``") as shown in the following example:
  363. EXTRA_OEMAKE_prepend_task-compile = "${PARALLEL_MAKE} "
  364. Key Expansion
  365. -------------
  366. Key expansion happens when the BitBake datastore is finalized. To better
  367. understand this, consider the following example: A${B} = "X" B = "2" A2
  368. = "Y" In this case, after all the parsing is complete, BitBake expands
  369. ``${B}`` into "2". This expansion causes ``A2``, which was set to "Y"
  370. before the expansion, to become "X".
  371. .. _variable-interaction-worked-examples:
  372. Examples
  373. --------
  374. Despite the previous explanations that show the different forms of
  375. variable definitions, it can be hard to work out exactly what happens
  376. when variable operators, conditional overrides, and unconditional
  377. overrides are combined. This section presents some common scenarios
  378. along with explanations for variable interactions that typically confuse
  379. users.
  380. There is often confusion concerning the order in which overrides and
  381. various "append" operators take effect. Recall that an append or prepend
  382. operation using "_append" and "_prepend" does not result in an immediate
  383. assignment as would "+=", ".=", "=+", or "=.". Consider the following
  384. example: OVERRIDES = "foo" A = "Z" A_foo_append = "X" For this case,
  385. ``A`` is unconditionally set to "Z" and "X" is unconditionally and
  386. immediately appended to the variable ``A_foo``. Because overrides have
  387. not been applied yet, ``A_foo`` is set to "X" due to the append and
  388. ``A`` simply equals "Z".
  389. Applying overrides, however, changes things. Since "foo" is listed in
  390. ``OVERRIDES``, the conditional variable ``A`` is replaced with the "foo"
  391. version, which is equal to "X". So effectively, ``A_foo`` replaces
  392. ``A``.
  393. This next example changes the order of the override and the append:
  394. OVERRIDES = "foo" A = "Z" A_append_foo = "X" For this case, before
  395. overrides are handled, ``A`` is set to "Z" and ``A_append_foo`` is set
  396. to "X". Once the override for "foo" is applied, however, ``A`` gets
  397. appended with "X". Consequently, ``A`` becomes "ZX". Notice that spaces
  398. are not appended.
  399. This next example has the order of the appends and overrides reversed
  400. back as in the first example: OVERRIDES = "foo" A = "Y" A_foo_append =
  401. "Z" A_foo_append = "X" For this case, before any overrides are resolved,
  402. ``A`` is set to "Y" using an immediate assignment. After this immediate
  403. assignment, ``A_foo`` is set to "Z", and then further appended with "X"
  404. leaving the variable set to "ZX". Finally, applying the override for
  405. "foo" results in the conditional variable ``A`` becoming "ZX" (i.e.
  406. ``A`` is replaced with ``A_foo``).
  407. This final example mixes in some varying operators: A = "1" A_append =
  408. "2" A_append = "3" A += "4" A .= "5" For this case, the type of append
  409. operators are affecting the order of assignments as BitBake passes
  410. through the code multiple times. Initially, ``A`` is set to "1 45"
  411. because of the three statements that use immediate operators. After
  412. these assignments are made, BitBake applies the "_append" operations.
  413. Those operations result in ``A`` becoming "1 4523".
  414. Sharing Functionality
  415. =====================
  416. BitBake allows for metadata sharing through include files (``.inc``) and
  417. class files (``.bbclass``). For example, suppose you have a piece of
  418. common functionality such as a task definition that you want to share
  419. between more than one recipe. In this case, creating a ``.bbclass`` file
  420. that contains the common functionality and then using the ``inherit``
  421. directive in your recipes to inherit the class would be a common way to
  422. share the task.
  423. This section presents the mechanisms BitBake provides to allow you to
  424. share functionality between recipes. Specifically, the mechanisms
  425. include ``include``, ``inherit``, ``INHERIT``, and ``require``
  426. directives.
  427. Locating Include and Class Files
  428. --------------------------------
  429. BitBake uses the :term:`BBPATH` variable to locate
  430. needed include and class files. Additionally, BitBake searches the
  431. current directory for ``include`` and ``require`` directives.
  432. .. note::
  433. The
  434. BBPATH
  435. variable is analogous to the environment variable
  436. PATH
  437. .
  438. In order for include and class files to be found by BitBake, they need
  439. to be located in a "classes" subdirectory that can be found in
  440. ``BBPATH``.
  441. ``inherit`` Directive
  442. ---------------------
  443. When writing a recipe or class file, you can use the ``inherit``
  444. directive to inherit the functionality of a class (``.bbclass``).
  445. BitBake only supports this directive when used within recipe and class
  446. files (i.e. ``.bb`` and ``.bbclass``).
  447. The ``inherit`` directive is a rudimentary means of specifying
  448. functionality contained in class files that your recipes require. For
  449. example, you can easily abstract out the tasks involved in building a
  450. package that uses Autoconf and Automake and put those tasks into a class
  451. file and then have your recipe inherit that class file.
  452. As an example, your recipes could use the following directive to inherit
  453. an ``autotools.bbclass`` file. The class file would contain common
  454. functionality for using Autotools that could be shared across recipes:
  455. inherit autotools In this case, BitBake would search for the directory
  456. ``classes/autotools.bbclass`` in ``BBPATH``.
  457. .. note::
  458. You can override any values and functions of the inherited class
  459. within your recipe by doing so after the "inherit" statement.
  460. If you want to use the directive to inherit multiple classes, separate
  461. them with spaces. The following example shows how to inherit both the
  462. ``buildhistory`` and ``rm_work`` classes: inherit buildhistory rm_work
  463. An advantage with the inherit directive as compared to both the
  464. `include <#include-directive>`__ and `require <#require-inclusion>`__
  465. directives is that you can inherit class files conditionally. You can
  466. accomplish this by using a variable expression after the ``inherit``
  467. statement. Here is an example: inherit ${VARNAME} If ``VARNAME`` is
  468. going to be set, it needs to be set before the ``inherit`` statement is
  469. parsed. One way to achieve a conditional inherit in this case is to use
  470. overrides: VARIABLE = "" VARIABLE_someoverride = "myclass"
  471. Another method is by using anonymous Python. Here is an example: python
  472. () { if condition == value: d.setVar('VARIABLE', 'myclass') else:
  473. d.setVar('VARIABLE', '') }
  474. Alternatively, you could use an in-line Python expression in the
  475. following form: inherit ${@'classname' if condition else ''} inherit
  476. ${@functionname(params)} In all cases, if the expression evaluates to an
  477. empty string, the statement does not trigger a syntax error because it
  478. becomes a no-op.
  479. ``include`` Directive
  480. ---------------------
  481. BitBake understands the ``include`` directive. This directive causes
  482. BitBake to parse whatever file you specify, and to insert that file at
  483. that location. The directive is much like its equivalent in Make except
  484. that if the path specified on the include line is a relative path,
  485. BitBake locates the first file it can find within ``BBPATH``.
  486. The include directive is a more generic method of including
  487. functionality as compared to the `inherit <#inherit-directive>`__
  488. directive, which is restricted to class (i.e. ``.bbclass``) files. The
  489. include directive is applicable for any other kind of shared or
  490. encapsulated functionality or configuration that does not suit a
  491. ``.bbclass`` file.
  492. As an example, suppose you needed a recipe to include some self-test
  493. definitions: include test_defs.inc
  494. .. note::
  495. The
  496. include
  497. directive does not produce an error when the file cannot be found.
  498. Consequently, it is recommended that if the file you are including is
  499. expected to exist, you should use
  500. :ref:`require <require-inclusion>`
  501. instead of
  502. include
  503. . Doing so makes sure that an error is produced if the file cannot be
  504. found.
  505. .. _require-inclusion:
  506. ``require`` Directive
  507. ---------------------
  508. BitBake understands the ``require`` directive. This directive behaves
  509. just like the ``include`` directive with the exception that BitBake
  510. raises a parsing error if the file to be included cannot be found. Thus,
  511. any file you require is inserted into the file that is being parsed at
  512. the location of the directive.
  513. The require directive, like the include directive previously described,
  514. is a more generic method of including functionality as compared to the
  515. `inherit <#inherit-directive>`__ directive, which is restricted to class
  516. (i.e. ``.bbclass``) files. The require directive is applicable for any
  517. other kind of shared or encapsulated functionality or configuration that
  518. does not suit a ``.bbclass`` file.
  519. Similar to how BitBake handles ```include`` <#include-directive>`__, if
  520. the path specified on the require line is a relative path, BitBake
  521. locates the first file it can find within ``BBPATH``.
  522. As an example, suppose you have two versions of a recipe (e.g.
  523. ``foo_1.2.2.bb`` and ``foo_2.0.0.bb``) where each version contains some
  524. identical functionality that could be shared. You could create an
  525. include file named ``foo.inc`` that contains the common definitions
  526. needed to build "foo". You need to be sure ``foo.inc`` is located in the
  527. same directory as your two recipe files as well. Once these conditions
  528. are set up, you can share the functionality using a ``require``
  529. directive from within each recipe: require foo.inc
  530. ``INHERIT`` Configuration Directive
  531. -----------------------------------
  532. When creating a configuration file (``.conf``), you can use the
  533. :term:`INHERIT` configuration directive to inherit a
  534. class. BitBake only supports this directive when used within a
  535. configuration file.
  536. As an example, suppose you needed to inherit a class file called
  537. ``abc.bbclass`` from a configuration file as follows: INHERIT += "abc"
  538. This configuration directive causes the named class to be inherited at
  539. the point of the directive during parsing. As with the ``inherit``
  540. directive, the ``.bbclass`` file must be located in a "classes"
  541. subdirectory in one of the directories specified in ``BBPATH``.
  542. .. note::
  543. Because
  544. .conf
  545. files are parsed first during BitBake's execution, using
  546. INHERIT
  547. to inherit a class effectively inherits the class globally (i.e. for
  548. all recipes).
  549. If you want to use the directive to inherit multiple classes, you can
  550. provide them on the same line in the ``local.conf`` file. Use spaces to
  551. separate the classes. The following example shows how to inherit both
  552. the ``autotools`` and ``pkgconfig`` classes: INHERIT += "autotools
  553. pkgconfig"
  554. Functions
  555. =========
  556. As with most languages, functions are the building blocks that are used
  557. to build up operations into tasks. BitBake supports these types of
  558. functions:
  559. - *Shell Functions:* Functions written in shell script and executed
  560. either directly as functions, tasks, or both. They can also be called
  561. by other shell functions.
  562. - *BitBake-Style Python Functions:* Functions written in Python and
  563. executed by BitBake or other Python functions using
  564. ``bb.build.exec_func()``.
  565. - *Python Functions:* Functions written in Python and executed by
  566. Python.
  567. - *Anonymous Python Functions:* Python functions executed automatically
  568. during parsing.
  569. Regardless of the type of function, you can only define them in class
  570. (``.bbclass``) and recipe (``.bb`` or ``.inc``) files.
  571. Shell Functions
  572. ---------------
  573. Functions written in shell script and executed either directly as
  574. functions, tasks, or both. They can also be called by other shell
  575. functions. Here is an example shell function definition: some_function
  576. () { echo "Hello World" } When you create these types of functions in
  577. your recipe or class files, you need to follow the shell programming
  578. rules. The scripts are executed by ``/bin/sh``, which may not be a bash
  579. shell but might be something such as ``dash``. You should not use
  580. Bash-specific script (bashisms).
  581. Overrides and override-style operators like ``_append`` and ``_prepend``
  582. can also be applied to shell functions. Most commonly, this application
  583. would be used in a ``.bbappend`` file to modify functions in the main
  584. recipe. It can also be used to modify functions inherited from classes.
  585. As an example, consider the following: do_foo() { bbplain first fn }
  586. fn_prepend() { bbplain second } fn() { bbplain third } do_foo_append() {
  587. bbplain fourth } Running ``do_foo`` prints the following: recipename
  588. do_foo: first recipename do_foo: second recipename do_foo: third
  589. recipename do_foo: fourth
  590. .. note::
  591. Overrides and override-style operators can be applied to any shell
  592. function, not just :ref:`tasks <bitbake-user-manual/bitbake-user-manual-metadata:Tasks>`.
  593. You can use the ``bitbake -e`` recipename command to view the final
  594. assembled function after all overrides have been applied.
  595. BitBake-Style Python Functions
  596. ------------------------------
  597. These functions are written in Python and executed by BitBake or other
  598. Python functions using ``bb.build.exec_func()``.
  599. An example BitBake function is: python some_python_function () {
  600. d.setVar("TEXT", "Hello World") print d.getVar("TEXT") } Because the
  601. Python "bb" and "os" modules are already imported, you do not need to
  602. import these modules. Also in these types of functions, the datastore
  603. ("d") is a global variable and is always automatically available.
  604. .. note::
  605. Variable expressions (e.g.
  606. ${X}
  607. ) are no longer expanded within Python functions. This behavior is
  608. intentional in order to allow you to freely set variable values to
  609. expandable expressions without having them expanded prematurely. If
  610. you do wish to expand a variable within a Python function, use
  611. d.getVar("X")
  612. . Or, for more complicated expressions, use
  613. d.expand()
  614. .
  615. Similar to shell functions, you can also apply overrides and
  616. override-style operators to BitBake-style Python functions.
  617. As an example, consider the following: python do_foo_prepend() {
  618. bb.plain("first") } python do_foo() { bb.plain("second") } python
  619. do_foo_append() { bb.plain("third") } Running ``do_foo`` prints the
  620. following: recipename do_foo: first recipename do_foo: second recipename
  621. do_foo: third You can use the ``bitbake -e`` recipename command to view
  622. the final assembled function after all overrides have been applied.
  623. Python Functions
  624. ----------------
  625. These functions are written in Python and are executed by other Python
  626. code. Examples of Python functions are utility functions that you intend
  627. to call from in-line Python or from within other Python functions. Here
  628. is an example: def get_depends(d): if d.getVar('SOMECONDITION'): return
  629. "dependencywithcond" else: return "dependency" SOMECONDITION = "1"
  630. DEPENDS = "${@get_depends(d)}" This would result in ``DEPENDS``
  631. containing ``dependencywithcond``.
  632. Here are some things to know about Python functions:
  633. - Python functions can take parameters.
  634. - The BitBake datastore is not automatically available. Consequently,
  635. you must pass it in as a parameter to the function.
  636. - The "bb" and "os" Python modules are automatically available. You do
  637. not need to import them.
  638. BitBake-Style Python Functions Versus Python Functions
  639. ------------------------------------------------------
  640. Following are some important differences between BitBake-style Python
  641. functions and regular Python functions defined with "def":
  642. - Only BitBake-style Python functions can be `tasks <#tasks>`__.
  643. - Overrides and override-style operators can only be applied to
  644. BitBake-style Python functions.
  645. - Only regular Python functions can take arguments and return values.
  646. - `Variable flags <#variable-flags>`__ such as ``[dirs]``,
  647. ``[cleandirs]``, and ``[lockfiles]`` can be used on BitBake-style
  648. Python functions, but not on regular Python functions.
  649. - BitBake-style Python functions generate a separate
  650. ``${``\ :term:`T`\ ``}/run.``\ function-name\ ``.``\ pid
  651. script that is executed to run the function, and also generate a log
  652. file in ``${T}/log.``\ function-name\ ``.``\ pid if they are executed
  653. as tasks.
  654. Regular Python functions execute "inline" and do not generate any
  655. files in ``${T}``.
  656. - Regular Python functions are called with the usual Python syntax.
  657. BitBake-style Python functions are usually tasks and are called
  658. directly by BitBake, but can also be called manually from Python code
  659. by using the ``bb.build.exec_func()`` function. Here is an example:
  660. bb.build.exec_func("my_bitbake_style_function", d)
  661. .. note::
  662. bb.build.exec_func()
  663. can also be used to run shell functions from Python code. If you
  664. want to run a shell function before a Python function within the
  665. same task, then you can use a parent helper Python function that
  666. starts by running the shell function with
  667. bb.build.exec_func()
  668. and then runs the Python code.
  669. To detect errors from functions executed with
  670. ``bb.build.exec_func()``, you can catch the ``bb.build.FuncFailed``
  671. exception.
  672. .. note::
  673. Functions in metadata (recipes and classes) should not themselves
  674. raise
  675. bb.build.FuncFailed
  676. . Rather,
  677. bb.build.FuncFailed
  678. should be viewed as a general indicator that the called function
  679. failed by raising an exception. For example, an exception raised
  680. by
  681. bb.fatal()
  682. will be caught inside
  683. bb.build.exec_func()
  684. , and a
  685. bb.build.FuncFailed
  686. will be raised in response.
  687. Due to their simplicity, you should prefer regular Python functions over
  688. BitBake-style Python functions unless you need a feature specific to
  689. BitBake-style Python functions. Regular Python functions in metadata are
  690. a more recent invention than BitBake-style Python functions, and older
  691. code tends to use ``bb.build.exec_func()`` more often.
  692. Anonymous Python Functions
  693. --------------------------
  694. Sometimes it is useful to set variables or perform other operations
  695. programmatically during parsing. To do this, you can define special
  696. Python functions, called anonymous Python functions, that run at the end
  697. of parsing. For example, the following conditionally sets a variable
  698. based on the value of another variable: python () { if
  699. d.getVar('SOMEVAR') == 'value': d.setVar('ANOTHERVAR', 'value2') } An
  700. equivalent way to mark a function as an anonymous function is to give it
  701. the name "__anonymous", rather than no name.
  702. Anonymous Python functions always run at the end of parsing, regardless
  703. of where they are defined. If a recipe contains many anonymous
  704. functions, they run in the same order as they are defined within the
  705. recipe. As an example, consider the following snippet: python () {
  706. d.setVar('FOO', 'foo 2') } FOO = "foo 1" python () { d.appendVar('BAR',
  707. ' bar 2') } BAR = "bar 1" The previous example is conceptually
  708. equivalent to the following snippet: FOO = "foo 1" BAR = "bar 1" FOO =
  709. "foo 2" BAR += "bar 2" ``FOO`` ends up with the value "foo 2", and
  710. ``BAR`` with the value "bar 1 bar 2". Just as in the second snippet, the
  711. values set for the variables within the anonymous functions become
  712. available to tasks, which always run after parsing.
  713. Overrides and override-style operators such as "``_append``" are applied
  714. before anonymous functions run. In the following example, ``FOO`` ends
  715. up with the value "foo from anonymous": FOO = "foo" FOO_append = " from
  716. outside" python () { d.setVar("FOO", "foo from anonymous") } For methods
  717. you can use with anonymous Python functions, see the "`Functions You Can
  718. Call From Within Python <#functions-you-can-call-from-within-python>`__"
  719. section. For a different method to run Python code during parsing, see
  720. the "`Inline Python Variable
  721. Expansion <#inline-python-variable-expansion>`__" section.
  722. Flexible Inheritance for Class Functions
  723. ----------------------------------------
  724. Through coding techniques and the use of ``EXPORT_FUNCTIONS``, BitBake
  725. supports exporting a function from a class such that the class function
  726. appears as the default implementation of the function, but can still be
  727. called if a recipe inheriting the class needs to define its own version
  728. of the function.
  729. To understand the benefits of this feature, consider the basic scenario
  730. where a class defines a task function and your recipe inherits the
  731. class. In this basic scenario, your recipe inherits the task function as
  732. defined in the class. If desired, your recipe can add to the start and
  733. end of the function by using the "_prepend" or "_append" operations
  734. respectively, or it can redefine the function completely. However, if it
  735. redefines the function, there is no means for it to call the class
  736. version of the function. ``EXPORT_FUNCTIONS`` provides a mechanism that
  737. enables the recipe's version of the function to call the original
  738. version of the function.
  739. To make use of this technique, you need the following things in place:
  740. - The class needs to define the function as follows:
  741. classname\ ``_``\ functionname For example, if you have a class file
  742. ``bar.bbclass`` and a function named ``do_foo``, the class must
  743. define the function as follows: bar_do_foo
  744. - The class needs to contain the ``EXPORT_FUNCTIONS`` statement as
  745. follows: EXPORT_FUNCTIONS functionname For example, continuing with
  746. the same example, the statement in the ``bar.bbclass`` would be as
  747. follows: EXPORT_FUNCTIONS do_foo
  748. - You need to call the function appropriately from within your recipe.
  749. Continuing with the same example, if your recipe needs to call the
  750. class version of the function, it should call ``bar_do_foo``.
  751. Assuming ``do_foo`` was a shell function and ``EXPORT_FUNCTIONS`` was
  752. used as above, the recipe's function could conditionally call the
  753. class version of the function as follows: do_foo() { if [
  754. somecondition ] ; then bar_do_foo else # Do something else fi } To
  755. call your modified version of the function as defined in your recipe,
  756. call it as ``do_foo``.
  757. With these conditions met, your single recipe can freely choose between
  758. the original function as defined in the class file and the modified
  759. function in your recipe. If you do not set up these conditions, you are
  760. limited to using one function or the other.
  761. Tasks
  762. =====
  763. Tasks are BitBake execution units that make up the steps that BitBake
  764. can run for a given recipe. Tasks are only supported in recipes and
  765. classes (i.e. in ``.bb`` files and files included or inherited from
  766. ``.bb`` files). By convention, tasks have names that start with "do_".
  767. Promoting a Function to a Task
  768. ------------------------------
  769. Tasks are either `shell functions <#shell-functions>`__ or
  770. `BitBake-style Python functions <#bitbake-style-python-functions>`__
  771. that have been promoted to tasks by using the ``addtask`` command. The
  772. ``addtask`` command can also optionally describe dependencies between
  773. the task and other tasks. Here is an example that shows how to define a
  774. task and declare some dependencies: python do_printdate () { import time
  775. print time.strftime('%Y%m%d', time.gmtime()) } addtask printdate after
  776. do_fetch before do_build The first argument to ``addtask`` is the name
  777. of the function to promote to a task. If the name does not start with
  778. "do_", "do_" is implicitly added, which enforces the convention that all
  779. task names start with "do_".
  780. In the previous example, the ``do_printdate`` task becomes a dependency
  781. of the ``do_build`` task, which is the default task (i.e. the task run
  782. by the ``bitbake`` command unless another task is specified explicitly).
  783. Additionally, the ``do_printdate`` task becomes dependent upon the
  784. ``do_fetch`` task. Running the ``do_build`` task results in the
  785. ``do_printdate`` task running first.
  786. .. note::
  787. If you try out the previous example, you might see that the
  788. do_printdate
  789. task is only run the first time you build the recipe with the
  790. bitbake
  791. command. This is because BitBake considers the task "up-to-date"
  792. after that initial run. If you want to force the task to always be
  793. rerun for experimentation purposes, you can make BitBake always
  794. consider the task "out-of-date" by using the
  795. :ref:`[nostamp] <bitbake-user-manual/bitbake-user-manual-metadata:Variable Flags>`
  796. variable flag, as follows:
  797. ::
  798. do_printdate[nostamp] = "1"
  799. You can also explicitly run the task and provide the
  800. -f
  801. option as follows:
  802. ::
  803. $ bitbake recipe -c printdate -f
  804. When manually selecting a task to run with the
  805. bitbake
  806. NBSP
  807. recipe
  808. NBSP
  809. -c
  810. NBSP
  811. task
  812. command, you can omit the "do_" prefix as part of the task name.
  813. You might wonder about the practical effects of using ``addtask``
  814. without specifying any dependencies as is done in the following example:
  815. addtask printdate In this example, assuming dependencies have not been
  816. added through some other means, the only way to run the task is by
  817. explicitly selecting it with ``bitbake`` recipe ``-c printdate``. You
  818. can use the ``do_listtasks`` task to list all tasks defined in a recipe
  819. as shown in the following example: $ bitbake recipe -c listtasks For
  820. more information on task dependencies, see the
  821. "`Dependencies <#dependencies>`__" section.
  822. See the "`Variable Flags <#variable-flags>`__" section for information
  823. on variable flags you can use with tasks.
  824. Deleting a Task
  825. ---------------
  826. As well as being able to add tasks, you can delete them. Simply use the
  827. ``deltask`` command to delete a task. For example, to delete the example
  828. task used in the previous sections, you would use: deltask printdate If
  829. you delete a task using the ``deltask`` command and the task has
  830. dependencies, the dependencies are not reconnected. For example, suppose
  831. you have three tasks named ``do_a``, ``do_b``, and ``do_c``.
  832. Furthermore, ``do_c`` is dependent on ``do_b``, which in turn is
  833. dependent on ``do_a``. Given this scenario, if you use ``deltask`` to
  834. delete ``do_b``, the implicit dependency relationship between ``do_c``
  835. and ``do_a`` through ``do_b`` no longer exists, and ``do_c``
  836. dependencies are not updated to include ``do_a``. Thus, ``do_c`` is free
  837. to run before ``do_a``.
  838. If you want dependencies such as these to remain intact, use the
  839. ``[noexec]`` varflag to disable the task instead of using the
  840. ``deltask`` command to delete it: do_b[noexec] = "1"
  841. Passing Information Into the Build Task Environment
  842. ---------------------------------------------------
  843. When running a task, BitBake tightly controls the shell execution
  844. environment of the build tasks to make sure unwanted contamination from
  845. the build machine cannot influence the build.
  846. .. note::
  847. By default, BitBake cleans the environment to include only those
  848. things exported or listed in its whitelist to ensure that the build
  849. environment is reproducible and consistent. You can prevent this
  850. "cleaning" by setting the
  851. :term:`BB_PRESERVE_ENV`
  852. variable.
  853. Consequently, if you do want something to get passed into the build task
  854. environment, you must take these two steps:
  855. 1. Tell BitBake to load what you want from the environment into the
  856. datastore. You can do so through the
  857. :term:`BB_ENV_WHITELIST` and
  858. :term:`BB_ENV_EXTRAWHITE` variables. For
  859. example, assume you want to prevent the build system from accessing
  860. your ``$HOME/.ccache`` directory. The following command "whitelists"
  861. the environment variable ``CCACHE_DIR`` causing BitBake to allow that
  862. variable into the datastore: export
  863. BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE CCACHE_DIR"
  864. 2. Tell BitBake to export what you have loaded into the datastore to the
  865. task environment of every running task. Loading something from the
  866. environment into the datastore (previous step) only makes it
  867. available in the datastore. To export it to the task environment of
  868. every running task, use a command similar to the following in your
  869. local configuration file ``local.conf`` or your distribution
  870. configuration file: export CCACHE_DIR
  871. .. note::
  872. A side effect of the previous steps is that BitBake records the
  873. variable as a dependency of the build process in things like the
  874. setscene checksums. If doing so results in unnecessary rebuilds of
  875. tasks, you can whitelist the variable so that the setscene code
  876. ignores the dependency when it creates checksums.
  877. Sometimes, it is useful to be able to obtain information from the
  878. original execution environment. BitBake saves a copy of the original
  879. environment into a special variable named
  880. :term:`BB_ORIGENV`.
  881. The ``BB_ORIGENV`` variable returns a datastore object that can be
  882. queried using the standard datastore operators such as
  883. ``getVar(, False)``. The datastore object is useful, for example, to
  884. find the original ``DISPLAY`` variable. Here is an example: origenv =
  885. d.getVar("BB_ORIGENV", False) bar = origenv.getVar("BAR", False) The
  886. previous example returns ``BAR`` from the original execution
  887. environment.
  888. Variable Flags
  889. ==============
  890. Variable flags (varflags) help control a task's functionality and
  891. dependencies. BitBake reads and writes varflags to the datastore using
  892. the following command forms: variable = d.getVarFlags("variable")
  893. self.d.setVarFlags("FOO", {"func": True})
  894. When working with varflags, the same syntax, with the exception of
  895. overrides, applies. In other words, you can set, append, and prepend
  896. varflags just like variables. See the "`Variable Flag
  897. Syntax <#variable-flag-syntax>`__" section for details.
  898. BitBake has a defined set of varflags available for recipes and classes.
  899. Tasks support a number of these flags which control various
  900. functionality of the task:
  901. - *``[cleandirs]``:* Empty directories that should be created before
  902. the task runs. Directories that already exist are removed and
  903. recreated to empty them.
  904. - *``[depends]``:* Controls inter-task dependencies. See the
  905. :term:`DEPENDS` variable and the "`Inter-Task
  906. Dependencies <#inter-task-dependencies>`__" section for more
  907. information.
  908. - *``[deptask]``:* Controls task build-time dependencies. See the
  909. :term:`DEPENDS` variable and the "`Build
  910. Dependencies <#build-dependencies>`__" section for more information.
  911. - *``[dirs]``:* Directories that should be created before the task
  912. runs. Directories that already exist are left as is. The last
  913. directory listed is used as the current working directory for the
  914. task.
  915. - *``[lockfiles]``:* Specifies one or more lockfiles to lock while the
  916. task executes. Only one task may hold a lockfile, and any task that
  917. attempts to lock an already locked file will block until the lock is
  918. released. You can use this variable flag to accomplish mutual
  919. exclusion.
  920. - *``[noexec]``:* When set to "1", marks the task as being empty, with
  921. no execution required. You can use the ``[noexec]`` flag to set up
  922. tasks as dependency placeholders, or to disable tasks defined
  923. elsewhere that are not needed in a particular recipe.
  924. - *``[nostamp]``:* When set to "1", tells BitBake to not generate a
  925. stamp file for a task, which implies the task should always be
  926. executed.
  927. .. note::
  928. Any task that depends (possibly indirectly) on a
  929. [nostamp]
  930. task will always be executed as well. This can cause unnecessary
  931. rebuilding if you are not careful.
  932. - *``[number_threads]``:* Limits tasks to a specific number of
  933. simultaneous threads during execution. This varflag is useful when
  934. your build host has a large number of cores but certain tasks need to
  935. be rate-limited due to various kinds of resource constraints (e.g. to
  936. avoid network throttling). ``number_threads`` works similarly to the
  937. :term:`BB_NUMBER_THREADS` variable but is
  938. task-specific.
  939. Set the value globally. For example, the following makes sure the
  940. ``do_fetch`` task uses no more than two simultaneous execution
  941. threads: do_fetch[number_threads] = "2"
  942. .. note::
  943. - Setting the varflag in individual recipes rather than globally
  944. can result in unpredictable behavior.
  945. - Setting the varflag to a value greater than the value used in
  946. the ``BB_NUMBER_THREADS`` variable causes ``number_threads`` to
  947. have no effect.
  948. - *``[postfuncs]``:* List of functions to call after the completion of
  949. the task.
  950. - *``[prefuncs]``:* List of functions to call before the task executes.
  951. - *``[rdepends]``:* Controls inter-task runtime dependencies. See the
  952. :term:`RDEPENDS` variable, the
  953. :term:`RRECOMMENDS` variable, and the
  954. "`Inter-Task Dependencies <#inter-task-dependencies>`__" section for
  955. more information.
  956. - *``[rdeptask]``:* Controls task runtime dependencies. See the
  957. :term:`RDEPENDS` variable, the
  958. :term:`RRECOMMENDS` variable, and the "`Runtime
  959. Dependencies <#runtime-dependencies>`__" section for more
  960. information.
  961. - *``[recideptask]``:* When set in conjunction with ``recrdeptask``,
  962. specifies a task that should be inspected for additional
  963. dependencies.
  964. - *``[recrdeptask]``:* Controls task recursive runtime dependencies.
  965. See the :term:`RDEPENDS` variable, the
  966. :term:`RRECOMMENDS` variable, and the
  967. "`Recursive Dependencies <#recursive-dependencies>`__" section for
  968. more information.
  969. - *``[stamp-extra-info]``:* Extra stamp information to append to the
  970. task's stamp. As an example, OpenEmbedded uses this flag to allow
  971. machine-specific tasks.
  972. - *``[umask]``:* The umask to run the task under.
  973. Several varflags are useful for controlling how signatures are
  974. calculated for variables. For more information on this process, see the
  975. "`Checksums (Signatures) <#checksums>`__" section.
  976. - *``[vardeps]``:* Specifies a space-separated list of additional
  977. variables to add to a variable's dependencies for the purposes of
  978. calculating its signature. Adding variables to this list is useful,
  979. for example, when a function refers to a variable in a manner that
  980. does not allow BitBake to automatically determine that the variable
  981. is referred to.
  982. - *``[vardepsexclude]``:* Specifies a space-separated list of variables
  983. that should be excluded from a variable's dependencies for the
  984. purposes of calculating its signature.
  985. - *``[vardepvalue]``:* If set, instructs BitBake to ignore the actual
  986. value of the variable and instead use the specified value when
  987. calculating the variable's signature.
  988. - *``[vardepvalueexclude]``:* Specifies a pipe-separated list of
  989. strings to exclude from the variable's value when calculating the
  990. variable's signature.
  991. Events
  992. ======
  993. BitBake allows installation of event handlers within recipe and class
  994. files. Events are triggered at certain points during operation, such as
  995. the beginning of operation against a given recipe (i.e. ``*.bb``), the
  996. start of a given task, a task failure, a task success, and so forth. The
  997. intent is to make it easy to do things like email notification on build
  998. failures.
  999. Following is an example event handler that prints the name of the event
  1000. and the content of the ``FILE`` variable: addhandler
  1001. myclass_eventhandler python myclass_eventhandler() { from bb.event
  1002. import getName print("The name of the Event is %s" % getName(e))
  1003. print("The file we run for is %s" % d.getVar('FILE')) }
  1004. myclass_eventhandler[eventmask] = "bb.event.BuildStarted
  1005. bb.event.BuildCompleted" In the previous example, an eventmask has been
  1006. set so that the handler only sees the "BuildStarted" and
  1007. "BuildCompleted" events. This event handler gets called every time an
  1008. event matching the eventmask is triggered. A global variable "e" is
  1009. defined, which represents the current event. With the ``getName(e)``
  1010. method, you can get the name of the triggered event. The global
  1011. datastore is available as "d". In legacy code, you might see "e.data"
  1012. used to get the datastore. However, realize that "e.data" is deprecated
  1013. and you should use "d" going forward.
  1014. The context of the datastore is appropriate to the event in question.
  1015. For example, "BuildStarted" and "BuildCompleted" events run before any
  1016. tasks are executed so would be in the global configuration datastore
  1017. namespace. No recipe-specific metadata exists in that namespace. The
  1018. "BuildStarted" and "BuildCompleted" events also run in the main
  1019. cooker/server process rather than any worker context. Thus, any changes
  1020. made to the datastore would be seen by other cooker/server events within
  1021. the current build but not seen outside of that build or in any worker
  1022. context. Task events run in the actual tasks in question consequently
  1023. have recipe-specific and task-specific contents. These events run in the
  1024. worker context and are discarded at the end of task execution.
  1025. During a standard build, the following common events might occur. The
  1026. following events are the most common kinds of events that most metadata
  1027. might have an interest in viewing:
  1028. - ``bb.event.ConfigParsed()``: Fired when the base configuration; which
  1029. consists of ``bitbake.conf``, ``base.bbclass`` and any global
  1030. ``INHERIT`` statements; has been parsed. You can see multiple such
  1031. events when each of the workers parse the base configuration or if
  1032. the server changes configuration and reparses. Any given datastore
  1033. only has one such event executed against it, however. If
  1034. ```BB_INVALIDCONF`` <#>`__ is set in the datastore by the event
  1035. handler, the configuration is reparsed and a new event triggered,
  1036. allowing the metadata to update configuration.
  1037. - ``bb.event.HeartbeatEvent()``: Fires at regular time intervals of one
  1038. second. You can configure the interval time using the
  1039. ``BB_HEARTBEAT_EVENT`` variable. The event's "time" attribute is the
  1040. ``time.time()`` value when the event is triggered. This event is
  1041. useful for activities such as system state monitoring.
  1042. - ``bb.event.ParseStarted()``: Fired when BitBake is about to start
  1043. parsing recipes. This event's "total" attribute represents the number
  1044. of recipes BitBake plans to parse.
  1045. - ``bb.event.ParseProgress()``: Fired as parsing progresses. This
  1046. event's "current" attribute is the number of recipes parsed as well
  1047. as the "total" attribute.
  1048. - ``bb.event.ParseCompleted()``: Fired when parsing is complete. This
  1049. event's "cached", "parsed", "skipped", "virtuals", "masked", and
  1050. "errors" attributes provide statistics for the parsing results.
  1051. - ``bb.event.BuildStarted()``: Fired when a new build starts. BitBake
  1052. fires multiple "BuildStarted" events (one per configuration) when
  1053. multiple configuration (multiconfig) is enabled.
  1054. - ``bb.build.TaskStarted()``: Fired when a task starts. This event's
  1055. "taskfile" attribute points to the recipe from which the task
  1056. originates. The "taskname" attribute, which is the task's name,
  1057. includes the ``do_`` prefix, and the "logfile" attribute point to
  1058. where the task's output is stored. Finally, the "time" attribute is
  1059. the task's execution start time.
  1060. - ``bb.build.TaskInvalid()``: Fired if BitBake tries to execute a task
  1061. that does not exist.
  1062. - ``bb.build.TaskFailedSilent()``: Fired for setscene tasks that fail
  1063. and should not be presented to the user verbosely.
  1064. - ``bb.build.TaskFailed()``: Fired for normal tasks that fail.
  1065. - ``bb.build.TaskSucceeded()``: Fired when a task successfully
  1066. completes.
  1067. - ``bb.event.BuildCompleted()``: Fired when a build finishes.
  1068. - ``bb.cooker.CookerExit()``: Fired when the BitBake server/cooker
  1069. shuts down. This event is usually only seen by the UIs as a sign they
  1070. should also shutdown.
  1071. This next list of example events occur based on specific requests to the
  1072. server. These events are often used to communicate larger pieces of
  1073. information from the BitBake server to other parts of BitBake such as
  1074. user interfaces:
  1075. - ``bb.event.TreeDataPreparationStarted()``
  1076. - ``bb.event.TreeDataPreparationProgress()``
  1077. - ``bb.event.TreeDataPreparationCompleted()``
  1078. - ``bb.event.DepTreeGenerated()``
  1079. - ``bb.event.CoreBaseFilesFound()``
  1080. - ``bb.event.ConfigFilePathFound()``
  1081. - ``bb.event.FilesMatchingFound()``
  1082. - ``bb.event.ConfigFilesFound()``
  1083. - ``bb.event.TargetsTreeGenerated()``
  1084. .. _variants-class-extension-mechanism:
  1085. Variants - Class Extension Mechanism
  1086. ====================================
  1087. BitBake supports two features that facilitate creating from a single
  1088. recipe file multiple incarnations of that recipe file where all
  1089. incarnations are buildable. These features are enabled through the
  1090. :term:`BBCLASSEXTEND` and
  1091. :term:`BBVERSIONS` variables.
  1092. .. note::
  1093. The mechanism for this class extension is extremely specific to the
  1094. implementation. Usually, the recipe's
  1095. :term:`PROVIDES`
  1096. ,
  1097. :term:`PN`
  1098. , and
  1099. :term:`DEPENDS`
  1100. variables would need to be modified by the extension class. For
  1101. specific examples, see the OE-Core
  1102. native
  1103. ,
  1104. nativesdk
  1105. , and
  1106. multilib
  1107. classes.
  1108. - *``BBCLASSEXTEND``:* This variable is a space separated list of
  1109. classes used to "extend" the recipe for each variant. Here is an
  1110. example that results in a second incarnation of the current recipe
  1111. being available. This second incarnation will have the "native" class
  1112. inherited. BBCLASSEXTEND = "native"
  1113. - *``BBVERSIONS``:* This variable allows a single recipe to build
  1114. multiple versions of a project from a single recipe file. You can
  1115. also specify conditional metadata (using the
  1116. :term:`OVERRIDES` mechanism) for a single
  1117. version, or an optionally named range of versions. Here is an
  1118. example: BBVERSIONS = "1.0 2.0 git" SRC_URI_git =
  1119. "git://someurl/somepath.git" BBVERSIONS = "1.0.[0-6]:1.0.0+ \\
  1120. 1.0.[7-9]:1.0.7+" SRC_URI_append_1.0.7+ =
  1121. "file://some_patch_which_the_new_versions_need.patch;patch=1" The
  1122. name of the range defaults to the original version of the recipe. For
  1123. example, in OpenEmbedded, the recipe file ``foo_1.0.0+.bb`` creates a
  1124. default name range of ``1.0.0+``. This is useful because the range
  1125. name is not only placed into overrides, but it is also made available
  1126. for the metadata to use in the variable that defines the base recipe
  1127. versions for use in ``file://`` search paths
  1128. (:term:`FILESPATH`).
  1129. Dependencies
  1130. ============
  1131. To allow for efficient parallel processing, BitBake handles dependencies
  1132. at the task level. Dependencies can exist both between tasks within a
  1133. single recipe and between tasks in different recipes. Following are
  1134. examples of each:
  1135. - For tasks within a single recipe, a recipe's ``do_configure`` task
  1136. might need to complete before its ``do_compile`` task can run.
  1137. - For tasks in different recipes, one recipe's ``do_configure`` task
  1138. might require another recipe's ``do_populate_sysroot`` task to finish
  1139. first such that the libraries and headers provided by the other
  1140. recipe are available.
  1141. This section describes several ways to declare dependencies. Remember,
  1142. even though dependencies are declared in different ways, they are all
  1143. simply dependencies between tasks.
  1144. .. _dependencies-internal-to-the-bb-file:
  1145. Dependencies Internal to the ``.bb`` File
  1146. -----------------------------------------
  1147. BitBake uses the ``addtask`` directive to manage dependencies that are
  1148. internal to a given recipe file. You can use the ``addtask`` directive
  1149. to indicate when a task is dependent on other tasks or when other tasks
  1150. depend on that recipe. Here is an example: addtask printdate after
  1151. do_fetch before do_build In this example, the ``do_printdate`` task
  1152. depends on the completion of the ``do_fetch`` task, and the ``do_build``
  1153. task depends on the completion of the ``do_printdate`` task.
  1154. .. note::
  1155. For a task to run, it must be a direct or indirect dependency of some
  1156. other task that is scheduled to run.
  1157. For illustration, here are some examples:
  1158. - The directive ``addtask mytask before do_configure`` causes
  1159. ``do_mytask`` to run before ``do_configure`` runs. Be aware that
  1160. ``do_mytask`` still only runs if its `input
  1161. checksum <#checksums>`__ has changed since the last time it was
  1162. run. Changes to the input checksum of ``do_mytask`` also
  1163. indirectly cause ``do_configure`` to run.
  1164. - The directive ``addtask mytask after do_configure`` by itself
  1165. never causes ``do_mytask`` to run. ``do_mytask`` can still be run
  1166. manually as follows: $ bitbake recipe -c mytask Declaring
  1167. ``do_mytask`` as a dependency of some other task that is scheduled
  1168. to run also causes it to run. Regardless, the task runs after
  1169. ``do_configure``.
  1170. Build Dependencies
  1171. ------------------
  1172. BitBake uses the :term:`DEPENDS` variable to manage
  1173. build time dependencies. The ``[deptask]`` varflag for tasks signifies
  1174. the task of each item listed in ``DEPENDS`` that must complete before
  1175. that task can be executed. Here is an example: do_configure[deptask] =
  1176. "do_populate_sysroot" In this example, the ``do_populate_sysroot`` task
  1177. of each item in ``DEPENDS`` must complete before ``do_configure`` can
  1178. execute.
  1179. Runtime Dependencies
  1180. --------------------
  1181. BitBake uses the :term:`PACKAGES`,
  1182. :term:`RDEPENDS`, and
  1183. :term:`RRECOMMENDS` variables to manage runtime
  1184. dependencies.
  1185. The ``PACKAGES`` variable lists runtime packages. Each of those packages
  1186. can have ``RDEPENDS`` and ``RRECOMMENDS`` runtime dependencies. The
  1187. ``[rdeptask]`` flag for tasks is used to signify the task of each item
  1188. runtime dependency which must have completed before that task can be
  1189. executed. do_package_qa[rdeptask] = "do_packagedata" In the previous
  1190. example, the ``do_packagedata`` task of each item in ``RDEPENDS`` must
  1191. have completed before ``do_package_qa`` can execute.
  1192. Although ``RDEPENDS`` contains entries from the
  1193. runtime dependency namespace, BitBake knows how to map them back
  1194. to the build-time dependency namespace, in which the tasks are defined.
  1195. Recursive Dependencies
  1196. ----------------------
  1197. BitBake uses the ``[recrdeptask]`` flag to manage recursive task
  1198. dependencies. BitBake looks through the build-time and runtime
  1199. dependencies of the current recipe, looks through the task's inter-task
  1200. dependencies, and then adds dependencies for the listed task. Once
  1201. BitBake has accomplished this, it recursively works through the
  1202. dependencies of those tasks. Iterative passes continue until all
  1203. dependencies are discovered and added.
  1204. The ``[recrdeptask]`` flag is most commonly used in high-level recipes
  1205. that need to wait for some task to finish "globally". For example,
  1206. ``image.bbclass`` has the following: do_rootfs[recrdeptask] +=
  1207. "do_packagedata" This statement says that the ``do_packagedata`` task of
  1208. the current recipe and all recipes reachable (by way of dependencies)
  1209. from the image recipe must run before the ``do_rootfs`` task can run.
  1210. BitBake allows a task to recursively depend on itself by
  1211. referencing itself in the task list:
  1212. do_a[recrdeptask] = "do_a do_b"
  1213. In the same way as before, this means that the ``do_a``
  1214. and ``do_b`` tasks of the current recipe and all
  1215. recipes reachable (by way of dependencies) from the recipe
  1216. must run before the ``do_a`` task can run. In this
  1217. case BitBake will ignore the current recipe's ``do_a``
  1218. task circular dependency on itself.
  1219. Inter-Task Dependencies
  1220. -----------------------
  1221. BitBake uses the ``[depends]`` flag in a more generic form to manage
  1222. inter-task dependencies. This more generic form allows for
  1223. inter-dependency checks for specific tasks rather than checks for the
  1224. data in ``DEPENDS``. Here is an example: do_patch[depends] =
  1225. "quilt-native:do_populate_sysroot" In this example, the
  1226. ``do_populate_sysroot`` task of the target ``quilt-native`` must have
  1227. completed before the ``do_patch`` task can execute.
  1228. The ``[rdepends]`` flag works in a similar way but takes targets in the
  1229. runtime namespace instead of the build-time dependency namespace.
  1230. Functions You Can Call From Within Python
  1231. =========================================
  1232. BitBake provides many functions you can call from within Python
  1233. functions. This section lists the most commonly used functions, and
  1234. mentions where to find others.
  1235. Functions for Accessing Datastore Variables
  1236. -------------------------------------------
  1237. It is often necessary to access variables in the BitBake datastore using
  1238. Python functions. The BitBake datastore has an API that allows you this
  1239. access. Here is a list of available operations:
  1240. +-----------------------------------+-----------------------------------+
  1241. | *Operation* | *Description* |
  1242. +===================================+===================================+
  1243. | ``d.getVar("X", expand)`` | Returns the value of variable |
  1244. | | "X". Using "expand=True" expands |
  1245. | | the value. Returns "None" if the |
  1246. | | variable "X" does not exist. |
  1247. +-----------------------------------+-----------------------------------+
  1248. | ``d.setVar("X", "value")`` | Sets the variable "X" to "value". |
  1249. +-----------------------------------+-----------------------------------+
  1250. | ``d.appendVar("X", "value")`` | Adds "value" to the end of the |
  1251. | | variable "X". Acts like |
  1252. | | ``d.setVar("X", "value")`` if the |
  1253. | | variable "X" does not exist. |
  1254. +-----------------------------------+-----------------------------------+
  1255. | ``d.prependVar("X", "value")`` | Adds "value" to the start of the |
  1256. | | variable "X". Acts like |
  1257. | | ``d.setVar("X", "value")`` if the |
  1258. | | variable "X" does not exist. |
  1259. +-----------------------------------+-----------------------------------+
  1260. | ``d.delVar("X")`` | Deletes the variable "X" from the |
  1261. | | datastore. Does nothing if the |
  1262. | | variable "X" does not exist. |
  1263. +-----------------------------------+-----------------------------------+
  1264. | ``d.renameVar("X", "Y")`` | Renames the variable "X" to "Y". |
  1265. | | Does nothing if the variable "X" |
  1266. | | does not exist. |
  1267. +-----------------------------------+-----------------------------------+
  1268. | `` | Returns the value of variable |
  1269. | d.getVarFlag("X", flag, expand)`` | "X". Using "expand=True" expands |
  1270. | | the value. Returns "None" if |
  1271. | | either the variable "X" or the |
  1272. | | named flag does not exist. |
  1273. +-----------------------------------+-----------------------------------+
  1274. | ``d | Sets the named flag for variable |
  1275. | .setVarFlag("X", flag, "value")`` | "X" to "value". |
  1276. +-----------------------------------+-----------------------------------+
  1277. | ``d.ap | Appends "value" to the named flag |
  1278. | pendVarFlag("X", flag, "value")`` | on the variable "X". Acts like |
  1279. | | ``d |
  1280. | | .setVarFlag("X", flag, "value")`` |
  1281. | | if the named flag does not exist. |
  1282. +-----------------------------------+-----------------------------------+
  1283. | ``d.pre | Prepends "value" to the named |
  1284. | pendVarFlag("X", flag, "value")`` | flag on the variable "X". Acts |
  1285. | | like |
  1286. | | ``d |
  1287. | | .setVarFlag("X", flag, "value")`` |
  1288. | | if the named flag does not exist. |
  1289. +-----------------------------------+-----------------------------------+
  1290. | ``d.delVarFlag("X", flag)`` | Deletes the named flag on the |
  1291. | | variable "X" from the datastore. |
  1292. +-----------------------------------+-----------------------------------+
  1293. | ``d.setVarFlags("X", flagsdict)`` | Sets the flags specified in the |
  1294. | | ``flagsdict()`` parameter. |
  1295. | | ``setVarFlags`` does not clear |
  1296. | | previous flags. Think of this |
  1297. | | operation as ``addVarFlags``. |
  1298. +-----------------------------------+-----------------------------------+
  1299. | ``d.getVarFlags("X")`` | Returns a ``flagsdict`` of the |
  1300. | | flags for the variable "X". |
  1301. | | Returns "None" if the variable |
  1302. | | "X" does not exist. |
  1303. +-----------------------------------+-----------------------------------+
  1304. | ``d.delVarFlags("X")`` | Deletes all the flags for the |
  1305. | | variable "X". Does nothing if the |
  1306. | | variable "X" does not exist. |
  1307. +-----------------------------------+-----------------------------------+
  1308. | ``d.expand(expression)`` | Expands variable references in |
  1309. | | the specified string expression. |
  1310. | | References to variables that do |
  1311. | | not exist are left as is. For |
  1312. | | example, ``d.expand("foo ${X}")`` |
  1313. | | expands to the literal string |
  1314. | | "foo ${X}" if the variable "X" |
  1315. | | does not exist. |
  1316. +-----------------------------------+-----------------------------------+
  1317. Other Functions
  1318. ---------------
  1319. You can find many other functions that can be called from Python by
  1320. looking at the source code of the ``bb`` module, which is in
  1321. ``bitbake/lib/bb``. For example, ``bitbake/lib/bb/utils.py`` includes
  1322. the commonly used functions ``bb.utils.contains()`` and
  1323. ``bb.utils.mkdirhier()``, which come with docstrings.
  1324. Task Checksums and Setscene
  1325. ===========================
  1326. BitBake uses checksums (or signatures) along with the setscene to
  1327. determine if a task needs to be run. This section describes the process.
  1328. To help understand how BitBake does this, the section assumes an
  1329. OpenEmbedded metadata-based example.
  1330. These checksums are stored in :term:`STAMP`. You can
  1331. examine the checksums using the following BitBake command: $
  1332. bitbake-dumpsigs This command returns the signature data in a readable
  1333. format that allows you to examine the inputs used when the OpenEmbedded
  1334. build system generates signatures. For example, using
  1335. ``bitbake-dumpsigs`` allows you to examine the ``do_compile`` task's
  1336. “sigdata” for a C application (e.g. ``bash``). Running the command also
  1337. reveals that the “CC” variable is part of the inputs that are hashed.
  1338. Any changes to this variable would invalidate the stamp and cause the
  1339. ``do_compile`` task to run.
  1340. The following list describes related variables:
  1341. - :term:`BB_HASHCHECK_FUNCTION`:
  1342. Specifies the name of the function to call during the "setscene" part
  1343. of the task's execution in order to validate the list of task hashes.
  1344. - :term:`BB_SETSCENE_DEPVALID`:
  1345. Specifies a function BitBake calls that determines whether BitBake
  1346. requires a setscene dependency to be met.
  1347. - :term:`BB_SETSCENE_VERIFY_FUNCTION2`:
  1348. Specifies a function to call that verifies the list of planned task
  1349. execution before the main task execution happens.
  1350. - :term:`BB_STAMP_POLICY`: Defines the mode
  1351. for comparing timestamps of stamp files.
  1352. - :term:`BB_STAMP_WHITELIST`: Lists stamp
  1353. files that are looked at when the stamp policy is "whitelist".
  1354. - :term:`BB_TASKHASH`: Within an executing task,
  1355. this variable holds the hash of the task as returned by the currently
  1356. enabled signature generator.
  1357. - :term:`STAMP`: The base path to create stamp files.
  1358. - :term:`STAMPCLEAN`: Again, the base path to
  1359. create stamp files but can use wildcards for matching a range of
  1360. files for clean operations.
  1361. Wildcard Support in Variables
  1362. =============================
  1363. Support for wildcard use in variables varies depending on the context in
  1364. which it is used. For example, some variables and file names allow
  1365. limited use of wildcards through the "``%``" and "``*``" characters.
  1366. Other variables or names support Python's
  1367. ```glob`https://docs.python.org/3/library/glob.html syntax,
  1368. ```fnmatch`https://docs.python.org/3/library/fnmatch.html#module-fnmatch
  1369. syntax, or
  1370. ```Regular Expression (re)`https://docs.python.org/3/library/re.html#re
  1371. syntax.
  1372. For variables that have wildcard suport, the documentation describes
  1373. which form of wildcard, its use, and its limitations.