如何告诉 bitbake 在特定任务后计算变量的 basehash 值?

How to tell bitbake to calculate variable's basehash value after specific task?

在 Linux 内核的 Yocto 配方中,我需要在远程 Linux 内核 git 存储库中获取最近提交的标签。该标签被附加到 Linux 版本。我遇到的问题是 basehash 值(保留标签的变量)在构建过程中发生变化,我得到 bitbake 错误:

(...) the basehash value changed from 24896f703509afcd913bc2d97fcff392 to 2d43ec8fdf53988554b77bef20c6fd88. The metadata is not deterministic and this needs to be fixed.

这是我在食谱中使用的代码:

def get_git_tag(git_repo):
  import subprocess
  print(git_repo)
  try:
    subprocess.call("git fetch --tags", cwd=p, shell=True)
    tag = subprocess.Popen("git describe --exact-match 2>/dev/null", cwd=p, shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0].rstrip()
    return tag
  except OSError:
    return ""

KERNEL_LOCALVERSION = "-${@get_git_tag('${S}')}"
KERNEL_LOCALVERSION[vardepvalue] = "${KERNEL_LOCALVERSION}"
do_configure[vardeps] += "KERNEL_LOCALVERSION"

代码在新提交后首次构建时失败。二建没问题。失败是因为 basehash 值首先在不再存在的旧本地克隆(S 变量)上计算,然后在新克隆上计算,并且在构建期间更改了 basehash 值。

有没有办法告诉 bitbucket 在 do_fetch 任务后计算 basehash 值?

SRCREV 设置为 AUTOINC 时如何完成?

Bitbake 要求在解析时计算哈希值,而不是更改哈希值。这就是它们的工作原理,它们必须可以提前计算。

AUTOREV 的工作方式是在解析时扩展 PV,从而调用 bitbake 提取器。它能够使用 "git ls-remote" 调用将 AUTOREV 解析为特定修订版,用于其余的 bitbake 构建。

您的代码根本行不通,例如运行 "git fetch" 到哪个目录?当 WORKDIR 不存在时,需要在初始解析时设置散列。

如果您只是想更改输出版本(而不是用于配方的 bitbake),请改为查看 PKGV 变量。

我用 "git ls-remote" 修改了函数,它不需要本地存储库。

def get_git_tag(d):
  import subprocess
  try:
    uri = d.getVar('SRC_URI').split()
    branch = d.getVar('BRANCH')
    http_url = ""
    for u in uri:
      if u[:3] == "git":
        http_url = "http" + u.split(';')[0][3:]
        break
    cmd = " ".join(["git ls-remote --heads", http_url, "refs/heads/" + branch])
    current_head = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0].split()[0]
    cmd = " ".join(["git ls-remote --tags", http_url, "| grep", current_head])
    tag = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0].split()[-1]
    tag = tag.replace("refs/tags/", "")
    tag = tag.replace("^{}", "")
  except:
    tag = ""

  return tag

KERNEL_LOCALVERSION = "${@get_git_tag(d)}"
KERNEL_LOCALVERSION[vardepvalue] = "${KERNEL_LOCALVERSION}"