bitbake-user-manual-metadata.xml 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  3. <chapter id="bitbake-user-manual-metadata">
  4. <title>Syntax and Operators</title>
  5. <para>
  6. Bitbake files have their own syntax.
  7. The syntax has similarities to several
  8. other languages but also has some unique features.
  9. This section describes the available syntax and operators
  10. as well as provides examples.
  11. </para>
  12. <section id='basic-syntax'>
  13. <title>Basic Syntax</title>
  14. <para>
  15. This section provides some basic syntax examples.
  16. </para>
  17. <section id='basic-variable-setting'>
  18. <title>Basic Variable Setting</title>
  19. <para>
  20. The following example sets <filename>VARIABLE</filename> to
  21. "value".
  22. This assignment occurs immediately as the statement is parsed.
  23. It is a "hard" assignment.
  24. <literallayout class='monospaced'>
  25. VARIABLE = "value"
  26. </literallayout>
  27. As expected, if you include leading or trailing spaces as part of
  28. an assignment, the spaces are retained:
  29. <literallayout class='monospaced'>
  30. VARIABLE = " value"
  31. VARIABLE = "value "
  32. </literallayout>
  33. Setting <filename>VARIABLE</filename> to "" sets it to an empty string,
  34. while setting the variable to " " sets it to a blank space
  35. (i.e. these are not the same values).
  36. <literallayout class='monospaced'>
  37. VARIABLE = ""
  38. VARIABLE = " "
  39. </literallayout>
  40. </para>
  41. <para>
  42. You can use single quotes instead of double quotes
  43. when setting a variable's value.
  44. Doing so allows you to use values that contain the double
  45. quote character:
  46. <literallayout class='monospaced'>
  47. VARIABLE = 'I have a " in my value'
  48. </literallayout>
  49. <note>
  50. Unlike in Bourne shells, single quotes work identically
  51. to double quotes in all other ways.
  52. They do not suppress variable expansions.
  53. </note>
  54. </para>
  55. </section>
  56. <section id='line-joining'>
  57. <title>Line Joining</title>
  58. <para>
  59. Outside of
  60. <link linkend='functions'>functions</link>, BitBake joins
  61. any line ending in a backslash character ("\")
  62. with the following line before parsing statements.
  63. The most common use for the "\" character is to split variable
  64. assignments over multiple lines, as in the following example:
  65. <literallayout class='monospaced'>
  66. FOO = "bar \
  67. baz \
  68. qaz"
  69. </literallayout>
  70. Both the "\" character and the newline character
  71. that follow it are removed when joining lines.
  72. Thus, no newline characters end up in the value of
  73. <filename>FOO</filename>.
  74. </para>
  75. <para>
  76. Consider this additional example where the two
  77. assignments both assign "barbaz" to
  78. <filename>FOO</filename>:
  79. <literallayout class='monospaced'>
  80. FOO = "barbaz"
  81. FOO = "bar\
  82. baz"
  83. </literallayout>
  84. <note>
  85. BitBake does not interpret escape sequences like
  86. "\n" in variable values.
  87. For these to have an effect, the value must be passed
  88. to some utility that interprets escape sequences,
  89. such as <filename>printf</filename> or
  90. <filename>echo -n</filename>.
  91. </note>
  92. </para>
  93. </section>
  94. <section id='variable-expansion'>
  95. <title>Variable Expansion</title>
  96. <para>
  97. Variables can reference the contents of other variables
  98. using a syntax that is similar to variable expansion in
  99. Bourne shells.
  100. The following assignments
  101. result in A containing "aval" and B evaluating to "preavalpost".
  102. <literallayout class='monospaced'>
  103. A = "aval"
  104. B = "pre${A}post"
  105. </literallayout>
  106. <note>
  107. Unlike in Bourne shells, the curly braces are mandatory:
  108. Only <filename>${FOO}</filename> and not
  109. <filename>$FOO</filename> is recognized as an expansion of
  110. <filename>FOO</filename>.
  111. </note>
  112. The "=" operator does not immediately expand variable
  113. references in the right-hand side.
  114. Instead, expansion is deferred until the variable assigned to
  115. is actually used.
  116. The result depends on the current values of the referenced
  117. variables.
  118. The following example should clarify this behavior:
  119. <literallayout class='monospaced'>
  120. A = "${B} baz"
  121. B = "${C} bar"
  122. C = "foo"
  123. *At this point, ${A} equals "foo bar baz"*
  124. C = "qux"
  125. *At this point, ${A} equals "qux bar baz"*
  126. B = "norf"
  127. *At this point, ${A} equals "norf baz"*
  128. </literallayout>
  129. Contrast this behavior with the
  130. <link linkend='immediate-variable-expansion'>immediate variable expansion</link>
  131. operator (i.e. ":=").
  132. </para>
  133. <para>
  134. If the variable expansion syntax is used on a variable that
  135. does not exist, the string is kept as is.
  136. For example, given the following assignment,
  137. <filename>BAR</filename> expands to the literal string
  138. "${FOO}" as long as <filename>FOO</filename> does not exist.
  139. <literallayout class='monospaced'>
  140. BAR = "${FOO}"
  141. </literallayout>
  142. </para>
  143. </section>
  144. <section id='setting-a-default-value'>
  145. <title>Setting a default value (?=)</title>
  146. <para>
  147. You can use the "?=" operator to achieve a "softer" assignment
  148. for a variable.
  149. This type of assignment allows you to define a variable if it
  150. is undefined when the statement is parsed, but to leave the
  151. value alone if the variable has a value.
  152. Here is an example:
  153. <literallayout class='monospaced'>
  154. A ?= "aval"
  155. </literallayout>
  156. If <filename>A</filename> is set at the time this statement is parsed,
  157. the variable retains its value.
  158. However, if <filename>A</filename> is not set,
  159. the variable is set to "aval".
  160. <note>
  161. This assignment is immediate.
  162. Consequently, if multiple "?=" assignments
  163. to a single variable exist, the first of those ends up getting
  164. used.
  165. </note>
  166. </para>
  167. </section>
  168. <section id='setting-a-weak-default-value'>
  169. <title>Setting a weak default value (??=)</title>
  170. <para>
  171. It is possible to use a "weaker" assignment than in the
  172. previous section by using the "??=" operator.
  173. This assignment behaves identical to "?=" except that the
  174. assignment is made at the end of the parsing process rather
  175. than immediately.
  176. Consequently, when multiple "??=" assignments exist, the last
  177. one is used.
  178. Also, any "=" or "?=" assignment will override the value set with
  179. "??=".
  180. Here is an example:
  181. <literallayout class='monospaced'>
  182. A ??= "somevalue"
  183. A ??= "someothervalue"
  184. </literallayout>
  185. If <filename>A</filename> is set before the above statements are parsed,
  186. the variable retains its value.
  187. If <filename>A</filename> is not set,
  188. the variable is set to "someothervalue".
  189. </para>
  190. <para>
  191. Again, this assignment is a "lazy" or "weak" assignment
  192. because it does not occur until the end
  193. of the parsing process.
  194. </para>
  195. </section>
  196. <section id='immediate-variable-expansion'>
  197. <title>Immediate variable expansion (:=)</title>
  198. <para>
  199. The ":=" operator results in a variable's
  200. contents being expanded immediately,
  201. rather than when the variable is actually used:
  202. <literallayout class='monospaced'>
  203. T = "123"
  204. A := "${B} ${A} test ${T}"
  205. T = "456"
  206. B = "${T} bval"
  207. C = "cval"
  208. C := "${C}append"
  209. </literallayout>
  210. In this example, <filename>A</filename> contains
  211. "test 123" because <filename>${B}</filename> and
  212. <filename>${A}</filename> at the time of parsing are undefined,
  213. which leaves "test 123".
  214. And, the variable <filename>C</filename>
  215. contains "cvalappend" since <filename>${C}</filename> immediately
  216. expands to "cval".
  217. </para>
  218. </section>
  219. <section id='appending-and-prepending'>
  220. <title>Appending (+=) and prepending (=+) With Spaces</title>
  221. <para>
  222. Appending and prepending values is common and can be accomplished
  223. using the "+=" and "=+" operators.
  224. These operators insert a space between the current
  225. value and prepended or appended value.
  226. </para>
  227. <para>
  228. These operators take immediate effect during parsing.
  229. Here are some examples:
  230. <literallayout class='monospaced'>
  231. B = "bval"
  232. B += "additionaldata"
  233. C = "cval"
  234. C =+ "test"
  235. </literallayout>
  236. The variable <filename>B</filename> contains
  237. "bval additionaldata" and <filename>C</filename>
  238. contains "test cval".
  239. </para>
  240. </section>
  241. <section id='appending-and-prepending-without-spaces'>
  242. <title>Appending (.=) and Prepending (=.) Without Spaces</title>
  243. <para>
  244. If you want to append or prepend values without an
  245. inserted space, use the ".=" and "=." operators.
  246. </para>
  247. <para>
  248. These operators take immediate effect during parsing.
  249. Here are some examples:
  250. <literallayout class='monospaced'>
  251. B = "bval"
  252. B .= "additionaldata"
  253. C = "cval"
  254. C =. "test"
  255. </literallayout>
  256. The variable <filename>B</filename> contains
  257. "bvaladditionaldata" and
  258. <filename>C</filename> contains "testcval".
  259. </para>
  260. </section>
  261. <section id='appending-and-prepending-override-style-syntax'>
  262. <title>Appending and Prepending (Override Style Syntax)</title>
  263. <para>
  264. You can also append and prepend a variable's value
  265. using an override style syntax.
  266. When you use this syntax, no spaces are inserted.
  267. </para>
  268. <para>
  269. These operators differ from the ":=", ".=", "=.", "+=", and "=+"
  270. operators in that their effects are deferred
  271. until after parsing completes rather than being immediately
  272. applied.
  273. Here are some examples:
  274. <literallayout class='monospaced'>
  275. B = "bval"
  276. B_append = " additional data"
  277. C = "cval"
  278. C_prepend = "additional data "
  279. D = "dval"
  280. D_append = "additional data"
  281. </literallayout>
  282. The variable <filename>B</filename> becomes
  283. "bval additional data" and <filename>C</filename> becomes
  284. "additional data cval".
  285. The variable <filename>D</filename> becomes
  286. "dvaladditional data".
  287. <note>
  288. You must control all spacing when you use the
  289. override syntax.
  290. </note>
  291. </para>
  292. <para>
  293. It is also possible to append and prepend to shell
  294. functions and BitBake-style Python functions.
  295. See the
  296. "<link linkend='shell-functions'>Shell Functions</link>" and
  297. "<link linkend='bitbake-style-python-functions'>BitBake-Style Python Functions</link>
  298. sections for examples.
  299. </para>
  300. </section>
  301. <section id='removing-override-style-syntax'>
  302. <title>Removal (Override Style Syntax)</title>
  303. <para>
  304. You can remove values from lists using the removal
  305. override style syntax.
  306. Specifying a value for removal causes all occurrences of that
  307. value to be removed from the variable.
  308. </para>
  309. <para>
  310. When you use this syntax, BitBake expects one or more strings.
  311. Surrounding spaces and spacing are preserved.
  312. Here is an example:
  313. <literallayout class='monospaced'>
  314. FOO = "123 456 789 123456 123 456 123 456"
  315. FOO_remove = "123"
  316. FOO_remove = "456"
  317. FOO2 = "abc def ghi abcdef abc def abc def"
  318. FOO2_remove = "abc def"
  319. </literallayout>
  320. The variable <filename>FOO</filename> becomes
  321. "&nbsp;&nbsp;789 123456&nbsp;&nbsp;&nbsp;&nbsp;"
  322. and <filename>FOO2</filename> becomes
  323. "&nbsp;&nbsp;ghi abcdef&nbsp;&nbsp;&nbsp;&nbsp;".
  324. </para>
  325. <para>
  326. Like "_append" and "_prepend", "_remove"
  327. is deferred until after parsing completes.
  328. </para>
  329. </section>
  330. <section id='override-style-operation-advantages'>
  331. <title>Override Style Operation Advantages</title>
  332. <para>
  333. An advantage of the override style operations
  334. "_append", "_prepend", and "_remove" as compared to the
  335. "+=" and "=+" operators is that the override style
  336. operators provide guaranteed operations.
  337. For example, consider a class <filename>foo.bbclass</filename>
  338. that needs to add the value "val" to the variable
  339. <filename>FOO</filename>, and a recipe that uses
  340. <filename>foo.bbclass</filename> as follows:
  341. <literallayout class='monospaced'>
  342. inherit foo
  343. FOO = "initial"
  344. </literallayout>
  345. If <filename>foo.bbclass</filename> uses the "+=" operator,
  346. as follows, then the final value of <filename>FOO</filename>
  347. will be "initial", which is not what is desired:
  348. <literallayout class='monospaced'>
  349. FOO += "val"
  350. </literallayout>
  351. If, on the other hand, <filename>foo.bbclass</filename>
  352. uses the "_append" operator, then the final value of
  353. <filename>FOO</filename> will be "initial val", as intended:
  354. <literallayout class='monospaced'>
  355. FOO_append = " val"
  356. </literallayout>
  357. <note>
  358. It is never necessary to use "+=" together with "_append".
  359. The following sequence of assignments appends "barbaz" to
  360. <filename>FOO</filename>:
  361. <literallayout class='monospaced'>
  362. FOO_append = "bar"
  363. FOO_append = "baz"
  364. </literallayout>
  365. The only effect of changing the second assignment in the
  366. previous example to use "+=" would be to add a space before
  367. "baz" in the appended value (due to how the "+=" operator
  368. works).
  369. </note>
  370. Another advantage of the override style operations is that
  371. you can combine them with other overrides as described in the
  372. "<link linkend='conditional-syntax-overrides'>Conditional Syntax (Overrides)</link>"
  373. section.
  374. </para>
  375. </section>
  376. <section id='variable-flag-syntax'>
  377. <title>Variable Flag Syntax</title>
  378. <para>
  379. Variable flags are BitBake's implementation of variable properties
  380. or attributes.
  381. It is a way of tagging extra information onto a variable.
  382. You can find more out about variable flags in general in the
  383. "<link linkend='variable-flags'>Variable Flags</link>"
  384. section.
  385. </para>
  386. <para>
  387. You can define, append, and prepend values to variable flags.
  388. All the standard syntax operations previously mentioned work
  389. for variable flags except for override style syntax
  390. (i.e. "_prepend", "_append", and "_remove").
  391. </para>
  392. <para>
  393. Here are some examples showing how to set variable flags:
  394. <literallayout class='monospaced'>
  395. FOO[a] = "abc"
  396. FOO[b] = "123"
  397. FOO[a] += "456"
  398. </literallayout>
  399. The variable <filename>FOO</filename> has two flags:
  400. <filename>[a]</filename> and <filename>[b]</filename>.
  401. The flags are immediately set to "abc" and "123", respectively.
  402. The <filename>[a]</filename> flag becomes "abc 456".
  403. </para>
  404. <para>
  405. No need exists to pre-define variable flags.
  406. You can simply start using them.
  407. One extremely common application
  408. is to attach some brief documentation to a BitBake variable as
  409. follows:
  410. <literallayout class='monospaced'>
  411. CACHE[doc] = "The directory holding the cache of the metadata."
  412. </literallayout>
  413. </para>
  414. </section>
  415. <section id='inline-python-variable-expansion'>
  416. <title>Inline Python Variable Expansion</title>
  417. <para>
  418. You can use inline Python variable expansion to
  419. set variables.
  420. Here is an example:
  421. <literallayout class='monospaced'>
  422. DATE = "${@time.strftime('%Y%m%d',time.gmtime())}"
  423. </literallayout>
  424. This example results in the <filename>DATE</filename>
  425. variable being set to the current date.
  426. </para>
  427. <para>
  428. Probably the most common use of this feature is to extract
  429. the value of variables from BitBake's internal data dictionary,
  430. <filename>d</filename>.
  431. The following lines select the values of a package name
  432. and its version number, respectively:
  433. <literallayout class='monospaced'>
  434. PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
  435. PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[1] or '1.0'}"
  436. </literallayout>
  437. <note>
  438. Inline Python expressions work just like variable expansions
  439. insofar as the "=" and ":=" operators are concerned.
  440. Given the following assignment, <filename>foo()</filename>
  441. is called each time <filename>FOO</filename> is expanded:
  442. <literallayout class='monospaced'>
  443. FOO = "${@foo()}"
  444. </literallayout>
  445. Contrast this with the following immediate assignment, where
  446. <filename>foo()</filename> is only called once, while the
  447. assignment is parsed:
  448. <literallayout class='monospaced'>
  449. FOO := "${@foo()}"
  450. </literallayout>
  451. </note>
  452. For a different way to set variables with Python code during
  453. parsing, see the
  454. "<link linkend='anonymous-python-functions'>Anonymous Python Functions</link>"
  455. section.
  456. </para>
  457. </section>
  458. <section id='unsetting-variables'>
  459. <title>Unsetting variables</title>
  460. <para>
  461. It is possible to completely remove a variable or a variable flag
  462. from BitBake's internal data dictionary by using the "unset" keyword.
  463. Here is an example:
  464. <literallayout class='monospaced'>
  465. unset DATE
  466. unset do_fetch[noexec]
  467. </literallayout>
  468. These two statements remove the <filename>DATE</filename> and the
  469. <filename>do_fetch[noexec]</filename> flag.
  470. </para>
  471. </section>
  472. <section id='providing-pathnames'>
  473. <title>Providing Pathnames</title>
  474. <para>
  475. When specifying pathnames for use with BitBake,
  476. do not use the tilde ("~") character as a shortcut
  477. for your home directory.
  478. Doing so might cause BitBake to not recognize the
  479. path since BitBake does not expand this character in
  480. the same way a shell would.
  481. </para>
  482. <para>
  483. Instead, provide a fuller path as the following
  484. example illustrates:
  485. <literallayout class='monospaced'>
  486. BBLAYERS ?= " \
  487. /home/scott-lenovo/LayerA \
  488. "
  489. </literallayout>
  490. </para>
  491. </section>
  492. </section>
  493. <section id='exporting-variables-to-the-environment'>
  494. <title>Exporting Variables to the Environment</title>
  495. <para>
  496. You can export variables to the environment of running
  497. tasks by using the <filename>export</filename> keyword.
  498. For example, in the following example, the
  499. <filename>do_foo</filename> task prints "value from
  500. the environment" when run:
  501. <literallayout class='monospaced'>
  502. export ENV_VARIABLE
  503. ENV_VARIABLE = "value from the environment"
  504. do_foo() {
  505. bbplain "$ENV_VARIABLE"
  506. }
  507. </literallayout>
  508. <note>
  509. BitBake does not expand <filename>$ENV_VARIABLE</filename>
  510. in this case because it lacks the obligatory
  511. <filename>{}</filename>.
  512. Rather, <filename>$ENV_VARIABLE</filename> is expanded
  513. by the shell.
  514. </note>
  515. It does not matter whether
  516. <filename>export ENV_VARIABLE</filename> appears before or
  517. after assignments to <filename>ENV_VARIABLE</filename>.
  518. </para>
  519. <para>
  520. It is also possible to combine <filename>export</filename>
  521. with setting a value for the variable.
  522. Here is an example:
  523. <literallayout class='monospaced'>
  524. export ENV_VARIABLE = "<replaceable>variable-value</replaceable>"
  525. </literallayout>
  526. In the output of <filename>bitbake -e</filename>, variables
  527. that are exported to the environment are preceded by "export".
  528. </para>
  529. <para>
  530. Among the variables commonly exported to the environment
  531. are <filename>CC</filename> and <filename>CFLAGS</filename>,
  532. which are picked up by many build systems.
  533. </para>
  534. </section>
  535. <section id='conditional-syntax-overrides'>
  536. <title>Conditional Syntax (Overrides)</title>
  537. <para>
  538. BitBake uses
  539. <link linkend='var-OVERRIDES'><filename>OVERRIDES</filename></link>
  540. to control what variables are overridden after BitBake
  541. parses recipes and configuration files.
  542. This section describes how you can use
  543. <filename>OVERRIDES</filename> as conditional metadata,
  544. talks about key expansion in relationship to
  545. <filename>OVERRIDES</filename>, and provides some examples
  546. to help with understanding.
  547. </para>
  548. <section id='conditional-metadata'>
  549. <title>Conditional Metadata</title>
  550. <para>
  551. You can use <filename>OVERRIDES</filename> to conditionally select
  552. a specific version of a variable and to conditionally
  553. append or prepend the value of a variable.
  554. <note>
  555. Overrides can only use lower-case characters.
  556. Additionally, underscores are not permitted in override names
  557. as they are used to separate overrides from each other and
  558. from the variable name.
  559. </note>
  560. <itemizedlist>
  561. <listitem><para><emphasis>Selecting a Variable:</emphasis>
  562. The <filename>OVERRIDES</filename> variable is
  563. a colon-character-separated list that contains items
  564. for which you want to satisfy conditions.
  565. Thus, if you have a variable that is conditional on “arm”, and “arm”
  566. is in <filename>OVERRIDES</filename>, then the “arm”-specific
  567. version of the variable is used rather than the non-conditional
  568. version.
  569. Here is an example:
  570. <literallayout class='monospaced'>
  571. OVERRIDES = "architecture:os:machine"
  572. TEST = "default"
  573. TEST_os = "osspecific"
  574. TEST_nooverride = "othercondvalue"
  575. </literallayout>
  576. In this example, the <filename>OVERRIDES</filename>
  577. variable lists three overrides:
  578. "architecture", "os", and "machine".
  579. The variable <filename>TEST</filename> by itself has a default
  580. value of "default".
  581. You select the os-specific version of the <filename>TEST</filename>
  582. variable by appending the "os" override to the variable
  583. (i.e.<filename>TEST_os</filename>).
  584. </para>
  585. <para>
  586. To better understand this, consider a practical example
  587. that assumes an OpenEmbedded metadata-based Linux
  588. kernel recipe file.
  589. The following lines from the recipe file first set
  590. the kernel branch variable <filename>KBRANCH</filename>
  591. to a default value, then conditionally override that
  592. value based on the architecture of the build:
  593. <literallayout class='monospaced'>
  594. KBRANCH = "standard/base"
  595. KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
  596. KBRANCH_qemumips = "standard/mti-malta32"
  597. KBRANCH_qemuppc = "standard/qemuppc"
  598. KBRANCH_qemux86 = "standard/common-pc/base"
  599. KBRANCH_qemux86-64 = "standard/common-pc-64/base"
  600. KBRANCH_qemumips64 = "standard/mti-malta64"
  601. </literallayout>
  602. </para></listitem>
  603. <listitem><para><emphasis>Appending and Prepending:</emphasis>
  604. BitBake also supports append and prepend operations to
  605. variable values based on whether a specific item is
  606. listed in <filename>OVERRIDES</filename>.
  607. Here is an example:
  608. <literallayout class='monospaced'>
  609. DEPENDS = "glibc ncurses"
  610. OVERRIDES = "machine:local"
  611. DEPENDS_append_machine = " libmad"
  612. </literallayout>
  613. In this example, <filename>DEPENDS</filename> becomes
  614. "glibc ncurses libmad".
  615. </para>
  616. <para>
  617. Again, using an OpenEmbedded metadata-based
  618. kernel recipe file as an example, the
  619. following lines will conditionally append to the
  620. <filename>KERNEL_FEATURES</filename> variable based
  621. on the architecture:
  622. <literallayout class='monospaced'>
  623. KERNEL_FEATURES_append = " ${KERNEL_EXTRA_FEATURES}"
  624. KERNEL_FEATURES_append_qemux86=" cfg/sound.scc cfg/paravirt_kvm.scc"
  625. KERNEL_FEATURES_append_qemux86-64=" cfg/sound.scc cfg/paravirt_kvm.scc"
  626. </literallayout>
  627. </para></listitem>
  628. <listitem><para><emphasis>Setting a Variable for a Single Task:</emphasis>
  629. BitBake supports setting a variable just for the
  630. duration of a single task.
  631. Here is an example:
  632. <literallayout class='monospaced'>
  633. FOO_task-configure = "val 1"
  634. FOO_task-compile = "val 2"
  635. </literallayout>
  636. In the previous example, <filename>FOO</filename>
  637. has the value "val 1" while the
  638. <filename>do_configure</filename> task is executed,
  639. and the value "val 2" while the
  640. <filename>do_compile</filename> task is executed.
  641. </para>
  642. <para>Internally, this is implemented by prepending
  643. the task (e.g. "task-compile:") to the value of
  644. <link linkend='var-OVERRIDES'><filename>OVERRIDES</filename></link>
  645. for the local datastore of the <filename>do_compile</filename>
  646. task.</para>
  647. <para>You can also use this syntax with other combinations
  648. (e.g. "<filename>_prepend</filename>") as shown in the
  649. following example:
  650. <literallayout class='monospaced'>
  651. EXTRA_OEMAKE_prepend_task-compile = "${PARALLEL_MAKE} "
  652. </literallayout>
  653. </para></listitem>
  654. </itemizedlist>
  655. </para>
  656. </section>
  657. <section id='key-expansion'>
  658. <title>Key Expansion</title>
  659. <para>
  660. Key expansion happens when the BitBake datastore is finalized
  661. just before BitBake expands overrides.
  662. To better understand this, consider the following example:
  663. <literallayout class='monospaced'>
  664. A${B} = "X"
  665. B = "2"
  666. A2 = "Y"
  667. </literallayout>
  668. In this case, after all the parsing is complete, and
  669. before any overrides are handled, BitBake expands
  670. <filename>${B}</filename> into "2".
  671. This expansion causes <filename>A2</filename>, which was
  672. set to "Y" before the expansion, to become "X".
  673. </para>
  674. </section>
  675. <section id='variable-interaction-worked-examples'>
  676. <title>Examples</title>
  677. <para>
  678. Despite the previous explanations that show the different forms of
  679. variable definitions, it can be hard to work
  680. out exactly what happens when variable operators, conditional
  681. overrides, and unconditional overrides are combined.
  682. This section presents some common scenarios along
  683. with explanations for variable interactions that
  684. typically confuse users.
  685. </para>
  686. <para>
  687. There is often confusion concerning the order in which
  688. overrides and various "append" operators take effect.
  689. Recall that an append or prepend operation using "_append"
  690. and "_prepend" does not result in an immediate assignment
  691. as would "+=", ".=", "=+", or "=.".
  692. Consider the following example:
  693. <literallayout class='monospaced'>
  694. OVERRIDES = "foo"
  695. A = "Z"
  696. A_foo_append = "X"
  697. </literallayout>
  698. For this case, <filename>A</filename> is
  699. unconditionally set to "Z" and "X" is
  700. unconditionally and immediately appended to the variable
  701. <filename>A_foo</filename>.
  702. Because overrides have not been applied yet,
  703. <filename>A_foo</filename> is set to "X" due to the append
  704. and <filename>A</filename> simply equals "Z".
  705. </para>
  706. <para>
  707. Applying overrides, however, changes things.
  708. Since "foo" is listed in <filename>OVERRIDES</filename>,
  709. the conditional variable <filename>A</filename> is replaced
  710. with the "foo" version, which is equal to "X".
  711. So effectively, <filename>A_foo</filename> replaces <filename>A</filename>.
  712. </para>
  713. <para>
  714. This next example changes the order of the override and
  715. the append:
  716. <literallayout class='monospaced'>
  717. OVERRIDES = "foo"
  718. A = "Z"
  719. A_append_foo = "X"
  720. </literallayout>
  721. For this case, before overrides are handled,
  722. <filename>A</filename> is set to "Z" and <filename>A_append_foo</filename>
  723. is set to "X".
  724. Once the override for "foo" is applied, however,
  725. <filename>A</filename> gets appended with "X".
  726. Consequently, <filename>A</filename> becomes "ZX".
  727. Notice that spaces are not appended.
  728. </para>
  729. <para>
  730. This next example has the order of the appends and overrides reversed
  731. back as in the first example:
  732. <literallayout class='monospaced'>
  733. OVERRIDES = "foo"
  734. A = "Y"
  735. A_foo_append = "Z"
  736. A_foo_append = "X"
  737. </literallayout>
  738. For this case, before any overrides are resolved,
  739. <filename>A</filename> is set to "Y" using an immediate assignment.
  740. After this immediate assignment, <filename>A_foo</filename> is set
  741. to "Z", and then further appended with
  742. "X" leaving the variable set to "ZX".
  743. Finally, applying the override for "foo" results in the conditional
  744. variable <filename>A</filename> becoming "ZX" (i.e.
  745. <filename>A</filename> is replaced with <filename>A_foo</filename>).
  746. </para>
  747. <para>
  748. This final example mixes in some varying operators:
  749. <literallayout class='monospaced'>
  750. A = "1"
  751. A_append = "2"
  752. A_append = "3"
  753. A += "4"
  754. A .= "5"
  755. </literallayout>
  756. For this case, the type of append operators are affecting the
  757. order of assignments as BitBake passes through the code
  758. multiple times.
  759. Initially, <filename>A</filename> is set to "1 45" because
  760. of the three statements that use immediate operators.
  761. After these assignments are made, BitBake applies the
  762. "_append" operations.
  763. Those operations result in <filename>A</filename> becoming "1 4523".
  764. </para>
  765. </section>
  766. </section>
  767. <section id='sharing-functionality'>
  768. <title>Sharing Functionality</title>
  769. <para>
  770. BitBake allows for metadata sharing through include files
  771. (<filename>.inc</filename>) and class files
  772. (<filename>.bbclass</filename>).
  773. For example, suppose you have a piece of common functionality
  774. such as a task definition that you want to share between
  775. more than one recipe.
  776. In this case, creating a <filename>.bbclass</filename>
  777. file that contains the common functionality and then using
  778. the <filename>inherit</filename> directive in your recipes to
  779. inherit the class would be a common way to share the task.
  780. </para>
  781. <para>
  782. This section presents the mechanisms BitBake provides to
  783. allow you to share functionality between recipes.
  784. Specifically, the mechanisms include <filename>include</filename>,
  785. <filename>inherit</filename>, <filename>INHERIT</filename>, and
  786. <filename>require</filename> directives.
  787. </para>
  788. <section id='locating-include-and-class-files'>
  789. <title>Locating Include and Class Files</title>
  790. <para>
  791. BitBake uses the
  792. <link linkend='var-BBPATH'><filename>BBPATH</filename></link>
  793. variable to locate needed include and class files.
  794. Additionally, BitBake searches the current directory for
  795. <filename>include</filename> and <filename>require</filename>
  796. directives.
  797. <note>
  798. The <filename>BBPATH</filename> variable is analogous to
  799. the environment variable <filename>PATH</filename>.
  800. </note>
  801. </para>
  802. <para>
  803. In order for include and class files to be found by BitBake,
  804. they need to be located in a "classes" subdirectory that can
  805. be found in <filename>BBPATH</filename>.
  806. </para>
  807. </section>
  808. <section id='inherit-directive'>
  809. <title><filename>inherit</filename> Directive</title>
  810. <para>
  811. When writing a recipe or class file, you can use the
  812. <filename>inherit</filename> directive to inherit the
  813. functionality of a class (<filename>.bbclass</filename>).
  814. BitBake only supports this directive when used within recipe
  815. and class files (i.e. <filename>.bb</filename> and
  816. <filename>.bbclass</filename>).
  817. </para>
  818. <para>
  819. The <filename>inherit</filename> directive is a rudimentary
  820. means of specifying functionality contained in class files
  821. that your recipes require.
  822. For example, you can easily abstract out the tasks involved in
  823. building a package that uses Autoconf and Automake and put
  824. those tasks into a class file and then have your recipe
  825. inherit that class file.
  826. </para>
  827. <para>
  828. As an example, your recipes could use the following directive
  829. to inherit an <filename>autotools.bbclass</filename> file.
  830. The class file would contain common functionality for using
  831. Autotools that could be shared across recipes:
  832. <literallayout class='monospaced'>
  833. inherit autotools
  834. </literallayout>
  835. In this case, BitBake would search for the directory
  836. <filename>classes/autotools.bbclass</filename>
  837. in <filename>BBPATH</filename>.
  838. <note>
  839. You can override any values and functions of the
  840. inherited class within your recipe by doing so
  841. after the "inherit" statement.
  842. </note>
  843. If you want to use the directive to inherit
  844. multiple classes, separate them with spaces.
  845. The following example shows how to inherit both the
  846. <filename>buildhistory</filename> and <filename>rm_work</filename>
  847. classes:
  848. <literallayout class='monospaced'>
  849. inherit buildhistory rm_work
  850. </literallayout>
  851. </para>
  852. <para>
  853. An advantage with the inherit directive as compared to both
  854. the
  855. <link linkend='include-directive'>include</link> and
  856. <link linkend='require-inclusion'>require</link> directives
  857. is that you can inherit class files conditionally.
  858. You can accomplish this by using a variable expression
  859. after the <filename>inherit</filename> statement.
  860. Here is an example:
  861. <literallayout class='monospaced'>
  862. inherit ${VARNAME}
  863. </literallayout>
  864. If <filename>VARNAME</filename> is going to be set, it needs
  865. to be set before the <filename>inherit</filename> statement
  866. is parsed.
  867. One way to achieve a conditional inherit in this case is to use
  868. overrides:
  869. <literallayout class='monospaced'>
  870. VARIABLE = ""
  871. VARIABLE_someoverride = "myclass"
  872. </literallayout>
  873. </para>
  874. <para>
  875. Another method is by using anonymous Python.
  876. Here is an example:
  877. <literallayout class='monospaced'>
  878. python () {
  879. if condition == value:
  880. d.setVar('VARIABLE', 'myclass')
  881. else:
  882. d.setVar('VARIABLE', '')
  883. }
  884. </literallayout>
  885. </para>
  886. <para>
  887. Alternatively, you could use an in-line Python expression
  888. in the following form:
  889. <literallayout class='monospaced'>
  890. inherit ${@'classname' if condition else ''}
  891. inherit ${@functionname(params)}
  892. </literallayout>
  893. In all cases, if the expression evaluates to an empty
  894. string, the statement does not trigger a syntax error
  895. because it becomes a no-op.
  896. </para>
  897. </section>
  898. <section id='include-directive'>
  899. <title><filename>include</filename> Directive</title>
  900. <para>
  901. BitBake understands the <filename>include</filename>
  902. directive.
  903. This directive causes BitBake to parse whatever file you specify,
  904. and to insert that file at that location.
  905. The directive is much like its equivalent in Make except
  906. that if the path specified on the include line is a relative
  907. path, BitBake locates the first file it can find
  908. within <filename>BBPATH</filename>.
  909. </para>
  910. <para>
  911. The include directive is a more generic method of including
  912. functionality as compared to the
  913. <link linkend='inherit-directive'>inherit</link> directive,
  914. which is restricted to class (i.e. <filename>.bbclass</filename>)
  915. files.
  916. The include directive is applicable for any other kind of
  917. shared or encapsulated functionality or configuration that
  918. does not suit a <filename>.bbclass</filename> file.
  919. </para>
  920. <para>
  921. As an example, suppose you needed a recipe to include some
  922. self-test definitions:
  923. <literallayout class='monospaced'>
  924. include test_defs.inc
  925. </literallayout>
  926. <note>
  927. The <filename>include</filename> directive does not
  928. produce an error when the file cannot be found.
  929. Consequently, it is recommended that if the file you
  930. are including is expected to exist, you should use
  931. <link linkend='require-inclusion'><filename>require</filename></link>
  932. instead of <filename>include</filename>.
  933. Doing so makes sure that an error is produced if the
  934. file cannot be found.
  935. </note>
  936. </para>
  937. </section>
  938. <section id='require-inclusion'>
  939. <title><filename>require</filename> Directive</title>
  940. <para>
  941. BitBake understands the <filename>require</filename>
  942. directive.
  943. This directive behaves just like the
  944. <filename>include</filename> directive with the exception that
  945. BitBake raises a parsing error if the file to be included cannot
  946. be found.
  947. Thus, any file you require is inserted into the file that is
  948. being parsed at the location of the directive.
  949. </para>
  950. <para>
  951. The require directive, like the include directive previously
  952. described, is a more generic method of including
  953. functionality as compared to the
  954. <link linkend='inherit-directive'>inherit</link> directive,
  955. which is restricted to class (i.e. <filename>.bbclass</filename>)
  956. files.
  957. The require directive is applicable for any other kind of
  958. shared or encapsulated functionality or configuration that
  959. does not suit a <filename>.bbclass</filename> file.
  960. </para>
  961. <para>
  962. Similar to how BitBake handles
  963. <link linkend='include-directive'><filename>include</filename></link>,
  964. if the path specified
  965. on the require line is a relative path, BitBake locates
  966. the first file it can find within <filename>BBPATH</filename>.
  967. </para>
  968. <para>
  969. As an example, suppose you have two versions of a recipe
  970. (e.g. <filename>foo_1.2.2.bb</filename> and
  971. <filename>foo_2.0.0.bb</filename>) where
  972. each version contains some identical functionality that could be
  973. shared.
  974. You could create an include file named <filename>foo.inc</filename>
  975. that contains the common definitions needed to build "foo".
  976. You need to be sure <filename>foo.inc</filename> is located in the
  977. same directory as your two recipe files as well.
  978. Once these conditions are set up, you can share the functionality
  979. using a <filename>require</filename> directive from within each
  980. recipe:
  981. <literallayout class='monospaced'>
  982. require foo.inc
  983. </literallayout>
  984. </para>
  985. </section>
  986. <section id='inherit-configuration-directive'>
  987. <title><filename>INHERIT</filename> Configuration Directive</title>
  988. <para>
  989. When creating a configuration file (<filename>.conf</filename>),
  990. you can use the
  991. <link linkend='var-INHERIT'><filename>INHERIT</filename></link>
  992. configuration directive to inherit a class.
  993. BitBake only supports this directive when used within
  994. a configuration file.
  995. </para>
  996. <para>
  997. As an example, suppose you needed to inherit a class
  998. file called <filename>abc.bbclass</filename> from a
  999. configuration file as follows:
  1000. <literallayout class='monospaced'>
  1001. INHERIT += "abc"
  1002. </literallayout>
  1003. This configuration directive causes the named
  1004. class to be inherited at the point of the directive
  1005. during parsing.
  1006. As with the <filename>inherit</filename> directive, the
  1007. <filename>.bbclass</filename> file must be located in a
  1008. "classes" subdirectory in one of the directories specified
  1009. in <filename>BBPATH</filename>.
  1010. <note>
  1011. Because <filename>.conf</filename> files are parsed
  1012. first during BitBake's execution, using
  1013. <filename>INHERIT</filename> to inherit a class effectively
  1014. inherits the class globally (i.e. for all recipes).
  1015. </note>
  1016. If you want to use the directive to inherit
  1017. multiple classes, you can provide them on the same line in the
  1018. <filename>local.conf</filename> file.
  1019. Use spaces to separate the classes.
  1020. The following example shows how to inherit both the
  1021. <filename>autotools</filename> and <filename>pkgconfig</filename>
  1022. classes:
  1023. <literallayout class='monospaced'>
  1024. INHERIT += "autotools pkgconfig"
  1025. </literallayout>
  1026. </para>
  1027. </section>
  1028. </section>
  1029. <section id='functions'>
  1030. <title>Functions</title>
  1031. <para>
  1032. As with most languages, functions are the building blocks that
  1033. are used to build up operations into tasks.
  1034. BitBake supports these types of functions:
  1035. <itemizedlist>
  1036. <listitem><para><emphasis>Shell Functions:</emphasis>
  1037. Functions written in shell script and executed either
  1038. directly as functions, tasks, or both.
  1039. They can also be called by other shell functions.
  1040. </para></listitem>
  1041. <listitem><para><emphasis>BitBake-Style Python Functions:</emphasis>
  1042. Functions written in Python and executed by BitBake or other
  1043. Python functions using <filename>bb.build.exec_func()</filename>.
  1044. </para></listitem>
  1045. <listitem><para><emphasis>Python Functions:</emphasis>
  1046. Functions written in Python and executed by Python.
  1047. </para></listitem>
  1048. <listitem><para><emphasis>Anonymous Python Functions:</emphasis>
  1049. Python functions executed automatically during
  1050. parsing.
  1051. </para></listitem>
  1052. </itemizedlist>
  1053. Regardless of the type of function, you can only
  1054. define them in class (<filename>.bbclass</filename>)
  1055. and recipe (<filename>.bb</filename> or <filename>.inc</filename>)
  1056. files.
  1057. </para>
  1058. <section id='shell-functions'>
  1059. <title>Shell Functions</title>
  1060. <para>
  1061. Functions written in shell script and executed either
  1062. directly as functions, tasks, or both.
  1063. They can also be called by other shell functions.
  1064. Here is an example shell function definition:
  1065. <literallayout class='monospaced'>
  1066. some_function () {
  1067. echo "Hello World"
  1068. }
  1069. </literallayout>
  1070. When you create these types of functions in your recipe
  1071. or class files, you need to follow the shell programming
  1072. rules.
  1073. The scripts are executed by <filename>/bin/sh</filename>,
  1074. which may not be a bash shell but might be something
  1075. such as <filename>dash</filename>.
  1076. You should not use Bash-specific script (bashisms).
  1077. </para>
  1078. <para>
  1079. Overrides and override-style operators like
  1080. <filename>_append</filename> and
  1081. <filename>_prepend</filename> can also be applied to
  1082. shell functions.
  1083. Most commonly, this application would be used in a
  1084. <filename>.bbappend</filename> file to modify functions in
  1085. the main recipe.
  1086. It can also be used to modify functions inherited from
  1087. classes.
  1088. </para>
  1089. <para>
  1090. As an example, consider the following:
  1091. <literallayout class='monospaced'>
  1092. do_foo() {
  1093. bbplain first
  1094. fn
  1095. }
  1096. fn_prepend() {
  1097. bbplain second
  1098. }
  1099. fn() {
  1100. bbplain third
  1101. }
  1102. do_foo_append() {
  1103. bbplain fourth
  1104. }
  1105. </literallayout>
  1106. Running <filename>do_foo</filename>
  1107. prints the following:
  1108. <literallayout class='monospaced'>
  1109. recipename do_foo: first
  1110. recipename do_foo: second
  1111. recipename do_foo: third
  1112. recipename do_foo: fourth
  1113. </literallayout>
  1114. <note>
  1115. Overrides and override-style operators can
  1116. be applied to any shell function, not just
  1117. <link linkend='tasks'>tasks</link>.
  1118. </note>
  1119. You can use the <filename>bitbake -e</filename>&nbsp;<replaceable>recipename</replaceable>
  1120. command to view the final assembled function
  1121. after all overrides have been applied.
  1122. </para>
  1123. </section>
  1124. <section id='bitbake-style-python-functions'>
  1125. <title>BitBake-Style Python Functions</title>
  1126. <para>
  1127. These functions are written in Python and executed by
  1128. BitBake or other Python functions using
  1129. <filename>bb.build.exec_func()</filename>.
  1130. </para>
  1131. <para>
  1132. An example BitBake function is:
  1133. <literallayout class='monospaced'>
  1134. python some_python_function () {
  1135. d.setVar("TEXT", "Hello World")
  1136. print d.getVar("TEXT")
  1137. }
  1138. </literallayout>
  1139. Because the Python "bb" and "os" modules are already
  1140. imported, you do not need to import these modules.
  1141. Also in these types of functions, the datastore ("d")
  1142. is a global variable and is always automatically
  1143. available.
  1144. <note>
  1145. Variable expressions (e.g. <filename>${X}</filename>)
  1146. are no longer expanded within Python functions.
  1147. This behavior is intentional in order to allow you
  1148. to freely set variable values to expandable expressions
  1149. without having them expanded prematurely.
  1150. If you do wish to expand a variable within a Python
  1151. function, use <filename>d.getVar("X")</filename>.
  1152. Or, for more complicated expressions, use
  1153. <filename>d.expand()</filename>.
  1154. </note>
  1155. </para>
  1156. <para>
  1157. Similar to shell functions, you can also apply overrides
  1158. and override-style operators to BitBake-style Python
  1159. functions.
  1160. </para>
  1161. <para>
  1162. As an example, consider the following:
  1163. <literallayout class='monospaced'>
  1164. python do_foo_prepend() {
  1165. bb.plain("first")
  1166. }
  1167. python do_foo() {
  1168. bb.plain("second")
  1169. }
  1170. python do_foo_append() {
  1171. bb.plain("third")
  1172. }
  1173. </literallayout>
  1174. Running <filename>do_foo</filename> prints
  1175. the following:
  1176. <literallayout class='monospaced'>
  1177. recipename do_foo: first
  1178. recipename do_foo: second
  1179. recipename do_foo: third
  1180. </literallayout>
  1181. You can use the <filename>bitbake -e</filename>&nbsp;<replaceable>recipename</replaceable>
  1182. command to view the final assembled function
  1183. after all overrides have been applied.
  1184. </para>
  1185. </section>
  1186. <section id='python-functions'>
  1187. <title>Python Functions</title>
  1188. <para>
  1189. These functions are written in Python and are executed by
  1190. other Python code.
  1191. Examples of Python functions are utility functions
  1192. that you intend to call from in-line Python or
  1193. from within other Python functions.
  1194. Here is an example:
  1195. <literallayout class='monospaced'>
  1196. def get_depends(d):
  1197. if d.getVar('SOMECONDITION'):
  1198. return "dependencywithcond"
  1199. else:
  1200. return "dependency"
  1201. SOMECONDITION = "1"
  1202. DEPENDS = "${@get_depends(d)}"
  1203. </literallayout>
  1204. This would result in <filename>DEPENDS</filename>
  1205. containing <filename>dependencywithcond</filename>.
  1206. </para>
  1207. <para>
  1208. Here are some things to know about Python functions:
  1209. <itemizedlist>
  1210. <listitem><para>Python functions can take parameters.
  1211. </para></listitem>
  1212. <listitem><para>The BitBake datastore is not
  1213. automatically available.
  1214. Consequently, you must pass it in as a
  1215. parameter to the function.
  1216. </para></listitem>
  1217. <listitem><para>The "bb" and "os" Python modules are
  1218. automatically available.
  1219. You do not need to import them.
  1220. </para></listitem>
  1221. </itemizedlist>
  1222. </para>
  1223. </section>
  1224. <section id='bitbake-style-python-functions-versus-python-functions'>
  1225. <title>Bitbake-Style Python Functions Versus Python Functions</title>
  1226. <para>
  1227. Following are some important differences between
  1228. BitBake-style Python functions and regular Python
  1229. functions defined with "def":
  1230. <itemizedlist>
  1231. <listitem><para>
  1232. Only BitBake-style Python functions can be
  1233. <link linkend='tasks'>tasks</link>.
  1234. </para></listitem>
  1235. <listitem><para>
  1236. Overrides and override-style operators can only
  1237. be applied to BitBake-style Python functions.
  1238. </para></listitem>
  1239. <listitem><para>
  1240. Only regular Python functions can take arguments
  1241. and return values.
  1242. </para></listitem>
  1243. <listitem><para>
  1244. <link linkend='variable-flags'>Variable flags</link>
  1245. such as <filename>[dirs]</filename>,
  1246. <filename>[cleandirs]</filename>, and
  1247. <filename>[lockfiles]</filename> can be used
  1248. on BitBake-style Python functions, but not on
  1249. regular Python functions.
  1250. </para></listitem>
  1251. <listitem><para>
  1252. BitBake-style Python functions generate a separate
  1253. <filename>${</filename><link linkend='var-T'><filename>T</filename></link><filename>}/run.</filename><replaceable>function-name</replaceable><filename>.</filename><replaceable>pid</replaceable>
  1254. script that is executed to run the function, and also
  1255. generate a log file in
  1256. <filename>${T}/log.</filename><replaceable>function-name</replaceable><filename>.</filename><replaceable>pid</replaceable>
  1257. if they are executed as tasks.</para>
  1258. <para>
  1259. Regular Python functions execute "inline" and do not
  1260. generate any files in <filename>${T}</filename>.
  1261. </para></listitem>
  1262. <listitem><para>
  1263. Regular Python functions are called with the usual
  1264. Python syntax.
  1265. BitBake-style Python functions are usually tasks and
  1266. are called directly by BitBake, but can also be called
  1267. manually from Python code by using the
  1268. <filename>bb.build.exec_func()</filename> function.
  1269. Here is an example:
  1270. <literallayout class='monospaced'>
  1271. bb.build.exec_func("my_bitbake_style_function", d)
  1272. </literallayout>
  1273. <note>
  1274. <filename>bb.build.exec_func()</filename> can also
  1275. be used to run shell functions from Python code.
  1276. If you want to run a shell function before a Python
  1277. function within the same task, then you can use a
  1278. parent helper Python function that starts by running
  1279. the shell function with
  1280. <filename>bb.build.exec_func()</filename> and then
  1281. runs the Python code.
  1282. </note></para>
  1283. <para>To detect errors from functions executed with
  1284. <filename>bb.build.exec_func()</filename>, you
  1285. can catch the <filename>bb.build.FuncFailed</filename>
  1286. exception.
  1287. <note>
  1288. Functions in metadata (recipes and classes) should
  1289. not themselves raise
  1290. <filename>bb.build.FuncFailed</filename>.
  1291. Rather, <filename>bb.build.FuncFailed</filename>
  1292. should be viewed as a general indicator that the
  1293. called function failed by raising an exception.
  1294. For example, an exception raised by
  1295. <filename>bb.fatal()</filename> will be caught inside
  1296. <filename>bb.build.exec_func()</filename>, and a
  1297. <filename>bb.build.FuncFailed</filename> will be raised
  1298. in response.
  1299. </note>
  1300. </para></listitem>
  1301. </itemizedlist>
  1302. </para>
  1303. <para>
  1304. Due to their simplicity, you should prefer regular Python functions
  1305. over BitBake-style Python functions unless you need a feature specific
  1306. to BitBake-style Python functions.
  1307. Regular Python functions in metadata are a more recent invention than
  1308. BitBake-style Python functions, and older code tends to use
  1309. <filename>bb.build.exec_func()</filename> more often.
  1310. </para>
  1311. </section>
  1312. <section id='anonymous-python-functions'>
  1313. <title>Anonymous Python Functions</title>
  1314. <para>
  1315. Sometimes it is useful to set variables or perform
  1316. other operations programmatically during parsing.
  1317. To do this, you can define special Python functions,
  1318. called anonymous Python functions, that run at the
  1319. end of parsing.
  1320. For example, the following conditionally sets a variable
  1321. based on the value of another variable:
  1322. <literallayout class='monospaced'>
  1323. python () {
  1324. if d.getVar('SOMEVAR') == 'value':
  1325. d.setVar('ANOTHERVAR', 'value2')
  1326. }
  1327. </literallayout>
  1328. An equivalent way to mark a function as an anonymous
  1329. function is to give it the name "__anonymous", rather
  1330. than no name.
  1331. </para>
  1332. <para>
  1333. Anonymous Python functions always run at the end
  1334. of parsing, regardless of where they are defined.
  1335. If a recipe contains many anonymous functions, they
  1336. run in the same order as they are defined within the
  1337. recipe.
  1338. As an example, consider the following snippet:
  1339. <literallayout class='monospaced'>
  1340. python () {
  1341. d.setVar('FOO', 'foo 2')
  1342. }
  1343. FOO = "foo 1"
  1344. python () {
  1345. d.appendVar('BAR', ' bar 2')
  1346. }
  1347. BAR = "bar 1"
  1348. </literallayout>
  1349. The previous example is conceptually equivalent to the
  1350. following snippet:
  1351. <literallayout class='monospaced'>
  1352. FOO = "foo 1"
  1353. BAR = "bar 1"
  1354. FOO = "foo 2"
  1355. BAR += "bar 2"
  1356. </literallayout>
  1357. <filename>FOO</filename> ends up with the value "foo 2",
  1358. and <filename>BAR</filename> with the value "bar 1 bar 2".
  1359. Just as in the second snippet, the values set for the
  1360. variables within the anonymous functions become available
  1361. to tasks, which always run after parsing.
  1362. </para>
  1363. <para>
  1364. Overrides and override-style operators such as
  1365. "<filename>_append</filename>" are applied before
  1366. anonymous functions run.
  1367. In the following example, <filename>FOO</filename> ends
  1368. up with the value "foo from anonymous":
  1369. <literallayout class='monospaced'>
  1370. FOO = "foo"
  1371. FOO_append = " from outside"
  1372. python () {
  1373. d.setVar("FOO", "foo from anonymous")
  1374. }
  1375. </literallayout>
  1376. For methods you can use with anonymous Python functions,
  1377. see the
  1378. "<link linkend='functions-you-can-call-from-within-python'>Functions You Can Call From Within Python</link>"
  1379. section.
  1380. For a different method to run Python code during parsing,
  1381. see the
  1382. "<link linkend='inline-python-variable-expansion'>Inline Python Variable Expansion</link>"
  1383. section.
  1384. </para>
  1385. </section>
  1386. <section id='flexible-inheritance-for-class-functions'>
  1387. <title>Flexible Inheritance for Class Functions</title>
  1388. <para>
  1389. Through coding techniques and the use of
  1390. <filename>EXPORT_FUNCTIONS</filename>, BitBake supports
  1391. exporting a function from a class such that the
  1392. class function appears as the default implementation
  1393. of the function, but can still be called if a recipe
  1394. inheriting the class needs to define its own version of
  1395. the function.
  1396. </para>
  1397. <para>
  1398. To understand the benefits of this feature, consider
  1399. the basic scenario where a class defines a task function
  1400. and your recipe inherits the class.
  1401. In this basic scenario, your recipe inherits the task
  1402. function as defined in the class.
  1403. If desired, your recipe can add to the start and end of the
  1404. function by using the "_prepend" or "_append" operations
  1405. respectively, or it can redefine the function completely.
  1406. However, if it redefines the function, there is
  1407. no means for it to call the class version of the function.
  1408. <filename>EXPORT_FUNCTIONS</filename> provides a mechanism
  1409. that enables the recipe's version of the function to call
  1410. the original version of the function.
  1411. </para>
  1412. <para>
  1413. To make use of this technique, you need the following
  1414. things in place:
  1415. <itemizedlist>
  1416. <listitem><para>
  1417. The class needs to define the function as follows:
  1418. <literallayout class='monospaced'>
  1419. <replaceable>classname</replaceable><filename>_</filename><replaceable>functionname</replaceable>
  1420. </literallayout>
  1421. For example, if you have a class file
  1422. <filename>bar.bbclass</filename> and a function named
  1423. <filename>do_foo</filename>, the class must define the function
  1424. as follows:
  1425. <literallayout class='monospaced'>
  1426. bar_do_foo
  1427. </literallayout>
  1428. </para></listitem>
  1429. <listitem><para>
  1430. The class needs to contain the <filename>EXPORT_FUNCTIONS</filename>
  1431. statement as follows:
  1432. <literallayout class='monospaced'>
  1433. EXPORT_FUNCTIONS <replaceable>functionname</replaceable>
  1434. </literallayout>
  1435. For example, continuing with the same example, the
  1436. statement in the <filename>bar.bbclass</filename> would be
  1437. as follows:
  1438. <literallayout class='monospaced'>
  1439. EXPORT_FUNCTIONS do_foo
  1440. </literallayout>
  1441. </para></listitem>
  1442. <listitem><para>
  1443. You need to call the function appropriately from within your
  1444. recipe.
  1445. Continuing with the same example, if your recipe
  1446. needs to call the class version of the function,
  1447. it should call <filename>bar_do_foo</filename>.
  1448. Assuming <filename>do_foo</filename> was a shell function
  1449. and <filename>EXPORT_FUNCTIONS</filename> was used as above,
  1450. the recipe's function could conditionally call the
  1451. class version of the function as follows:
  1452. <literallayout class='monospaced'>
  1453. do_foo() {
  1454. if [ somecondition ] ; then
  1455. bar_do_foo
  1456. else
  1457. # Do something else
  1458. fi
  1459. }
  1460. </literallayout>
  1461. To call your modified version of the function as defined
  1462. in your recipe, call it as <filename>do_foo</filename>.
  1463. </para></listitem>
  1464. </itemizedlist>
  1465. With these conditions met, your single recipe
  1466. can freely choose between the original function
  1467. as defined in the class file and the modified function in your recipe.
  1468. If you do not set up these conditions, you are limited to using one function
  1469. or the other.
  1470. </para>
  1471. </section>
  1472. </section>
  1473. <section id='tasks'>
  1474. <title>Tasks</title>
  1475. <para>
  1476. Tasks are BitBake execution units that make up the
  1477. steps that BitBake can run for a given recipe.
  1478. Tasks are only supported in recipes and classes
  1479. (i.e. in <filename>.bb</filename> files and files
  1480. included or inherited from <filename>.bb</filename>
  1481. files).
  1482. By convention, tasks have names that start with "do_".
  1483. </para>
  1484. <section id='promoting-a-function-to-a-task'>
  1485. <title>Promoting a Function to a Task</title>
  1486. <para>
  1487. Tasks are either
  1488. <link linkend='shell-functions'>shell functions</link> or
  1489. <link linkend='bitbake-style-python-functions'>BitBake-style Python functions</link>
  1490. that have been promoted to tasks by using the
  1491. <filename>addtask</filename> command.
  1492. The <filename>addtask</filename> command can also
  1493. optionally describe dependencies between the
  1494. task and other tasks.
  1495. Here is an example that shows how to define a task
  1496. and declare some dependencies:
  1497. <literallayout class='monospaced'>
  1498. python do_printdate () {
  1499. import time
  1500. print time.strftime('%Y%m%d', time.gmtime())
  1501. }
  1502. addtask printdate after do_fetch before do_build
  1503. </literallayout>
  1504. The first argument to <filename>addtask</filename>
  1505. is the name of the function to promote to
  1506. a task.
  1507. If the name does not start with "do_", "do_" is
  1508. implicitly added, which enforces the convention that
  1509. all task names start with "do_".
  1510. </para>
  1511. <para>
  1512. In the previous example, the
  1513. <filename>do_printdate</filename> task becomes a
  1514. dependency of the <filename>do_build</filename>
  1515. task, which is the default task (i.e. the task run by
  1516. the <filename>bitbake</filename> command unless
  1517. another task is specified explicitly).
  1518. Additionally, the <filename>do_printdate</filename>
  1519. task becomes dependent upon the
  1520. <filename>do_fetch</filename> task.
  1521. Running the <filename>do_build</filename> task
  1522. results in the <filename>do_printdate</filename>
  1523. task running first.
  1524. <note>
  1525. If you try out the previous example, you might see that
  1526. the <filename>do_printdate</filename> task is only run
  1527. the first time you build the recipe with
  1528. the <filename>bitbake</filename> command.
  1529. This is because BitBake considers the task "up-to-date"
  1530. after that initial run.
  1531. If you want to force the task to always be rerun for
  1532. experimentation purposes, you can make BitBake always
  1533. consider the task "out-of-date" by using the
  1534. <filename>[</filename><link linkend='variable-flags'><filename>nostamp</filename></link><filename>]</filename>
  1535. variable flag, as follows:
  1536. <literallayout class='monospaced'>
  1537. do_printdate[nostamp] = "1"
  1538. </literallayout>
  1539. You can also explicitly run the task and provide the
  1540. <filename>-f</filename> option as follows:
  1541. <literallayout class='monospaced'>
  1542. $ bitbake <replaceable>recipe</replaceable> -c printdate -f
  1543. </literallayout>
  1544. When manually selecting a task to run with the
  1545. <filename>bitbake</filename>&nbsp;<replaceable>recipe</replaceable>&nbsp;<filename>-c</filename>&nbsp;<replaceable>task</replaceable>
  1546. command, you can omit the "do_" prefix as part of the
  1547. task name.
  1548. </note>
  1549. </para>
  1550. <para>
  1551. You might wonder about the practical effects of using
  1552. <filename>addtask</filename> without specifying any
  1553. dependencies as is done in the following example:
  1554. <literallayout class='monospaced'>
  1555. addtask printdate
  1556. </literallayout>
  1557. In this example, assuming dependencies have not been
  1558. added through some other means, the only way to run
  1559. the task is by explicitly selecting it with
  1560. <filename>bitbake</filename>&nbsp;<replaceable>recipe</replaceable>&nbsp;<filename>-c printdate</filename>.
  1561. You can use the
  1562. <filename>do_listtasks</filename> task to list all tasks
  1563. defined in a recipe as shown in the following example:
  1564. <literallayout class='monospaced'>
  1565. $ bitbake <replaceable>recipe</replaceable> -c listtasks
  1566. </literallayout>
  1567. For more information on task dependencies, see the
  1568. "<link linkend='dependencies'>Dependencies</link>"
  1569. section.
  1570. </para>
  1571. <para>
  1572. See the
  1573. "<link linkend='variable-flags'>Variable Flags</link>"
  1574. section for information on variable flags you can use with
  1575. tasks.
  1576. </para>
  1577. </section>
  1578. <section id='deleting-a-task'>
  1579. <title>Deleting a Task</title>
  1580. <para>
  1581. As well as being able to add tasks, you can delete them.
  1582. Simply use the <filename>deltask</filename> command to
  1583. delete a task.
  1584. For example, to delete the example task used in the previous
  1585. sections, you would use:
  1586. <literallayout class='monospaced'>
  1587. deltask printdate
  1588. </literallayout>
  1589. If you delete a task using the <filename>deltask</filename>
  1590. command and the task has dependencies, the dependencies are
  1591. not reconnected.
  1592. For example, suppose you have three tasks named
  1593. <filename>do_a</filename>, <filename>do_b</filename>, and
  1594. <filename>do_c</filename>.
  1595. Furthermore, <filename>do_c</filename> is dependent on
  1596. <filename>do_b</filename>, which in turn is dependent on
  1597. <filename>do_a</filename>.
  1598. Given this scenario, if you use <filename>deltask</filename>
  1599. to delete <filename>do_b</filename>, the implicit dependency
  1600. relationship between <filename>do_c</filename> and
  1601. <filename>do_a</filename> through <filename>do_b</filename>
  1602. no longer exists, and <filename>do_c</filename> dependencies
  1603. are not updated to include <filename>do_a</filename>.
  1604. Thus, <filename>do_c</filename> is free to run before
  1605. <filename>do_a</filename>.
  1606. </para>
  1607. <para>
  1608. If you want dependencies such as these to remain intact, use
  1609. the <filename>[noexec]</filename> varflag to disable the task
  1610. instead of using the <filename>deltask</filename> command to
  1611. delete it:
  1612. <literallayout class='monospaced'>
  1613. do_b[noexec] = "1"
  1614. </literallayout>
  1615. </para>
  1616. </section>
  1617. <section id='passing-information-into-the-build-task-environment'>
  1618. <title>Passing Information Into the Build Task Environment</title>
  1619. <para>
  1620. When running a task, BitBake tightly controls the shell execution
  1621. environment of the build tasks to make
  1622. sure unwanted contamination from the build machine cannot
  1623. influence the build.
  1624. <note>
  1625. By default, BitBake cleans the environment to include only those
  1626. things exported or listed in its whitelist to ensure that the build
  1627. environment is reproducible and consistent.
  1628. You can prevent this "cleaning" by setting the
  1629. <link linkend='var-BB_PRESERVE_ENV'><filename>BB_PRESERVE_ENV</filename></link>
  1630. variable.
  1631. </note>
  1632. Consequently, if you do want something to get passed into the
  1633. build task environment, you must take these two steps:
  1634. <orderedlist>
  1635. <listitem><para>
  1636. Tell BitBake to load what you want from the environment
  1637. into the datastore.
  1638. You can do so through the
  1639. <link linkend='var-BB_ENV_WHITELIST'><filename>BB_ENV_WHITELIST</filename></link>
  1640. and
  1641. <link linkend='var-BB_ENV_EXTRAWHITE'><filename>BB_ENV_EXTRAWHITE</filename></link>
  1642. variables.
  1643. For example, assume you want to prevent the build system from
  1644. accessing your <filename>$HOME/.ccache</filename>
  1645. directory.
  1646. The following command "whitelists" the environment variable
  1647. <filename>CCACHE_DIR</filename> causing BitBack to allow that
  1648. variable into the datastore:
  1649. <literallayout class='monospaced'>
  1650. export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE CCACHE_DIR"
  1651. </literallayout></para></listitem>
  1652. <listitem><para>
  1653. Tell BitBake to export what you have loaded into the
  1654. datastore to the task environment of every running task.
  1655. Loading something from the environment into the datastore
  1656. (previous step) only makes it available in the datastore.
  1657. To export it to the task environment of every running task,
  1658. use a command similar to the following in your local configuration
  1659. file <filename>local.conf</filename> or your
  1660. distribution configuration file:
  1661. <literallayout class='monospaced'>
  1662. export CCACHE_DIR
  1663. </literallayout>
  1664. <note>
  1665. A side effect of the previous steps is that BitBake
  1666. records the variable as a dependency of the build process
  1667. in things like the setscene checksums.
  1668. If doing so results in unnecessary rebuilds of tasks, you can
  1669. whitelist the variable so that the setscene code
  1670. ignores the dependency when it creates checksums.
  1671. </note></para></listitem>
  1672. </orderedlist>
  1673. </para>
  1674. <para>
  1675. Sometimes, it is useful to be able to obtain information
  1676. from the original execution environment.
  1677. Bitbake saves a copy of the original environment into
  1678. a special variable named
  1679. <link linkend='var-BB_ORIGENV'><filename>BB_ORIGENV</filename></link>.
  1680. </para>
  1681. <para>
  1682. The <filename>BB_ORIGENV</filename> variable returns a datastore
  1683. object that can be queried using the standard datastore operators
  1684. such as <filename>getVar(, False)</filename>.
  1685. The datastore object is useful, for example, to find the original
  1686. <filename>DISPLAY</filename> variable.
  1687. Here is an example:
  1688. <literallayout class='monospaced'>
  1689. origenv = d.getVar("BB_ORIGENV", False)
  1690. bar = origenv.getVar("BAR", False)
  1691. </literallayout>
  1692. The previous example returns <filename>BAR</filename> from the original
  1693. execution environment.
  1694. </para>
  1695. </section>
  1696. </section>
  1697. <section id='variable-flags'>
  1698. <title>Variable Flags</title>
  1699. <para>
  1700. Variable flags (varflags) help control a task's functionality
  1701. and dependencies.
  1702. BitBake reads and writes varflags to the datastore using the following
  1703. command forms:
  1704. <literallayout class='monospaced'>
  1705. <replaceable>variable</replaceable> = d.getVarFlags("<replaceable>variable</replaceable>")
  1706. self.d.setVarFlags("FOO", {"func": True})
  1707. </literallayout>
  1708. </para>
  1709. <para>
  1710. When working with varflags, the same syntax, with the exception of
  1711. overrides, applies.
  1712. In other words, you can set, append, and prepend varflags just like
  1713. variables.
  1714. See the
  1715. "<link linkend='variable-flag-syntax'>Variable Flag Syntax</link>"
  1716. section for details.
  1717. </para>
  1718. <para>
  1719. BitBake has a defined set of varflags available for recipes and
  1720. classes.
  1721. Tasks support a number of these flags which control various
  1722. functionality of the task:
  1723. <itemizedlist>
  1724. <listitem><para><emphasis><filename>[cleandirs]</filename>:</emphasis>
  1725. Empty directories that should be created before the
  1726. task runs.
  1727. Directories that already exist are removed and recreated
  1728. to empty them.
  1729. </para></listitem>
  1730. <listitem><para><emphasis><filename>[depends]</filename>:</emphasis>
  1731. Controls inter-task dependencies.
  1732. See the
  1733. <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link>
  1734. variable and the
  1735. "<link linkend='inter-task-dependencies'>Inter-Task Dependencies</link>"
  1736. section for more information.
  1737. </para></listitem>
  1738. <listitem><para><emphasis><filename>[deptask]</filename>:</emphasis>
  1739. Controls task build-time dependencies.
  1740. See the
  1741. <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link>
  1742. variable and the
  1743. "<link linkend='build-dependencies'>Build Dependencies</link>"
  1744. section for more information.
  1745. </para></listitem>
  1746. <listitem><para><emphasis><filename>[dirs]</filename>:</emphasis>
  1747. Directories that should be created before the task runs.
  1748. Directories that already exist are left as is.
  1749. The last directory listed is used as the
  1750. current working directory for the task.
  1751. </para></listitem>
  1752. <listitem><para><emphasis><filename>[lockfiles]</filename>:</emphasis>
  1753. Specifies one or more lockfiles to lock while the task
  1754. executes.
  1755. Only one task may hold a lockfile, and any task that
  1756. attempts to lock an already locked file will block until
  1757. the lock is released.
  1758. You can use this variable flag to accomplish mutual
  1759. exclusion.
  1760. </para></listitem>
  1761. <listitem><para><emphasis><filename>[noexec]</filename>:</emphasis>
  1762. When set to "1", marks the task as being empty, with
  1763. no execution required.
  1764. You can use the <filename>[noexec]</filename> flag to set up
  1765. tasks as dependency placeholders, or to disable tasks defined
  1766. elsewhere that are not needed in a particular recipe.
  1767. </para></listitem>
  1768. <listitem><para><emphasis><filename>[nostamp]</filename>:</emphasis>
  1769. When set to "1", tells BitBake to not generate a stamp
  1770. file for a task, which implies the task should always
  1771. be executed.
  1772. <note><title>Caution</title>
  1773. Any task that depends (possibly indirectly) on a
  1774. <filename>[nostamp]</filename> task will always be
  1775. executed as well.
  1776. This can cause unnecessary rebuilding if you are
  1777. not careful.
  1778. </note>
  1779. </para></listitem>
  1780. <listitem><para><emphasis><filename>[number_threads]</filename>:</emphasis>
  1781. Limits tasks to a specific number of simultaneous threads
  1782. during execution.
  1783. This varflag is useful when your build host has a large number
  1784. of cores but certain tasks need to be rate-limited due to various
  1785. kinds of resource constraints (e.g. to avoid network throttling).
  1786. <filename>number_threads</filename> works similarly to the
  1787. <link linkend='var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename></link>
  1788. variable but is task-specific.</para>
  1789. <para>Set the value globally.
  1790. For example, the following makes sure the
  1791. <filename>do_fetch</filename> task uses no more than two
  1792. simultaneous execution threads:
  1793. <literallayout class='monospaced'>
  1794. do_fetch[number_threads] = "2"
  1795. </literallayout>
  1796. <note><title>Warnings</title>
  1797. <itemizedlist>
  1798. <listitem><para>
  1799. Setting the varflag in individual recipes rather
  1800. than globally can result in unpredictable behavior.
  1801. </para></listitem>
  1802. <listitem><para>
  1803. Setting the varflag to a value greater than the
  1804. value used in the <filename>BB_NUMBER_THREADS</filename>
  1805. variable causes <filename>number_threads</filename>
  1806. to have no effect.
  1807. </para></listitem>
  1808. </itemizedlist>
  1809. </note>
  1810. </para></listitem>
  1811. <listitem><para><emphasis><filename>[postfuncs]</filename>:</emphasis>
  1812. List of functions to call after the completion of the task.
  1813. </para></listitem>
  1814. <listitem><para><emphasis><filename>[prefuncs]</filename>:</emphasis>
  1815. List of functions to call before the task executes.
  1816. </para></listitem>
  1817. <listitem><para><emphasis><filename>[rdepends]</filename>:</emphasis>
  1818. Controls inter-task runtime dependencies.
  1819. See the
  1820. <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link>
  1821. variable, the
  1822. <link linkend='var-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
  1823. variable, and the
  1824. "<link linkend='inter-task-dependencies'>Inter-Task Dependencies</link>"
  1825. section for more information.
  1826. </para></listitem>
  1827. <listitem><para><emphasis><filename>[rdeptask]</filename>:</emphasis>
  1828. Controls task runtime dependencies.
  1829. See the
  1830. <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link>
  1831. variable, the
  1832. <link linkend='var-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
  1833. variable, and the
  1834. "<link linkend='runtime-dependencies'>Runtime Dependencies</link>"
  1835. section for more information.
  1836. </para></listitem>
  1837. <listitem><para><emphasis><filename>[recideptask]</filename>:</emphasis>
  1838. When set in conjunction with
  1839. <filename>recrdeptask</filename>, specifies a task that
  1840. should be inspected for additional dependencies.
  1841. </para></listitem>
  1842. <listitem><para><emphasis><filename>[recrdeptask]</filename>:</emphasis>
  1843. Controls task recursive runtime dependencies.
  1844. See the
  1845. <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link>
  1846. variable, the
  1847. <link linkend='var-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
  1848. variable, and the
  1849. "<link linkend='recursive-dependencies'>Recursive Dependencies</link>"
  1850. section for more information.
  1851. </para></listitem>
  1852. <listitem><para><emphasis><filename>[stamp-extra-info]</filename>:</emphasis>
  1853. Extra stamp information to append to the task's stamp.
  1854. As an example, OpenEmbedded uses this flag to allow
  1855. machine-specific tasks.
  1856. </para></listitem>
  1857. <listitem><para><emphasis><filename>[umask]</filename>:</emphasis>
  1858. The umask to run the task under.
  1859. </para></listitem>
  1860. </itemizedlist>
  1861. </para>
  1862. <para>
  1863. Several varflags are useful for controlling how signatures are
  1864. calculated for variables.
  1865. For more information on this process, see the
  1866. "<link linkend='checksums'>Checksums (Signatures)</link>"
  1867. section.
  1868. <itemizedlist>
  1869. <listitem><para><emphasis><filename>[vardeps]</filename>:</emphasis>
  1870. Specifies a space-separated list of additional
  1871. variables to add to a variable's dependencies
  1872. for the purposes of calculating its signature.
  1873. Adding variables to this list is useful, for example, when
  1874. a function refers to a variable in a manner that
  1875. does not allow BitBake to automatically determine
  1876. that the variable is referred to.
  1877. </para></listitem>
  1878. <listitem><para><emphasis><filename>[vardepsexclude]</filename>:</emphasis>
  1879. Specifies a space-separated list of variables
  1880. that should be excluded from a variable's dependencies
  1881. for the purposes of calculating its signature.
  1882. </para></listitem>
  1883. <listitem><para><emphasis><filename>[vardepvalue]</filename>:</emphasis>
  1884. If set, instructs BitBake to ignore the actual
  1885. value of the variable and instead use the specified
  1886. value when calculating the variable's signature.
  1887. </para></listitem>
  1888. <listitem><para><emphasis><filename>[vardepvalueexclude]</filename>:</emphasis>
  1889. Specifies a pipe-separated list of strings to exclude
  1890. from the variable's value when calculating the
  1891. variable's signature.
  1892. </para></listitem>
  1893. </itemizedlist>
  1894. </para>
  1895. </section>
  1896. <section id='events'>
  1897. <title>Events</title>
  1898. <para>
  1899. BitBake allows installation of event handlers within recipe
  1900. and class files.
  1901. Events are triggered at certain points during operation, such
  1902. as the beginning of operation against a given recipe
  1903. (i.e. <filename>*.bb</filename>), the start of a given task,
  1904. a task failure, a task success, and so forth.
  1905. The intent is to make it easy to do things like email
  1906. notification on build failures.
  1907. </para>
  1908. <para>
  1909. Following is an example event handler that prints the name
  1910. of the event and the content of the
  1911. <filename>FILE</filename> variable:
  1912. <literallayout class='monospaced'>
  1913. addhandler myclass_eventhandler
  1914. python myclass_eventhandler() {
  1915. from bb.event import getName
  1916. print("The name of the Event is %s" % getName(e))
  1917. print("The file we run for is %s" % d.getVar('FILE'))
  1918. }
  1919. myclass_eventhandler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted"
  1920. </literallayout>
  1921. In the previous example, an eventmask has been set so that
  1922. the handler only sees the "BuildStarted" and "BuildCompleted"
  1923. events.
  1924. This event handler gets called every time an event matching
  1925. the eventmask is triggered.
  1926. A global variable "e" is defined, which represents the current
  1927. event.
  1928. With the <filename>getName(e)</filename> method, you can get
  1929. the name of the triggered event.
  1930. The global datastore is available as "d".
  1931. In legacy code, you might see "e.data" used to get the datastore.
  1932. However, realize that "e.data" is deprecated and you should use
  1933. "d" going forward.
  1934. </para>
  1935. <para>
  1936. The context of the datastore is appropriate to the event
  1937. in question.
  1938. For example, "BuildStarted" and "BuildCompleted" events run
  1939. before any tasks are executed so would be in the global
  1940. configuration datastore namespace.
  1941. No recipe-specific metadata exists in that namespace.
  1942. The "BuildStarted" and "BuildCompleted" events also run in
  1943. the main cooker/server process rather than any worker context.
  1944. Thus, any changes made to the datastore would be seen by other
  1945. cooker/server events within the current build but not seen
  1946. outside of that build or in any worker context.
  1947. Task events run in the actual tasks in question consequently
  1948. have recipe-specific and task-specific contents.
  1949. These events run in the worker context and are discarded at
  1950. the end of task execution.
  1951. </para>
  1952. <para>
  1953. During a standard build, the following common events might
  1954. occur.
  1955. The following events are the most common kinds of events that
  1956. most metadata might have an interest in viewing:
  1957. <itemizedlist>
  1958. <listitem><para>
  1959. <filename>bb.event.ConfigParsed()</filename>:
  1960. Fired when the base configuration; which consists of
  1961. <filename>bitbake.conf</filename>,
  1962. <filename>base.bbclass</filename> and any global
  1963. <filename>INHERIT</filename> statements; has been parsed.
  1964. You can see multiple such events when each of the
  1965. workers parse the base configuration or if the server
  1966. changes configuration and reparses.
  1967. Any given datastore only has one such event executed
  1968. against it, however.
  1969. If
  1970. <link linkende='var-BB_INVALIDCONF'><filename>BB_INVALIDCONF</filename></link>
  1971. is set in the datastore by the event handler, the
  1972. configuration is reparsed and a new event triggered,
  1973. allowing the metadata to update configuration.
  1974. </para></listitem>
  1975. <listitem><para>
  1976. <filename>bb.event.HeartbeatEvent()</filename>:
  1977. Fires at regular time intervals of one second.
  1978. You can configure the interval time using the
  1979. <filename>BB_HEARTBEAT_EVENT</filename> variable.
  1980. The event's "time" attribute is the
  1981. <filename>time.time()</filename> value when the
  1982. event is triggered.
  1983. This event is useful for activities such as
  1984. system state monitoring.
  1985. </para></listitem>
  1986. <listitem><para>
  1987. <filename>bb.event.ParseStarted()</filename>:
  1988. Fired when BitBake is about to start parsing recipes.
  1989. This event's "total" attribute represents the number of
  1990. recipes BitBake plans to parse.
  1991. </para></listitem>
  1992. <listitem><para>
  1993. <filename>bb.event.ParseProgress()</filename>:
  1994. Fired as parsing progresses.
  1995. This event's "current" attribute is the number of
  1996. recipes parsed as well as the "total" attribute.
  1997. </para></listitem>
  1998. <listitem><para>
  1999. <filename>bb.event.ParseCompleted()</filename>:
  2000. Fired when parsing is complete.
  2001. This event's "cached", "parsed", "skipped", "virtuals",
  2002. "masked", and "errors" attributes provide statistics
  2003. for the parsing results.
  2004. </para></listitem>
  2005. <listitem><para>
  2006. <filename>bb.event.BuildStarted()</filename>:
  2007. Fired when a new build starts.
  2008. BitBake fires multiple "BuildStarted" events (one per configuration)
  2009. when multiple configuration (multiconfig) is enabled.
  2010. </para></listitem>
  2011. <listitem><para>
  2012. <filename>bb.build.TaskStarted()</filename>:
  2013. Fired when a task starts.
  2014. This event's "taskfile" attribute points to the recipe
  2015. from which the task originates.
  2016. The "taskname" attribute, which is the task's name,
  2017. includes the <filename>do_</filename> prefix, and the
  2018. "logfile" attribute point to where the task's output is
  2019. stored.
  2020. Finally, the "time" attribute is the task's execution start
  2021. time.
  2022. </para></listitem>
  2023. <listitem><para>
  2024. <filename>bb.build.TaskInvalid()</filename>:
  2025. Fired if BitBake tries to execute a task that does not exist.
  2026. </para></listitem>
  2027. <listitem><para>
  2028. <filename>bb.build.TaskFailedSilent()</filename>:
  2029. Fired for setscene tasks that fail and should not be
  2030. presented to the user verbosely.
  2031. </para></listitem>
  2032. <listitem><para>
  2033. <filename>bb.build.TaskFailed()</filename>:
  2034. Fired for normal tasks that fail.
  2035. </para></listitem>
  2036. <listitem><para>
  2037. <filename>bb.build.TaskSucceeded()</filename>:
  2038. Fired when a task successfully completes.
  2039. </para></listitem>
  2040. <listitem><para>
  2041. <filename>bb.event.BuildCompleted()</filename>:
  2042. Fired when a build finishes.
  2043. </para></listitem>
  2044. <listitem><para>
  2045. <filename>bb.cooker.CookerExit()</filename>:
  2046. Fired when the BitBake server/cooker shuts down.
  2047. This event is usually only seen by the UIs as a
  2048. sign they should also shutdown.
  2049. </para></listitem>
  2050. </itemizedlist>
  2051. </para>
  2052. <para>
  2053. This next list of example events occur based on specific
  2054. requests to the server.
  2055. These events are often used to communicate larger pieces of
  2056. information from the BitBake server to other parts of
  2057. BitBake such as user interfaces:
  2058. <itemizedlist>
  2059. <listitem><para>
  2060. <filename>bb.event.TreeDataPreparationStarted()</filename>
  2061. </para></listitem>
  2062. <listitem><para>
  2063. <filename>bb.event.TreeDataPreparationProgress()</filename>
  2064. </para></listitem>
  2065. <listitem><para>
  2066. <filename>bb.event.TreeDataPreparationCompleted()</filename>
  2067. </para></listitem>
  2068. <listitem><para>
  2069. <filename>bb.event.DepTreeGenerated()</filename>
  2070. </para></listitem>
  2071. <listitem><para>
  2072. <filename>bb.event.CoreBaseFilesFound()</filename>
  2073. </para></listitem>
  2074. <listitem><para>
  2075. <filename>bb.event.ConfigFilePathFound()</filename>
  2076. </para></listitem>
  2077. <listitem><para>
  2078. <filename>bb.event.FilesMatchingFound()</filename>
  2079. </para></listitem>
  2080. <listitem><para>
  2081. <filename>bb.event.ConfigFilesFound()</filename>
  2082. </para></listitem>
  2083. <listitem><para>
  2084. <filename>bb.event.TargetsTreeGenerated()</filename>
  2085. </para></listitem>
  2086. </itemizedlist>
  2087. </para>
  2088. </section>
  2089. <section id='variants-class-extension-mechanism'>
  2090. <title>Variants - Class Extension Mechanism</title>
  2091. <para>
  2092. BitBake supports two features that facilitate creating
  2093. from a single recipe file multiple incarnations of that
  2094. recipe file where all incarnations are buildable.
  2095. These features are enabled through the
  2096. <link linkend='var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></link>
  2097. and
  2098. <link linkend='var-BBVERSIONS'><filename>BBVERSIONS</filename></link>
  2099. variables.
  2100. <note>
  2101. The mechanism for this class extension is extremely
  2102. specific to the implementation.
  2103. Usually, the recipe's
  2104. <link linkend='var-PROVIDES'><filename>PROVIDES</filename></link>,
  2105. <link linkend='var-PN'><filename>PN</filename></link>, and
  2106. <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link>
  2107. variables would need to be modified by the extension class.
  2108. For specific examples, see the OE-Core
  2109. <filename>native</filename>, <filename>nativesdk</filename>,
  2110. and <filename>multilib</filename> classes.
  2111. </note>
  2112. <itemizedlist>
  2113. <listitem><para><emphasis><filename>BBCLASSEXTEND</filename>:</emphasis>
  2114. This variable is a space separated list of classes used to "extend" the
  2115. recipe for each variant.
  2116. Here is an example that results in a second incarnation of the current
  2117. recipe being available.
  2118. This second incarnation will have the "native" class inherited.
  2119. <literallayout class='monospaced'>
  2120. BBCLASSEXTEND = "native"
  2121. </literallayout></para></listitem>
  2122. <listitem><para><emphasis><filename>BBVERSIONS</filename>:</emphasis>
  2123. This variable allows a single recipe to build multiple versions of a
  2124. project from a single recipe file.
  2125. You can also specify conditional metadata
  2126. (using the
  2127. <link linkend='var-OVERRIDES'><filename>OVERRIDES</filename></link>
  2128. mechanism) for a single version, or an optionally named range of versions.
  2129. Here is an example:
  2130. <literallayout class='monospaced'>
  2131. BBVERSIONS = "1.0 2.0 git"
  2132. SRC_URI_git = "git://someurl/somepath.git"
  2133. BBVERSIONS = "1.0.[0-6]:1.0.0+ \ 1.0.[7-9]:1.0.7+"
  2134. SRC_URI_append_1.0.7+ = "file://some_patch_which_the_new_versions_need.patch;patch=1"
  2135. </literallayout>
  2136. The name of the range defaults to the original version of the
  2137. recipe.
  2138. For example, in OpenEmbedded, the recipe file
  2139. <filename>foo_1.0.0+.bb</filename> creates a default name range
  2140. of <filename>1.0.0+</filename>.
  2141. This is useful because the range name is not only placed
  2142. into overrides, but it is also made available for the metadata to use
  2143. in the variable that defines the base recipe versions for use in
  2144. <filename>file://</filename> search paths
  2145. (<link linkend='var-FILESPATH'><filename>FILESPATH</filename></link>).
  2146. </para></listitem>
  2147. </itemizedlist>
  2148. </para>
  2149. </section>
  2150. <section id='dependencies'>
  2151. <title>Dependencies</title>
  2152. <para>
  2153. To allow for efficient parallel processing, BitBake handles
  2154. dependencies at the task level.
  2155. Dependencies can exist both between tasks within a single recipe
  2156. and between tasks in different recipes.
  2157. Following are examples of each:
  2158. <itemizedlist>
  2159. <listitem><para>For tasks within a single recipe, a
  2160. recipe's <filename>do_configure</filename>
  2161. task might need to complete before its
  2162. <filename>do_compile</filename> task can run.
  2163. </para></listitem>
  2164. <listitem><para>For tasks in different recipes, one
  2165. recipe's <filename>do_configure</filename>
  2166. task might require another recipe's
  2167. <filename>do_populate_sysroot</filename>
  2168. task to finish first such that the libraries and headers
  2169. provided by the other recipe are available.
  2170. </para></listitem>
  2171. </itemizedlist>
  2172. </para>
  2173. <para>
  2174. This section describes several ways to declare dependencies.
  2175. Remember, even though dependencies are declared in different ways, they
  2176. are all simply dependencies between tasks.
  2177. </para>
  2178. <section id='dependencies-internal-to-the-bb-file'>
  2179. <title>Dependencies Internal to the <filename>.bb</filename> File</title>
  2180. <para>
  2181. BitBake uses the <filename>addtask</filename> directive
  2182. to manage dependencies that are internal to a given recipe
  2183. file.
  2184. You can use the <filename>addtask</filename> directive to
  2185. indicate when a task is dependent on other tasks or when
  2186. other tasks depend on that recipe.
  2187. Here is an example:
  2188. <literallayout class='monospaced'>
  2189. addtask printdate after do_fetch before do_build
  2190. </literallayout>
  2191. In this example, the <filename>do_printdate</filename>
  2192. task depends on the completion of the
  2193. <filename>do_fetch</filename> task, and the
  2194. <filename>do_build</filename> task depends on the
  2195. completion of the <filename>do_printdate</filename>
  2196. task.
  2197. <note><para>
  2198. For a task to run, it must be a direct or indirect
  2199. dependency of some other task that is scheduled to
  2200. run.</para>
  2201. <para>For illustration, here are some examples:
  2202. <itemizedlist>
  2203. <listitem><para>
  2204. The directive
  2205. <filename>addtask mytask before do_configure</filename>
  2206. causes <filename>do_mytask</filename> to run before
  2207. <filename>do_configure</filename> runs.
  2208. Be aware that <filename>do_mytask</filename> still only
  2209. runs if its <link linkend='checksums'>input checksum</link>
  2210. has changed since the last time it was run.
  2211. Changes to the input checksum of
  2212. <filename>do_mytask</filename> also indirectly cause
  2213. <filename>do_configure</filename> to run.
  2214. </para></listitem>
  2215. <listitem><para>
  2216. The directive
  2217. <filename>addtask mytask after do_configure</filename>
  2218. by itself never causes <filename>do_mytask</filename>
  2219. to run.
  2220. <filename>do_mytask</filename> can still be run manually
  2221. as follows:
  2222. <literallayout class='monospaced'>
  2223. $ bitbake <replaceable>recipe</replaceable> -c mytask
  2224. </literallayout>
  2225. Declaring <filename>do_mytask</filename> as a dependency
  2226. of some other task that is scheduled to run also causes
  2227. it to run.
  2228. Regardless, the task runs after
  2229. <filename>do_configure</filename>.
  2230. </para></listitem>
  2231. </itemizedlist></para>
  2232. </note>
  2233. </para>
  2234. </section>
  2235. <section id='build-dependencies'>
  2236. <title>Build Dependencies</title>
  2237. <para>
  2238. BitBake uses the
  2239. <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link>
  2240. variable to manage build time dependencies.
  2241. The <filename>[deptask]</filename> varflag for tasks
  2242. signifies the task of each
  2243. item listed in <filename>DEPENDS</filename> that must
  2244. complete before that task can be executed.
  2245. Here is an example:
  2246. <literallayout class='monospaced'>
  2247. do_configure[deptask] = "do_populate_sysroot"
  2248. </literallayout>
  2249. In this example, the <filename>do_populate_sysroot</filename>
  2250. task of each item in <filename>DEPENDS</filename> must complete before
  2251. <filename>do_configure</filename> can execute.
  2252. </para>
  2253. </section>
  2254. <section id='runtime-dependencies'>
  2255. <title>Runtime Dependencies</title>
  2256. <para>
  2257. BitBake uses the
  2258. <link linkend='var-PACKAGES'><filename>PACKAGES</filename></link>,
  2259. <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link>, and
  2260. <link linkend='var-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
  2261. variables to manage runtime dependencies.
  2262. </para>
  2263. <para>
  2264. The <filename>PACKAGES</filename> variable lists runtime
  2265. packages.
  2266. Each of those packages can have <filename>RDEPENDS</filename> and
  2267. <filename>RRECOMMENDS</filename> runtime dependencies.
  2268. The <filename>[rdeptask]</filename> flag for tasks is used to
  2269. signify the task of each
  2270. item runtime dependency which must have completed before that
  2271. task can be executed.
  2272. <literallayout class='monospaced'>
  2273. do_package_qa[rdeptask] = "do_packagedata"
  2274. </literallayout>
  2275. In the previous example, the <filename>do_packagedata</filename>
  2276. task of each item in <filename>RDEPENDS</filename> must have
  2277. completed before <filename>do_package_qa</filename> can execute.
  2278. </para>
  2279. </section>
  2280. <section id='recursive-dependencies'>
  2281. <title>Recursive Dependencies</title>
  2282. <para>
  2283. BitBake uses the <filename>[recrdeptask]</filename> flag to manage
  2284. recursive task dependencies.
  2285. BitBake looks through the build-time and runtime
  2286. dependencies of the current recipe, looks through
  2287. the task's inter-task
  2288. dependencies, and then adds dependencies for the
  2289. listed task.
  2290. Once BitBake has accomplished this, it recursively works through
  2291. the dependencies of those tasks.
  2292. Iterative passes continue until all dependencies are discovered
  2293. and added.
  2294. </para>
  2295. <para>
  2296. The <filename>[recrdeptask]</filename> flag is most commonly
  2297. used in high-level
  2298. recipes that need to wait for some task to finish "globally".
  2299. For example, <filename>image.bbclass</filename> has the following:
  2300. <literallayout class='monospaced'>
  2301. do_rootfs[recrdeptask] += "do_packagedata"
  2302. </literallayout>
  2303. This statement says that the <filename>do_packagedata</filename>
  2304. task of the current recipe and all recipes reachable
  2305. (by way of dependencies) from the
  2306. image recipe must run before the <filename>do_rootfs</filename>
  2307. task can run.
  2308. </para>
  2309. <para>
  2310. You might want to not only have BitBake look for
  2311. dependencies of those tasks, but also have BitBake look
  2312. for build-time and runtime dependencies of the dependent
  2313. tasks as well.
  2314. If that is the case, you need to reference the task name
  2315. itself in the task list:
  2316. <literallayout class='monospaced'>
  2317. do_a[recrdeptask] = "do_a do_b"
  2318. </literallayout>
  2319. </para>
  2320. </section>
  2321. <section id='inter-task-dependencies'>
  2322. <title>Inter-Task Dependencies</title>
  2323. <para>
  2324. BitBake uses the <filename>[depends]</filename>
  2325. flag in a more generic form
  2326. to manage inter-task dependencies.
  2327. This more generic form allows for inter-dependency
  2328. checks for specific tasks rather than checks for
  2329. the data in <filename>DEPENDS</filename>.
  2330. Here is an example:
  2331. <literallayout class='monospaced'>
  2332. do_patch[depends] = "quilt-native:do_populate_sysroot"
  2333. </literallayout>
  2334. In this example, the <filename>do_populate_sysroot</filename>
  2335. task of the target <filename>quilt-native</filename>
  2336. must have completed before the
  2337. <filename>do_patch</filename> task can execute.
  2338. </para>
  2339. <para>
  2340. The <filename>[rdepends]</filename> flag works in a similar
  2341. way but takes targets
  2342. in the runtime namespace instead of the build-time dependency
  2343. namespace.
  2344. </para>
  2345. </section>
  2346. </section>
  2347. <section id='functions-you-can-call-from-within-python'>
  2348. <title>Functions You Can Call From Within Python</title>
  2349. <para>
  2350. BitBake provides many functions you can call from
  2351. within Python functions.
  2352. This section lists the most commonly used functions,
  2353. and mentions where to find others.
  2354. </para>
  2355. <section id='functions-for-accessing-datastore-variables'>
  2356. <title>Functions for Accessing Datastore Variables</title>
  2357. <para>
  2358. It is often necessary to access variables in the
  2359. BitBake datastore using Python functions.
  2360. The Bitbake datastore has an API that allows you this
  2361. access.
  2362. Here is a list of available operations:
  2363. </para>
  2364. <para>
  2365. <informaltable frame='none'>
  2366. <tgroup cols='2' align='left' colsep='1' rowsep='1'>
  2367. <colspec colname='c1' colwidth='1*'/>
  2368. <colspec colname='c2' colwidth='1*'/>
  2369. <thead>
  2370. <row>
  2371. <entry align="left"><emphasis>Operation</emphasis></entry>
  2372. <entry align="left"><emphasis>Description</emphasis></entry>
  2373. </row>
  2374. </thead>
  2375. <tbody>
  2376. <row>
  2377. <entry align="left"><filename>d.getVar("X", expand)</filename></entry>
  2378. <entry align="left">Returns the value of variable "X".
  2379. Using "expand=True" expands the value.
  2380. Returns "None" if the variable "X" does not exist.</entry>
  2381. </row>
  2382. <row>
  2383. <entry align="left"><filename>d.setVar("X", "value")</filename></entry>
  2384. <entry align="left">Sets the variable "X" to "value".</entry>
  2385. </row>
  2386. <row>
  2387. <entry align="left"><filename>d.appendVar("X", "value")</filename></entry>
  2388. <entry align="left">Adds "value" to the end of the variable "X".
  2389. Acts like <filename>d.setVar("X", "value")</filename>
  2390. if the variable "X" does not exist.</entry>
  2391. </row>
  2392. <row>
  2393. <entry align="left"><filename>d.prependVar("X", "value")</filename></entry>
  2394. <entry align="left">Adds "value" to the start of the variable "X".
  2395. Acts like <filename>d.setVar("X", "value")</filename>
  2396. if the variable "X" does not exist.</entry>
  2397. </row>
  2398. <row>
  2399. <entry align="left"><filename>d.delVar("X")</filename></entry>
  2400. <entry align="left">Deletes the variable "X" from the datastore.
  2401. Does nothing if the variable "X" does not exist.</entry>
  2402. </row>
  2403. <row>
  2404. <entry align="left"><filename>d.renameVar("X", "Y")</filename></entry>
  2405. <entry align="left">Renames the variable "X" to "Y".
  2406. Does nothing if the variable "X" does not exist.</entry>
  2407. </row>
  2408. <row>
  2409. <entry align="left"><filename>d.getVarFlag("X", flag, expand)</filename></entry>
  2410. <entry align="left">Returns the value of variable "X".
  2411. Using "expand=True" expands the value.
  2412. Returns "None" if either the variable "X" or the named flag
  2413. does not exist.</entry>
  2414. </row>
  2415. <row>
  2416. <entry align="left"><filename>d.setVarFlag("X", flag, "value")</filename></entry>
  2417. <entry align="left">Sets the named flag for variable "X" to "value".</entry>
  2418. </row>
  2419. <row>
  2420. <entry align="left"><filename>d.appendVarFlag("X", flag, "value")</filename></entry>
  2421. <entry align="left">Appends "value" to the named flag on the
  2422. variable "X".
  2423. Acts like <filename>d.setVarFlag("X", flag, "value")</filename>
  2424. if the named flag does not exist.</entry>
  2425. </row>
  2426. <row>
  2427. <entry align="left"><filename>d.prependVarFlag("X", flag, "value")</filename></entry>
  2428. <entry align="left">Prepends "value" to the named flag on
  2429. the variable "X".
  2430. Acts like <filename>d.setVarFlag("X", flag, "value")</filename>
  2431. if the named flag does not exist.</entry>
  2432. </row>
  2433. <row>
  2434. <entry align="left"><filename>d.delVarFlag("X", flag)</filename></entry>
  2435. <entry align="left">Deletes the named flag on the variable
  2436. "X" from the datastore.</entry>
  2437. </row>
  2438. <row>
  2439. <entry align="left"><filename>d.setVarFlags("X", flagsdict)</filename></entry>
  2440. <entry align="left">Sets the flags specified in
  2441. the <filename>flagsdict()</filename> parameter.
  2442. <filename>setVarFlags</filename> does not clear previous flags.
  2443. Think of this operation as <filename>addVarFlags</filename>.</entry>
  2444. </row>
  2445. <row>
  2446. <entry align="left"><filename>d.getVarFlags("X")</filename></entry>
  2447. <entry align="left">Returns a <filename>flagsdict</filename>
  2448. of the flags for the variable "X".
  2449. Returns "None" if the variable "X" does not exist.</entry>
  2450. </row>
  2451. <row>
  2452. <entry align="left"><filename>d.delVarFlags("X")</filename></entry>
  2453. <entry align="left">Deletes all the flags for the variable "X".
  2454. Does nothing if the variable "X" does not exist.</entry>
  2455. </row>
  2456. <row>
  2457. <entry align="left"><filename>d.expand(expression)</filename></entry>
  2458. <entry align="left">Expands variable references in the specified
  2459. string expression.
  2460. References to variables that do not exist are left as is.
  2461. For example, <filename>d.expand("foo ${X}")</filename>
  2462. expands to the literal string "foo ${X}" if the
  2463. variable "X" does not exist.</entry>
  2464. </row>
  2465. </tbody>
  2466. </tgroup>
  2467. </informaltable>
  2468. </para>
  2469. </section>
  2470. <section id='other-functions'>
  2471. <title>Other Functions</title>
  2472. <para>
  2473. You can find many other functions that can be called
  2474. from Python by looking at the source code of the
  2475. <filename>bb</filename> module, which is in
  2476. <filename>bitbake/lib/bb</filename>.
  2477. For example,
  2478. <filename>bitbake/lib/bb/utils.py</filename> includes
  2479. the commonly used functions
  2480. <filename>bb.utils.contains()</filename> and
  2481. <filename>bb.utils.mkdirhier()</filename>, which come
  2482. with docstrings.
  2483. </para>
  2484. </section>
  2485. </section>
  2486. <section id='task-checksums-and-setscene'>
  2487. <title>Task Checksums and Setscene</title>
  2488. <para>
  2489. BitBake uses checksums (or signatures) along with the setscene
  2490. to determine if a task needs to be run.
  2491. This section describes the process.
  2492. To help understand how BitBake does this, the section assumes an
  2493. OpenEmbedded metadata-based example.
  2494. </para>
  2495. <para>
  2496. These checksums are stored in
  2497. <link linkend='var-STAMP'><filename>STAMP</filename></link>.
  2498. You can examine the checksums using the following BitBake command:
  2499. <literallayout class='monospaced'>
  2500. $ bitbake-dumpsigs
  2501. </literallayout>
  2502. This command returns the signature data in a readable format
  2503. that allows you to examine the inputs used when the
  2504. OpenEmbedded build system generates signatures.
  2505. For example, using <filename>bitbake-dumpsigs</filename>
  2506. allows you to examine the <filename>do_compile</filename>
  2507. task's “sigdata” for a C application (e.g.
  2508. <filename>bash</filename>).
  2509. Running the command also reveals that the “CC” variable is part of
  2510. the inputs that are hashed.
  2511. Any changes to this variable would invalidate the stamp and
  2512. cause the <filename>do_compile</filename> task to run.
  2513. </para>
  2514. <para>
  2515. The following list describes related variables:
  2516. <itemizedlist>
  2517. <listitem><para>
  2518. <link linkend='var-BB_HASHCHECK_FUNCTION'><filename>BB_HASHCHECK_FUNCTION</filename></link>:
  2519. Specifies the name of the function to call during
  2520. the "setscene" part of the task's execution in order
  2521. to validate the list of task hashes.
  2522. </para></listitem>
  2523. <listitem><para>
  2524. <link linkend='var-BB_SETSCENE_DEPVALID'><filename>BB_SETSCENE_DEPVALID</filename></link>:
  2525. Specifies a function BitBake calls that determines
  2526. whether BitBake requires a setscene dependency to
  2527. be met.
  2528. </para></listitem>
  2529. <listitem><para>
  2530. <link linkend='var-BB_SETSCENE_VERIFY_FUNCTION2'><filename>BB_SETSCENE_VERIFY_FUNCTION2</filename></link>:
  2531. Specifies a function to call that verifies the list of
  2532. planned task execution before the main task execution
  2533. happens.
  2534. </para></listitem>
  2535. <listitem><para>
  2536. <link linkend='var-BB_STAMP_POLICY'><filename>BB_STAMP_POLICY</filename></link>:
  2537. Defines the mode for comparing timestamps of stamp files.
  2538. </para></listitem>
  2539. <listitem><para>
  2540. <link linkend='var-BB_STAMP_WHITELIST'><filename>BB_STAMP_WHITELIST</filename></link>:
  2541. Lists stamp files that are looked at when the stamp policy
  2542. is "whitelist".
  2543. </para></listitem>
  2544. <listitem><para>
  2545. <link linkend='var-BB_TASKHASH'><filename>BB_TASKHASH</filename></link>:
  2546. Within an executing task, this variable holds the hash
  2547. of the task as returned by the currently enabled
  2548. signature generator.
  2549. </para></listitem>
  2550. <listitem><para>
  2551. <link linkend='var-STAMP'><filename>STAMP</filename></link>:
  2552. The base path to create stamp files.
  2553. </para></listitem>
  2554. <listitem><para>
  2555. <link linkend='var-STAMPCLEAN'><filename>STAMPCLEAN</filename></link>:
  2556. Again, the base path to create stamp files but can use wildcards
  2557. for matching a range of files for clean operations.
  2558. </para></listitem>
  2559. </itemizedlist>
  2560. </para>
  2561. </section>
  2562. <section id='wildcard-support-in-variables'>
  2563. <title>Wildcard Support in Variables</title>
  2564. <para>
  2565. Support for wildcard use in variables varies depending on the
  2566. context in which it is used.
  2567. For example, some variables and file names allow limited use of
  2568. wildcards through the "<filename>%</filename>" and
  2569. "<filename>*</filename>" characters.
  2570. Other variables or names support Python's
  2571. <ulink url='https://docs.python.org/3/library/glob.html'><filename>glob</filename></ulink>
  2572. syntax,
  2573. <ulink url='https://docs.python.org/3/library/fnmatch.html#module-fnmatch'><filename>fnmatch</filename></ulink>
  2574. syntax, or
  2575. <ulink url='https://docs.python.org/3/library/re.html#re'><filename>Regular Expression (re)</filename></ulink>
  2576. syntax.
  2577. </para>
  2578. <para>
  2579. For variables that have wildcard suport, the
  2580. documentation describes which form of wildcard, its
  2581. use, and its limitations.
  2582. </para>
  2583. </section>
  2584. </chapter>