# Bitbake Note ## Syntax ### ?= Softer assignment.如果在statement在parse後變數還沒有被定義,則變數就會被賦予該值,否則變數為原本的值。 當有複數"?="作用在同一變數,則採用第一個 Example: ``` A ?= val ``` --> If A is set at the time this statement is parsed, the variable retains its value. However, if A is not set, the variable is set to "val". ### ??= Weaker assignment. Same as "?=" except that the assignment is made at the end of the parsing process rather than immediately. ### := Expand immediately. Example: ``` T = "123" A := "${B} ${A} test ${T}" T = "456" B = "${T} bval" C = "cval" C := "${C}append" ``` A = test 123 因為 B和A此時為undefined C = cvalappend ### += and =+ Append and prepend with space Example: B = "bval" B += "additionaldata" C = "cval" C =+ "test" B = bval additionaldata C = test cval ### .= and =. Append and prepend without space B = "bval" B .= "additionaldata" C = "cval" C =. "test" B = bvaladditionaldata C = testcval ### Appending and Prepending (Override Style Syntax) 使用override syntax方法來append/prepend,使用此方法不會有空白 B = "bval" B_append = " additional data" C = "cval" C_prepend = "additional data " D = "dval" D_append = "additional data" B = bval additional data C = additional data cval D = additional datadval ### Conditional Metadata 如果有OVERRIDES variable是一個colon-character-separated list,如果滿足OVERRIDES定義的字串,則會使用定義字串的變數 Example: OVERRIDES = "architecture:os:machine" TEST = "default" TEST_os = "osspecific" TEST_nooverride = "othercondvalue" Select the os-specific version of the TEST variable by appending the "os" override to the variable (i.e.TEST_os). OVERRIDES也可搭配append/prepend語句 Example: DEPENDS = "glibc ncurses" OVERRIDES = "machine:local" DEPENDS_append_machine = "libmad" DEPENDS = glibc ncurses libmad ## Sharing Functionality ### inherit Directive 使用inherit directive來繼承.bbclass ### include Directive v.s. require Directive Bitbake會parse指定路徑下的.inc file,當找不到檔案時,inclue不會報錯,require則會報錯 ## Functions 支援 shell function, bitbake style python, python, anonymous python function ### Bitbake Style Python Functions 使用bb.build.exec_func()執行此類function ### Anonymous Python Functions 不同於一般的python function,anonymous Python functions只在parsing時運作 Example: python __anonymous () { if d.getVar('SOMEVAR', True) == 'value': d.setVar('ANOTHERVAR', 'value2') } 一般 "__anonymous" 也可以忽略 "d" variable指的是entire recipe的database ## Tasks Bitbake使用"addtask"來定義function執行順序 Example (meta/class/kernel-yocto.bbclass line:320) ``` addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc addtask kernel_metadata after do_validate_branches do_unpack before do_patch ``` 解讀為: do_kernel_checkout在do_kernel_metadata之前,但在do_symlink_kernsrc之後 do_kernel_metadata在do_validate_branches之後,但在do_unpack之前 因此全部順序為: do_symlink_kernsrc --> do_kernel_checkout --> do_validate_branches --> do_kernel_metadata --> do_patch ## Logging soure code: meta/classes/logging.bbclass ``` bbfatal bbfatal_log bberror bbwarn bbnote bbplain bbdebug ``` Both `bbfatal` and `bbfatal_log` will exit building process Usage: bbnote "test" Log file path (take meta/classes/kernel-yocto.bbclass for example): ``` build/tmp/work/witherspoon-openbmc-linux-gnueabi/linux-aspeed/5.4.39+gitAUTOINC+30079d65ac-r0/temp/log...... ```