bitbake-user-manual-metadata.xml 134 KB

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