bitbake中使用Python: os.path, os.lostdir, file.split;“P“,“PN“,“S“, LAYERDIR, BBPATH

以下内容部分参考自:

https://zhuanlan.zhihu.com/p/111688338

https://www.yoctoproject.org/docs/2.7/bitbake-user-manual/bitbake-user-manual.html

https://www.yoctoproject.org/docs/2.1/bitbake-user-manual/bitbake-user-manual.html#accessing-datastore-variables-using-python:

 

Chapter 3.10. Accessing Datastore Variables Using Python

os.path.exists():

Python 的 os 模块封装了常见的文件和目录操作。

os.path模块主要用于文件的属性获取,exists是“存在”的意思,所以顾名思义,os.path.exists()就是判断括号里的文件是否存在的意思,括号内的可以是文件路径。

os.listdir() :

os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表。

它不包括 . 和 .. 即使它在文件夹中。只支持在 Unix, Windows 下使用。

listdir()方法语法格式如下:

os.listdir(path)
  • path -- 需要列出的目录路径

返回指定路径下的文件和文件夹列表。

file.split()[1]

>>> str="a_b_c_d_e_f"
>>> str.split("_")[0]
'a'
>>> str.split("_")[1]
'b'
>>> str.split("_")[2]
'c'
>>> str.split("_")[1:]
['b', 'c', 'd', 'e', 'f']

>>> file="something_1.2.3.bbappend"
>>> file.split("_")[0]
'something'

变量的查询

在Yocto环境中, 使用Python时需要用到Bitbake中的一些变量。根据官方文档,可以使用devpyshell来查询。

Similar to working within a development shell as described in the previous section, you can also spawn and work within an interactive Python development shell. When debugging certain commands or even when just editing packages, devpyshell can be a useful tool. When you invoke devpyshell, all tasks up to and including do_patch are run for the specified target. Then a new terminal is opened. Additionally, key Python objects and code are available in the same way they are to BitBake tasks, in particular, the data store 'd'. So, commands such as the following are useful when exploring the data store and running functions:

进入pydevshell环境:“imx-cluster-image” 是目标名。可以是某一个你想编译的App的名字。也可以是编译的ROM名字,比如imx-ivi-image.

从下面的例子中,可以看出来不同变量之间存在着一定的联系。比如"P"是"PN"和"PV"的结合。

$ bitbake imx-cluster-image -c devpyshell
pydevshell> d.getVar("STAGING_DIR")
 '/media/build1/poky/build/tmp/sysroots'
 pydevshell> d.getVar("STAGING_DIR")
 '${TMPDIR}/sysroots'
 pydevshell> d.setVar("FOO", "bar")
 pydevshell> d.getVar("FOO")
 'bar'
 pydevshell> pydevshell> d.getVar('PN')
'imx-cluster-image'
pydevshell> d.getVar('P')
'imx-cluster-image-1.0'
pydevshell> d.getVar('PV')
'1.0'
pydevshell> d.getVar('S')
'/home/csd1013/imx-cluster/build/imx6/tmp/work/imx6-linux-gnueabi/imx-cluster-image/1.0-r0/imx-cluster-image-1.0'
pydevshell> d.getVar('TMPDIR')
'/home/csdn1013/imx-cluster/build/imx6/tmp'
pydevshell> d.getVar('D')
'/home/csdn1013/imx-cluster/build/imx6/tmp/work/imx6-linux-gnueabi/imx-cluster-image/1.0-r0/image'
pydevshell> d.getVar('B')
'/home/csdn1013/imx-cluster/build/imx6/tmp/work/imx6-linux-gnueabi/imx-cluster-image/1.0-r0/imx-cluster-image-1.0'
pydevshell> d.getVar('WORKDIR')
'/home/csdn1013/imx-cluster/build/imx6/tmp/work/imx6-linux-gnueabi/imx-cluster-image/1.0-r0'
pydevshell> d.getVar('BASE_WORKDIR')
'/home/csdn1013/imx-cluster/build/imx6/tmp/work'
pydevshell> d.getVar('BP')
'imx-cluster-image-1.0'
pydevshell> d.getVar('BPN')
'imx-cluster-image'
pydevshell> d.getVar('COREBASE')
'/home/csdn1013/imx-cluster/poky'
pydevshell> d.getVar('STAGING_KERNEL_DIR')
'/home/csdn1013/imx-cluster/build/im6/tmp/work-shared/imx6/kernel-source'

在.conf或者.class文件中常用到的一些变量解释: 

BBPATH

Used by BitBake to locate class (.bbclass) and configuration (.conf) files. This variable is analogous to the PATH variable.

用于定位.bbclass文件和.conf文件。此变量类似于PATH变量。一般是:

BBPATH .= ":${LAYERDIR}"

LAYERDIR

When used inside the layer.conf configuration file, this variable provides the path of the current layer. This variable is not available outside of layer.conf and references are expanded immediately when parsing of the file completes.

在layer.conf中使用该变量时,LAYERDIR表示当前layer的目录。layer.conf文件之外不可用,在文件(应该指的是所在的layer.conf文件)解析完成后立即展开引用。

BBFILES

When specifying recipe files, you can pattern match using Python's glob syntax. 

定义recipe文件的列表。Bitbake通过recipes构建软件。可以使用Python的glob模式匹配多个bb文件。

# We have a recipes directory containing .bb and .bbappend files, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
                        ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS

Lists the names of configured layers. These names are used to find the other BBFILE_* variables. Typically, each layer appends its name to this variable in its conf/layer.conf file.

创建唯一标识符以给OE构建系统参照。一般会写在 Layer的配置文件layer.conf中。例子:标识符"yoctobsp"代表"meta-yocto-bsp" Layer(layer的名称一般以"meta-"开头):

BBFILE_COLLECTIONS += "yoctobsp"

 

BBFILE_PATTERN: 解析时提供Layer目录

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值