In a Yocto recipe for the Linux kernel I need to get a tag for the most recent commit in the remote Linux kernel git repository. The tag is being appended to the Linux version. The problem I have is that basehash value (of the variable which keeps a tag) changes during build and i get bitbake error:
(...) the basehash value changed from 24896f703509afcd913bc2d97fcff392 to 2d43ec8fdf53988554b77bef20c6fd88. The metadata is not deterministic and this needs to be fixed.
Here is a code which i use in recipe:
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"
The code fails at first build after new commit. Second build is ok. The failure is because basehash value is calculated first on old local clone (S variable) which no longer exists and then on new clone and that changes basehash value during the build.
Is there a way to tell bitbake to calculate the basehash value after the do_fetch
task?
How is it done for SRCREV
when it is set to AUTOINC
?
Bitbake requires hashes be calculated at parse time and not change. That is how they work, they have to be computable in advance.
The way AUTOREV works is that at parse time, PV is expanded which leads to a call into the bitbake fetcher. It is able to use "git ls-remote" calls to resolve AUTOREV into a specific revision which is used for the rest of the bitbake build.
The code you have simply won't work, e.g. which directory is it going to run "git fetch" within? The hash needs to be set at initial parse time when WORKDIR won't exist.
If you're just trying to change the output version (not the one bitbake uses for the recipe), have a look at the PKGV variable instead.