base.bbclass 詳細(xì)分析 —— 匿名邏輯

Handle backfilling

  389     oe.utils.features_backfill("DISTRO_FEATURES", d)
  390     oe.utils.features_backfill("MACHINE_FEATURES", d)

--110 def features_backfill(var,d):                                                                                                                                                                                   
  111     # This construct allows the addition of new features to variable specified 
  112     # as var 
  113     # Example for var = "DISTRO_FEATURES" 
  114     # This construct allows the addition of new features to DISTRO_FEATURES 
  115     # that if not present would disable existing functionality, without 
  116     # disturbing distributions that have already set DISTRO_FEATURES. 
  117     # Distributions wanting to elide a value in DISTRO_FEATURES_BACKFILL should 
  118     # add the feature to DISTRO_FEATURES_BACKFILL_CONSIDERED 
  119     features = (d.getVar(var) or "").split()
  120     backfill = (d.getVar(var+"_BACKFILL") or "").split()
  121     considered = (d.getVar(var+"_BACKFILL_CONSIDERED") or "").split()
  122 
  123     addfeatures = []
  124     for feature in backfill:
  125     |   if feature not in features and feature not in considered:
  126     |   |   addfeatures.append(feature)
  127     
  128     if addfeatures:
  129     |   d.appendVar(var, " " + " ".join(addfeatures))

Handle PACKAGECONFIG

用到的方法

d.expand(varname)  如果變量中有${}朴皆,就展開
-- 398     def expandWithRefs(self, s, varname):
   399 
>> 400     |   if not isinstance(s, str): # sanity check
   401     |   |   return VariableParse(varname, self, s)
   402 
   403     |   varparse = VariableParse(varname, self)
   404 
   405     |   while s.find('${') != -1:
   406     |   |   olds = s                                                                                
   407     |   |   try:
   408     |   |   |   s = __expand_var_regexp__.sub(varparse.var_sub, s)                                  
   409     |   |   |   try:
   410     |   |   |   |   s = __expand_python_regexp__.sub(varparse.python_sub, s)                        
-- 411     |   |   |   except SyntaxError as e:                                                            
>> 412     |   |   |   |   # Likely unmatched brackets, just don't expand the expression                   
>> 413     |   |   |   |   if e.msg != "EOL while scanning string literal" and not e.msg.startswith("unterminated string literal"):
   414     |   |   |   |   |   raise                                                                       
   415     |   |   |   if s == olds:                                                                       
   416     |   |   |   |   break
-- 417     |   |   except ExpansionError as e:                                                             
   418     |   |   |   e.addVar(varname)                                                                   
   419     |   |   |   raise
   420     |   |   except bb.parse.SkipRecipe:                                                             
   421     |   |   |   raise                                                                               
   422     |   |   except bb.BBHandledException:                                                           
   423     |   |   |   raise                                                                               
   424     |   |   except Exception as exc:                                                                
-- 425     |   |   |   tb = sys.exc_info()[2]                                                              
>> 426     |   |   |   raise ExpansionError(varname, s, exc).with_traceback(tb) from exc
   427 
   428     |   varparse.value = s
   429 
   430     |   return varparse
   431 
-- 432     def expand(self, s, varname = None):
   433     |   return self.expandWithRefs(s, varname).value 

bb.utils.explode_deps
   160 def explode_deps(s):                                                                                
   161     """                                格式化                                                             
   162     Take an RDEPENDS style string of format:                                                        
   163     "DEPEND1 (optional version) DEPEND2 (optional version) ..."                                     
   164     and return a list of dependencies.                                                              
   165     Version information is ignored.
   166     """ 

根據(jù)PACKAGECONFIG和其flags([])以及MLPREFIX去擴(kuò)展變量 DEPENDS RDEPENDS:${PN} RRECOMMENDS:${PN} PACKAGECONFIG_CONFARGS

  408     pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
  409     if pkgconfigflags:                                                                                                                                                                                          
  410     |   pkgconfig = (d.getVar('PACKAGECONFIG') or "").split()
  411     |   pn = d.getVar("PN")
  412 
  413     |   mlprefix = d.getVar("MLPREFIX")
  414 
  415     |   def expandFilter(appends, extension, prefix):
  416     |   |   appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
  417     |   |   newappends = []
  418     |   |   for a in appends:
  419     |   |   |   if a.endswith("-native") or ("-cross-" in a):
  420     |   |   |   |   newappends.append(a)
  421     |   |   |   elif a.startswith("virtual/"):
  422     |   |   |   |   subs = a.split("/", 1)[1]
  423     |   |   |   |   if subs.startswith(prefix):
  424     |   |   |   |   |   newappends.append(a + extension)
  425     |   |   |   |   else:
