bitbake-user-manual-metadata.xml 134 KB

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