简体   繁体   English

Yocto食谱,可通过Dep工具管理Go依赖项

[英]Yocto recipe to manage Go dependencies with dep tool

Update: This question is already SOLVED. 更新:这个问题已经解决。 I'm re-editing the question to update to the fixed state. 我正在重新编辑问题以更新为固定状态。

I'm trying to write a recipe that uses dep tool to resolve dependencies of a go related project before building it. 我正在尝试编写一个食谱,该食谱在构建之前使用dep工具来解决go相关项目的依赖关系。 I'm using the 'poky' layer of the 'rocko' Yocto project branch. 我正在使用“ rocko” Yocto项目分支的“ poky”层。 That branch provides recipes to build the go compiler and the dep dependencies tool. 该分支提供了构建go编译器和dep依赖关系工具的方法。

My initial recipe fetches source code from a bitbucket repository: 我最初的食谱是从bitbucket存储库中获取源代码的:

GO_IMPORT = "bitbucket.org/path/to/my_project"
SRC_URI = "git://${GO_IMPORT}/protocol=http;user=${GIT_USER}:${GIT_PASS};destsuffix=${PN}-${PV}/src/${GO_IMPORT}"

Then I add this: 然后添加:

inherit go
DEPENDS += "go-dep"

And after I add this function: 然后添加此功能:

do_compile_prepend() {
    dep init
    dep ensure
}

Yocto complains with this error: Yocto抱怨此错误:

run.do_compile.8543: line 118: dep: command not found

After reading some of your answers below, I add suggested patch in your answers at the end of my poky/meta/recipes-devtools/go/go-dep_0.3.0.bb recipe file - thanks a lot!! 在阅读完以下一些答案后,我在poky / meta / recipes-devtools / go / go-dep_0.3.0.bb配方文件的末尾添加了建议的补丁-非常感谢! :-) :-)

BBCLASSEXTEND = "native nativesdk"

After I execute some bitbake commands: 在执行一些bitbake命令之后:

$ bitbake -c cleanall go-dep-native
$ bitbake go-dep-native

Bitbake process ends ok, displaying no errors nor warnings. Bitbake处理正常结束,不显示任何错误或警告。 The native go-dep tool has been built into tmp/work/x86_64-linux/go-dep-native directory and is properly installed into tmp/sysroots-components/x86_64/go-dep-native/usr/bin. 本机go-dep工具已内置到tmp / work / x86_64-linux / go-dep-native目录中,并已正确安装到tmp / sysroots-components / x86_64 / go-dep-native / usr / bin中。

I modify the do_compile_prepend() function as shown below: 我修改do_compile_prepend()函数,如下所示:

do_compile_prepend() {
    rm -f ${WORKDIR}/build/src/${GO_IMPORT}/Gopkg.toml
    rm -f ${WORKDIR}/build/src/${GO_IMPORT}/Gopkg.lock
    cd ${WORKDIR}/build/src/${GO_IMPORT}
    dep init
    dep ensure
}

I modify DEPENDS in my recipe like this: 我在食谱中修改DEPENDS,如下所示:

DEPENDS = "go-native go-dep-native"

Note the go-dep has been removed (I don't need dep tool on the target device, just to resolve dependencies on the native platform). 请注意,go-dep已被删除(我不需要目标设备上的dep工具,只需解决本机平台上的依赖性)。

After that, I execute this command: 之后,我执行以下命令:

$ bitbake <foo>

The do_compile stage works fine, but some errors appear when doing the do_package stage: do_compile阶段工作正常,但是在执行do_package阶段时会出现一些错误:

ERROR: <foo>-1.0-r0 do_package: QA Issue: File '/usr/bin/dep' from <foo> was already stripped, this will prevent future debugging! [already-stripped]
ERROR: <foo>-1.0-r0 do_package: Fatal QA errors found, failing task.
ERROR: <foo>-1.0-r0 do_package: Function failed: do_package

These errors are fixed appending this at the end of my recipe: 这些错误已修复,在我的食谱末尾附加了以下内容:

INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
INHIBIT_PACKAGE_STRIP = "1"
RDEPENDS_${PN}-staticdev += "bash"
RDEPENDS_${PN}-dev += "bash"

I don't know if this is the best way to solve my issue, but at least now it works fine. 我不知道这是否是解决我的问题的最佳方法,但至少现在可以正常工作。 Any advice to improve this recipe is wellcome. 任何改善此食谱的建议都是可以的。 Thank you in advance! 先感谢您! :-) :-)

The DEPENDS += "go-dep" means that your target recipe can include headers or link libs provided by go-dep, but you can't run the dep command, if you need run dep command, you need depend on go-dep-native: DEPENDS += "go-dep"表示您的目标配方可以包含go-dep提供的标题或链接库,但是您无法运行dep命令,如果需要运行dep命令,则需要依赖go-dep -native:

DEPENDS += "go-dep-native"

But yocto doesn't provide go-dep-native currently, so you have to add: 但是yocto当前不提供go-dep-native,因此您必须添加:

BBCLASSEXTEND = "native"

to meta/recipes-devtools/go/go-dep_XXX.bb. meta/recipes-devtools/go/go-dep_XXX.bb.

Then you can run dep command in do_compile_prepend() 然后,您可以在do_compile_prepend()运行dep命令

I just sent the patch[1] to enable the native and nativesdk support for the recipe. 我刚刚发送了补丁[1],以启用对食谱的native和nativesdk支持。

  1. https://patchwork.openembedded.org/patch/147390/ https://patchwork.openembedded.org/patch/147390/

Assuming you're using the same recipe as the one here , you should be able to refer to the ${GO_INSTALL} variable in your do_compile_prepend build step. 假设您使用与此处相同的配方,则应该能够在do_compile_prepend构建步骤中引用$ {GO_INSTALL}变量。 If not, try running -c devshell with your bitbake command, like: 如果没有,请尝试使用bitbake命令运行-c devshell,例如:

bitbake <package name> -c devshell

and look for the path of the dep tool. 并查找dep工具的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM