有条件语句的条件位包含 [英] bitbake conditional inclusion of depends statement

查看:143
本文介绍了有条件语句的条件位包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在带有条件的bitbake文件中包括一个depends行? 我想要类似以下的内容:

How do I include a depends line in a bitbake file with a condition ? I want something like below:

if (some env varible)
  DEPENDS += "recipe-1"
else
  DEPENDS += "recipe-2'

我已经在.bb文件中尝试过以下内容:

I have tried below in the .bb file:

DEPENDS += "${@ 'recipe-2' if '${ENV_VAR}' else 'recipe-1'}"

在此之前,我将ENV_VAR导出到BB_ENV_EXTRAWHITE

Before that I exported ENV_VAR to BB_ENV_EXTRAWHITE

export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE ENV_VAR"

这仅在设置ENV_VAR时有效:

This is working only when ENV_VAR is set:

env ENV_VAR="value" bitbake test-recipe

如果未设置ENV_VAR,则在解析bitbake DEPENDS行时会抛出错误

if ENV_VAR is not set, it is throwing an error while parsing the bitbake DEPENDS line

ExpansionError: Failure expanding variable DEPENDS, expression was
${@ 'recipe-2' if '${ENV_VAR}' else 'recipe-1'}  
which triggered exception SyntaxError: EOL while scanning string literal (DEPENDS, line 1)

推荐答案

尝试:

DEPENDS += "${@ 'recipe-2' if d.getVar('ENV_VAR') else 'recipe-1'}"

其原因是${ENV_VAR}被扩展为变量的值.如果未设置,则不会扩展,并且会触发您看到的错误.通过使用getVar,您将得到一个结果,其余的python表达式可以处理None或一个值.

The reason why is that ${ENV_VAR} gets expanded to the value of the variable. If its unset, it doesn't get expanded and that triggers the error you see. By using getVar you get a result which the rest of the python expression can deal with None or a value.

请注意,我们提出了一些建议的更改,这些更改可能会改善行为,使人们更容易使用和理解,但是无论如何,以上内容都将继续有效.

Note that there are some proposed changes which might improve the behaviour to make this a bit more usable and understandable to people but the above would continue to work regardless.

这篇关于有条件语句的条件位包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