1. 环境准备
按照前面几节的分享,我们已经知道了oe-init-build-env是如何建立yocto项目环境的,下面我们继续研究bitbake脚本,在这之前,因为我们选择qemuarm64为目标机进行开发,所以需要修改配置文件conf/local.conf,设置MACHINE为qemuarm64:
2. bitbake脚本分析
2.1 导入必要的包,注意这里用到了sys.path.insert并且连续调用两次os.path.dirname取得bitbake的祖父目录,然后再加上lib,这样就将poky-sumo-19.0.0/bitbake/lib注册到包搜索路径,从而可以在后面import bb:
import os import sys sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib')) try: import bb except RuntimeError as exc: sys.exit(str(exc)) from bb import cookerdata from bb.main import bitbake_main, BitBakeConfigParameters, BBMainException
2.2 检测区域是否为utf-8:
if sys.getfilesystemencoding() != "utf-8": sys.exit("Please use a locale setting which supports UTF-8 (such as LANG=en_US.UTF-8).\nPython can't change the filesystem locale after loading so we need a UTF-8 when Python starts or things won't work.")
2.3 执行bitbake_main,此前进行版本检测:bitbake脚本本身定义了__version__为"1.37.0",同时在bitbake/lib/bb/__init__.py也定义了__version__为“1.37.0”,这里进行一个版本的对比。
__version__ = "1.37.0" if __name__ == "__main__": if __version__ != bb.__version__: sys.exit("Bitbake core version and program version mismatch!") try: sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv), cookerdata.CookerConfiguration())) except BBMainException as err: sys.exit(err) except bb.BBHandledException: sys.exit(1) except Exception: import traceback traceback.print_exc() sys.exit(1)