bitbake-user-manual-metadata.xml 129 KB

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