1

在 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 值?

当设置为 AUTOINC 时,SRCREV 是如何完成的?

4

2 回答 2

1

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

AUTOREV 的工作方式是在解析时扩展 PV,这会导致调用 bitbake 提取器。它能够使用“git ls-remote”调用将 AUTOREV 解析为特定修订版,该修订版用于 bitbake 构建的其余部分。

您拥有的代码根本无法工作,例如它将在哪个目录中运行“git fetch”?当 WORKDIR 不存在时,需要在初始解析时设置哈希值。

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

于 2019-05-01T08:19:14.373 回答
0

我使用不需要本地存储库的“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}"
于 2019-05-02T14:20:38.527 回答