base.bbclass 详细分析 —— 匿名逻辑

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     """ 

根据PACKAGECONFIG和其flags([])以及MLPREFIX去扩展变量 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的依赖。

兼容主机处理

  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

这块感觉跟编译没啥关系,看注释把

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处理

主要是 不同的下载内容关联不同的依赖,比如下载内容是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组成;相应示例:

 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 不一致是什么情况,不管这个~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,539评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,911评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,337评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,723评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,795评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,762评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,742评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,508评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,954评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,247评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,404评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,104评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,736评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,352评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,557评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,371评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,292评论 2 352

推荐阅读更多精彩内容