poky distro 详细分析 —— uninative.bbclass

安装了2个event handler

  1. uninative_event_fetchloader
    uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted"
  2. uninative_event_enable
    uninative_event_enable[eventmask] = "bb.event.ConfigParsed"

eventmask的解释:

bb.event.BuildStarted(): Fired when a new build starts. BitBake fires multiple “BuildStarted” events (one per configuration) when multiple configuration (multiconfig) is enabled.

bb.event.ConfigParsed(): Fired when the base configuration; which consists of `bitbake.conf`, `base.bbclass` and any global [INHERIT](https://docs.yoctoproject.org/bitbake/2.0/bitbake-user-manual/bitbake-user-manual-ref-variables.html#term-INHERIT) statements; has been parsed. You can see multiple such events when each of the workers parse the base configuration or if the server changes configuration and reparses. Any given datastore only has one such event executed against it, however. If [BB_INVALIDCONF](https://docs.yoctoproject.org/bitbake/2.0/bitbake-user-manual/bitbake-user-manual-ref-variables.html#term-BB_INVALIDCONF) is set in the datastore by the event handler, the configuration is reparsed and a new event triggered, allowing the metadata to update configuration.

uninative_event_fetchloader

  1. 检查${UNINATIVE_LOADER}是否已经有了
   31     loader = d.getVar("UNINATIVE_LOADER")
   32     loaderchksum = loader + ".chksum"
   33     if os.path.exists(loader) and os.path.exists(loaderchksum):
   34     ¦   with open(loaderchksum, "r") as f:
   35     ¦   ¦   readchksum = f.read().strip()
   36     ¦   if readchksum == chksum:
   37     ¦   ¦   return
  1. 检查${UNINATIVE_TARBALL}是否下载;若没下载则下载。
   40     try:
   41     ¦   # Save and restore cwd as Fetch.download() does a chdir()
   42     ¦   olddir = os.getcwd()
   43 
   44     ¦   tarball = d.getVar("UNINATIVE_TARBALL")
   45     ¦   tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR"), chksum)
   46     ¦   tarballpath = os.path.join(tarballdir, tarball)
   47 
   48     ¦   if not os.path.exists(tarballpath + ".done"):
   49     ¦   ¦   bb.utils.mkdirhier(tarballdir)
 
   53     ¦   ¦   localdata = bb.data.createCopy(d)
   54     ¦   ¦   localdata.setVar('FILESPATH', "")
   55     ¦   ¦   localdata.setVar('DL_DIR', tarballdir)
>> 59     ¦   ¦   premirrors = bb.fetch2.mirror_from_string(localdata.getVar("PREMIRRORS"))
   60     ¦   ¦   for line in premirrors:
   61     ¦   ¦   ¦   try:
   62     ¦   ¦   ¦   ¦   (find, replace) = line
   67 
>> 68     ¦   ¦   srcuri = d.expand("${UNINATIVE_URL}${UNINATIVE_TARBALL};sha256sum=%s" % chksum)
>> 69     ¦   ¦   bb.note("Fetching uninative binary shim %s (will check PREMIRRORS first)" % srcuri)
   70 
   71     ¦   ¦   fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False)
   72     ¦   ¦   fetcher.download()
   73     ¦   ¦   localpath = fetcher.localpath(srcuri)
>> 74     ¦   ¦   if localpath != tarballpath and os.path.exists(localpath) and not os.path.exists(tarballpath):

   79     ¦   ¦   ¦   if os.path.islink(tarballpath):
   80     ¦   ¦   ¦   ¦   # Broken symbolic link
   81     ¦   ¦   ¦   ¦   os.unlink(tarballpath)
   82 
   83     ¦   ¦   ¦   # Deal with two processes trying to make symlink at once
   84     ¦   ¦   ¦   try:
   85     ¦   ¦   ¦   ¦   os.symlink(localpath, tarballpath)
  1. 检查gcc版本是否符合要求
>> 90     ¦   glibcver = subprocess.check_output(["ldd", "--version"]).decode('utf-8').split('\n')[0].split()[-1]
>> 91     ¦   if bb.utils.vercmp_string(d.getVar("UNINATIVE_MAXGLIBCVERSION"), glibcver) < 0:
>> 92     ¦   ¦   raise RuntimeError("Your host glibc version (%s) is newer than that in uninative (%s). Disabling uninative so that sstate is not corrupted." % (glibcver, d.getVar("UNINATIVE_MAXGLIBCVERSION")))
   93 
  1. 创建目录,解压并且执行${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py
    relocate_sdk.py最后说。
   94     ¦   cmd = d.expand("\
   95 mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; \
   96 cd ${UNINATIVE_STAGING_DIR}-uninative; \
   97 tar -xJf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; \
   98 ${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py \
   99   ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux \
  100   ${UNINATIVE_LOADER} \
  101   ${UNINATIVE_LOADER} \
>>102   ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative \
>>103   ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so*" % chksum)
  104     ¦   subprocess.check_output(cmd, shell=True)
  1. 调用 enable_uninative

uninative_event_enable

  1. 调用 enable_uninative

enable_uninative

>>131 def enable_uninative(d):
  132     loader = d.getVar("UNINATIVE_LOADER")
  133     if os.path.exists(loader):
  134     ¦   bb.debug(2, "Enabling uninative")
>>135     ¦   d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d))
  136     ¦   d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp")
>>137     ¦   d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp")
>>138     ¦   d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}")
>>139     ¦   d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}")
  140     ¦   d.appendVarFlag("BUILD_LDFLAGS", "vardepsexclude", "UNINATIVE_LOADER")
>>141     ¦   d.prependVar("PATH", "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:")
  1. 设置 SSTATEPOSTUNPACKFUNCS = uninative_changeinterp
  2. 设置 BUILD_LDFLAGS = -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}
  3. 添加$PATH ${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:

relocate_sdk.py

这个不细看了,大致意思就是将传入的目标 ——${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative \ 和 ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so*interpreter 和 change ld.so.cache path and default libs path for dynamic loader

uninative_changeinterp

${SSTATE_INSTDIR}目录下的所有文件(除了so、链接或者权限不对),修改其interpreter

python uninative_changeinterp () {
  144     import subprocess
  145     import stat
  146     import oe.qa
  147 
>>148     if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)):
  149     ¦   return
  150 
  151     sstateinst = d.getVar('SSTATE_INSTDIR')
  152     for walkroot, dirs, files in os.walk(sstateinst):
  153     ¦   for file in files:
  154     ¦   ¦   if file.endswith(".so") or ".so." in file:
  155     ¦   ¦   ¦   continue
  156     ¦   ¦   f = os.path.join(walkroot, file)
  157     ¦   ¦   if os.path.islink(f):
  158     ¦   ¦   ¦   continue
  159     ¦   ¦   s = os.stat(f)
>>160     ¦   ¦   if not ((s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH)):
  161     ¦   ¦   ¦   continue
  162     ¦   ¦   elf = oe.qa.ELFFile(f)
  163     ¦   ¦   try:
  164     ¦   ¦   ¦   elf.open()
  165     ¦   ¦   except oe.qa.NotELFFileError:
  166     ¦   ¦   ¦   continue
  167     ¦   ¦   if not elf.isDynamic():
  168     ¦   ¦   ¦   continue
  169 
>>170     ¦   ¦   subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)
  171 }

总结

目前跟外界发生关系的,只有 SSTATEPOSTUNPACKFUNCS,沿着这个线索去看。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念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

推荐阅读更多精彩内容