如何在yocto配方中管理golang项目的外部依赖项

时间:2018-03-23 17:08:53

标签: go dependency-management yocto recipe

我想用Yocto 2.4.1为交叉编译的golang应用程序编写一个yocto配方,但我不能让外部依赖项工作。 任何人都可以帮助我吗?

current RECIPE_FILE: hello-world_%.bb
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
DESCRIPTION = "Hello world test with golang."

inherit go

COMPATIBLE_MACHINE = "(<machine>)"
DEPENDS = "go-cross-${TARGET_ARCH}"
GO_IMPORT = "hello-world"
SRC_URI = "<git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV}" 
SRCBRANCH = "master"
PV = "0.01"
S = "${WORKDIR}/git"

do_compile() {
  export GOPATH="${WORKDIR}/build"
  export GOARCH="<machine_arch>"
  export GOOS="linux"
  export CGO_ENABLED="0"
  go build src/${GO_IMPORT}/hello-world.go
}

 do_install() {
   install -d "${D}/${bindir}"
   install -m 0755 "${WORKDIR}/build/hello-world" "${D}/${bindir}/hello-world"
 }

RDEPENDS_${PN}-dev += "bash"

此配方仅适用于内部依赖项。但是如何整合外部依赖项,如“github.com/golang/protobuf/ptypes”?

PROJECT_FILE:hello-world.go

package main

import (
    "fmt"
    "github.com/golang/protobuf/ptypes"
)

func main() {
    timestamp := ptypes.TimestampNow()
    fmt.Println(timestamp)
}

有没有人知道这个用例的解决方案?

或者有人知道“go-dep”如何处理这个问题吗?

祝你好运

3 个答案:

答案 0 :(得分:0)

我相信只有两种类型的依赖关系 1.主机依赖关系(应用程序在yocto中编译时间时的依赖关系)
    在yocto recipe(.bb文件)中保留DEPENDS = "some lib"

  1. 目标依赖项(应用程序运行时的依赖关系)
     你的yocto食谱RDEPENDS = "some lib"
  2. hello.bb

    DESCRIPTION =  
    LIC =  
    SRC_URI =  
    DEPENDS ="sqlite3"   
    inherit autools
    

答案 1 :(得分:0)

我将go dep用于dep,这是一个示例。最麻烦的是有关代理的问题,该问题在配方中也得到解决:

inherit go

LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
DESCRIPTION = "Hello world test with golang."

COMPATIBLE_MACHINE = "(<machine>)"
DEPENDS += "go-dep-native"
GO_LINKSHARED = ""

GO_IMPORT = "<git_url>/hello-world.git"
SRC_URI = "<git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV}" 
SRCBRANCH = "master"

do_compile() {
    export SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"
    export HTTP_PROXY="${HTTP_PROXY}"
    ( cd ${WORKDIR}/build/src/${GO_IMPORT} && dep ensure -v )
}

do_compile[vardepsexclude] += "SSH_AUTH_SOCK HTTP_PROXY"

do_install() {
    install -d "${D}/${bindir}"
    install -m 0755 "${WORKDIR}/bin/<arch>/hello-world" "${D}/${bindir}/hello-world"
}

答案 2 :(得分:0)

您可以使用 SRC_URI 添加外部 go 依赖项:

SRC_URI = "\
           <git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV} \
           git://github.com/golang/protobuf/ptypes;protocol=https;name=ptype;destsuffix=${PN}-${PV}/src/github.com/golang/protobuf/ptypes \
"

SRCREV_ptype = "v0.1.0" <-- whatever revision you need (branch, tag, sha)