bitbake-user-manual-metadata.xml 118 KB

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