约克托。 git 命令生成的包版本

Yocto. Package version generated by git command

是否有任何选项可以在 git 输出的配方中设置包版本? 我有一个食谱,它总是通过设置 SRCREV = "${AUTOREV}" 从 git 下载最新修订版,并且想要 bitbake 将包版本 "PV" 设置为 git describe --abbrev=4 --dirty --always --long

的输出

我能够管理一些代码来实现这个目标,但我觉得这个解决方案不是完美的解决方案,但无论如何请看看为什么。

首先让我们比较输出 git 命令 (git describe --abbrev=4 --dirty --always --long)* 基于配方和 git 存储库,以确保它按预期工作:

  • PV 由 bitbake 根据配方生成:

    $ bitbake --environment hello-world | grep ^PV=
    PV="4b5f"
    
  • 输出git 存储库:

    $ git remote -v | grep fetch
    origin  https://github.com/leachim6/hello-world.git (fetch)
    $ git describe --abbrev=4 --always --long
    4b5f
    

如何存档?出于测试目的,我选择了 hello-world repository, lately on to define the PV I use bitbake python function 方法,该方法允许我将此类函数的输出设置为 PV,配方内容:

$ cat ../meta-test/recipes-hello-world/hello-world/hello-world_git.bb
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=2c4ac2930215d12ccb72d945112a0fa3"

SRC_URI = "git://github.com/leachim6/hello-world.git;protocol=https"
SRCREV = "4b5ff1ef90ceb442f5633fc9e5d28297ac0f69ff"

PV = "${@define_pn(d)}"

def define_pn(d):
    import subprocess
    source_dir = d.getVar('DL_DIR') + "/git2/github.com.leachim6.hello-world.git/"
    cmd = "git describe --abbrev=4 --always --long"
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, cwd=source_dir)
    out, err =  proc.communicate()
    return out.decode("utf-8").rstrip()

关于此解决方案,我主要是如何在 python 函数中正确设置 source_dir 变量,即 much灵活。例如,我试图使用 ${S} 变量,但运气不佳 - 我在解析配方时遇到 python 错误 - gist with error。我在 bitbake 代码方面不是那么先进,但也许其他人可以提供更好的方法来设置这个正确的路径。

*当我使用带有 --dirty 标志的原始命令时,在 bitbake 输出中有 PV="4b5f-dirty ",没有它,输出与 git 存储库中的相同。