bitbake-user-manual-metadata.rst 73 KB

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