>>426     |   |   |   |   |   newappends.append("virtual/" + prefix + subs + extension)
  427     |   |   |   else:
  428     |   |   |   |   if a.startswith(prefix):
  429     |   |   |   |   |   newappends.append(a + extension)
  430     |   |   |   |   else:
  431     |   |   |   |   |   newappends.append(prefix + a + extension)
  432     |   |   return newappends
  433 
  434     |   def appendVar(varname, appends):
  435     |   |   if not appends:
  436     |   |   |   return
  437     |   |   if varname.find("DEPENDS") != -1:
>>438     |   |   |   if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d) :
  439     |   |   |   |   appends = expandFilter(appends, "", "nativesdk-")
  440     |   |   |   elif bb.data.inherits_class('native', d):
  441     |   |   |   |   appends = expandFilter(appends, "-native", "")
  442     |   |   |   elif mlprefix:
  443     |   |   |   |   appends = expandFilter(appends, "", mlprefix)
  444     |   |   varname = d.expand(varname)
  445     |   |   d.appendVar(varname, " " + " ".join(appends))
  446 
  447     |   extradeps = []
  448     |   extrardeps = []
  449     |   extrarrecs = []
  450     |   extraconf = []
  451     |   for flag, flagval in sorted(pkgconfigflags.items()):
  452     |   |   items = flagval.split(",")
  453     |   |   num = len(items)
  454     |   |   if num > 6:
>>455     |   |   |   bb.error("%s: PACKAGECONFIG[%s] Only enable,disable,depend,rdepend,rrecommend,conflict_packageconfig can be specified!"
>>456     |   |   |   |   % (d.getVar('PN'), flag))
  457 
  458 +-- 24 lines: if flag in pkgconfig:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  482 
  483     |   appendVar('DEPENDS', extradeps)
  484     |   appendVar('RDEPENDS:${PN}', extrardeps)
  485     |   appendVar('RRECOMMENDS:${PN}', extrarrecs)
  486     |   appendVar('PACKAGECONFIG_CONFARGS', extraconf)

license處理

不看

非(沒有繼承)native|cross的recipe

>>507     if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):                                                                                                                      
>>508     |   d.appendVarFlag('do_prepare_recipe_sysroot', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
>>509     |   d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  510     |   d.setVarFlag('do_install', 'fakeroot', '1')
>>511     |   d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  512     |   d.setVarFlag('do_package', 'fakeroot', '1')
  513     |   d.setVarFlag('do_package_setscene', 'fakeroot', '1')
>>514     |   d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  515     |   d.setVarFlag('do_devshell', 'fakeroot', '1')
>>516     |   d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')

添加do_prepare_recipe_sysroot do_install do_package do_package_setscene do_devshellvirtual/fakeroot的依賴项戴。

兼容主機(jī)處理

  518     need_machine = d.getVar('COMPATIBLE_MACHINE') 
  519     if need_machine and not d.getVar('PARSE_ALL_RECIPES', False):
  520     |   import re
  521     |   compat_machines = (d.getVar('MACHINEOVERRIDES') or "").split(":")
  522     |   for m in compat_machines:
  523     |   |   if re.match(need_machine, m):
  524     |   |   |   break
  525     |   else:
>>526     |   |   raise bb.parse.SkipRecipe("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE'))

PARSE_ALL_RECIPES 和 SOURCE_MIRROR_FETCH

這塊感覺跟編譯沒啥關(guān)系汉柒,看注釋把

11098 # $SOURCE_MIRROR_FETCH                                                                                                                                                                                          
11099 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/documentation.conf:390
11100 #     [doc] "Switch marking build as source fetcher. Used to skip COMPATIBLE_* checking."

fetch處理

主要是 不同的下載內(nèi)容關(guān)聯(lián)不同的依賴,比如下載內(nèi)容是git鳍刷,則do_fetch[deps] += git-native:do_populate_sysroot

  592     needsrcrev = False
  593     srcuri = d.getVar('SRC_URI')
  594     for uri_string in srcuri.split():
  595     |   uri = bb.fetch.URI(uri_string)
>>596     |   # Also check downloadfilename as the URL path might not be useful for sniffing
  597     |   path = uri.params.get("downloadfilename", uri.path)
  598 
  599     |   # HTTP/FTP use the wget fetcher
  600     |   if uri.scheme in ("http", "https", "ftp"):
>>601     |   |   d.appendVarFlag('do_fetch', 'depends', ' wget-native:do_populate_sysroot')
  602 
  603 +--  5 lines: Svn packages should DEPEND on subversion-native---------------------------------------------------------------------------------------------------------------------------------------------------
  608     |   # Git packages should DEPEND on git-native
  609     |   elif uri.scheme in ("git", "gitsm"):
  610     |   |   needsrcrev = True
>>611     |   |   d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
  612 
  613 +-- 17 lines: Mercurial packages should DEPEND on mercurial-native----------------------------------------------------------------------------------------------------------------------------------------------
  630     |   # *.lz4 should DEPEND on lz4-native for unpacking
  631     |   if path.endswith('.lz4'):
>>632     |   |   d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
  633 
  634     |   # *.zst should DEPEND on zstd-native for unpacking
  635 +-- 11 lines: elif path.endswith('.zst'):-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  646     |   # .zip should DEPEND on unzip-native for unpacking
  647     |   elif path.endswith('.zip') or path.endswith('.jar'):
>>648     |   |   d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
  649 
>>650     |   # Some rpm files may be compressed internally using xz (for example, rpms from Fedora)
  651     |   elif path.endswith('.rpm'):
>>652     |   |   d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
  653 
  654     |   # *.deb should DEPEND on xz-native for unpacking
  655     |   elif path.endswith('.deb'):
>>656     |   |   d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
  657 
  658     if needsrcrev:
  659     |   d.setVar("SRCPV", "${@bb.fetch2.get_srcrev(d)}")
  660 
  661     |   # Gather all named SRCREVs to add to the sstate hash calculation
  662     |   # This anonymous python snippet is called multiple times so we
  663     |   # need to be careful to not double up the appends here and cause
  664     |   # the base hash to mismatch the task hash
  665     |   for uri in srcuri.split():
  666     |   |   parm = bb.fetch.decodeurl(uri)[5]
  667     |   |   uri_names = parm.get("name", "").split(",")
  668     |   |   for uri_name in filter(None, uri_names):
  669     |   |   |   srcrev_name = "SRCREV_{}".format(uri_name)
>>670     |   |   |   if srcrev_name not in (d.getVarFlag("do_fetch", "vardeps") or "").split():
>>671     |   |   |   |   d.appendVarFlag("do_fetch", "vardeps", " {}".format(srcrev_name))

set_packagetriplet

>>354 def set_packagetriplet(d):
>>355     archs = []
  356     tos = []
  357     tvs = []
  358     
  359     archs.append(d.getVar("PACKAGE_ARCHS").split())
  360     tos.append(d.getVar("TARGET_OS"))
  361     tvs.append(d.getVar("TARGET_VENDOR"))
  362     
  363     def settriplet(d, varname, archs, tos, tvs):
  364     |   triplets = []
  365     |   for i in range(len(archs)):
  366     |   |   for arch in archs[i]:
  367     |   |   |   triplets.append(arch + tvs[i] + "-" + tos[i])
  368     |   triplets.reverse()
  369     |   d.setVar(varname, " ".join(triplets))
  370     
  371     settriplet(d, "PKGTRIPLETS", archs, tos, tvs)                                                                                                                                                               
  372 
  373     variants = d.getVar("MULTILIB_VARIANTS") or ""
  374     for item in variants.split():
  375     |   localdata = bb.data.createCopy(d)
>>376     |   overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
  377     |   localdata.setVar("OVERRIDES", overrides)
  378     
  379     |   archs.append(localdata.getVar("PACKAGE_ARCHS").split())
  380     |   tos.append(localdata.getVar("TARGET_OS"))
  381     |   tvs.append(localdata.getVar("TARGET_VENDOR"))
  382     
  383     settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)

初始化變量 PKGTRIPLETS PKGMLTRIPLETS 奸忽,由變量 PACKAGE_ARCHS TARGET_OS TARGET_VENDOR組成何鸡;相應(yīng)示例:

 4690 # $PACKAGE_ARCHS [3 operations]
 4691 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/bitbake.conf:154
 4692 #     "all any noarch ${PACKAGE_EXTRA_ARCHS} ${MACHINE_ARCH}"
 4693 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/bitbake.conf:157
 4694 #     [vardepsexclude] "MACHINE_ARCH"
 4695 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/documentation.conf:311
 4696 #     [doc] "A list of architectures compatible with the given target in order of priority."
 4697 # pre-expansion value:
 4698 #   "all any noarch ${PACKAGE_EXTRA_ARCHS} ${MACHINE_ARCH}"
 4699 PACKAGE_ARCHS="all any noarch x86_64 core2-64 genericx86_64" 

12054 # $TARGET_VENDOR [2 operations]
12055 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/bitbake.conf:132
12056 #     "-oe"
12057 #   set /home/zhangsong/work/about_yocto/sources/poky/meta-poky/conf/distro/poky.conf:11
12058 #     "-poky"
12059 # pre-expansion value:
12060 #   "-poky"
12061 TARGET_VENDOR="-poky"

12027 # $TARGET_OS [2 operations]
12028 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/bitbake.conf:131
12029 #     "linux${LIBCEXTENSION}${ABIEXTENSION}"
12030 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/documentation.conf:421
12031 #     [doc] "Specifies the target's operating system."
12032 # pre-expansion value:
12033 #   "linux${LIBCEXTENSION}${ABIEXTENSION}"
12034 TARGET_OS="linux"


 5007 # $PKGTRIPLETS
 5008 #   set base.bbclass:369 [settriplet]
 5009 #     "genericx86_64-poky-linux core2-64-poky-linux x86_64-poky-linux noarch-poky-linux any-poky-linux all-poky-linux"
 5010 PKGTRIPLETS="genericx86_64-poky-linux core2-64-poky-linux x86_64-poky-linux noarch-poky-linux any-poky-linux all-poky-linux"

 4997 # $PKGMLTRIPLETS
 4998 #   set base.bbclass:369 [settriplet]
 4999 #     "genericx86_64-poky-linux core2-64-poky-linux x86_64-poky-linux noarch-poky-linux any-poky-linux all-poky-linux"
 5000 PKGMLTRIPLETS="genericx86_64-poky-linux core2-64-poky-linux x86_64-poky-linux noarch-poky-linux any-poky-linux all-poky-linux"

PACKAGE_ARCH 與 MACHINE_ARCH 不一致的情況

# $PACKAGE_ARCHS 
        [doc] "A list of architectures compatible with the given target in order of priority."

 4679 # $PACKAGE_ARCH [3 operations]
 4680 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/bitbake.conf:151
 4681 #     [_defaultval] "${TUNE_PKGARCH}"
 4682 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/documentation.conf:310
 4683 #     [doc] "The architecture of the resulting package or packages."
 4684 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/classes/grub-efi-cfg.bbclass:30
 4685 #     "${MACHINE_ARCH}"
 4686 # pre-expansion value:
 4687 #   "${MACHINE_ARCH}"
 4688 PACKAGE_ARCH="genericx86_64"  

 4229 # $MACHINE_ARCH
 4230 #   set /home/zhangsong/work/about_yocto/sources/poky/meta/conf/bitbake.conf:152
 4231 #     "${@[d.getVar('TUNE_PKGARCH'), d.getVar('MACHINE')][bool(d.getVar('MACHINE'))].replace('-', '_')}"
 4232 MACHINE_ARCH="genericx86_64"

# $MACHINE
        [doc] "Specifies the target device for which the image is built. You define MACHINE in the conf/local.conf file in the Build Directory."

不知道 MACHINE 與 PACKAGE_ARCH 不一致是什么情況渐北,不管這個~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市卧波,隨后出現(xiàn)的幾起案子时肿,更是在濱河造成了極大的恐慌,老刑警劉巖港粱,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件螃成,死亡現(xiàn)場離奇詭異,居然都是意外死亡查坪,警方通過查閱死者的電腦和手機(jī)寸宏,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來偿曙,“玉大人氮凝,你說我怎么就攤上這事⊥洌” “怎么了罩阵?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長启摄。 經(jīng)常有香客問我稿壁,道長,這世上最難降的妖魔是什么歉备? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任傅是,我火速辦了婚禮,結(jié)果婚禮上蕾羊,老公的妹妹穿的比我還像新娘喧笔。我一直安慰自己,他們只是感情好龟再,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布溃斋。 她就那樣靜靜地躺著,像睡著了一般吸申。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天截碴,我揣著相機(jī)與錄音梳侨,去河邊找鬼。 笑死日丹,一個胖子當(dāng)著我的面吹牛走哺,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播哲虾,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼丙躏,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了束凑?” 一聲冷哼從身側(cè)響起晒旅,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎汪诉,沒想到半個月后废恋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡扒寄,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年鱼鼓,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片该编。...
    茶點(diǎn)故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡迄本,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出课竣,到底是詐尸還是另有隱情嘉赎,我是刑警寧澤,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布稠氮,位于F島的核電站曹阔,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏隔披。R本人自食惡果不足惜赃份,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望奢米。 院中可真熱鬧抓韩,春花似錦、人聲如沸鬓长。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽涉波。三九已至英上,卻和暖如春炭序,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背苍日。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工惭聂, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人相恃。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓辜纲,卻偏偏與公主長得像,于是被迫代替她去往敵國和親拦耐。 傳聞我的和親對象是個殘疾皇子耕腾,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容