Bitbake: "The metadata is not deterministic and this needs to be fixed"
Asked Answered
S

10

24

I'm building a Bitbake recipe and getting the following error message:

ERROR: When reparsing virtual:native:/path/to/poky/meta/recipes-devtools/cve-check-tool/cve-check-tool_5.6.4.bb.do_populate_cve_db, the basehash value changed from 0b637979bcb5db4263f9ed97497a6330 to bcd28a5efe646ed4d327fefa349f889c. The metadata is not deterministic and this needs to be fixed.

This reproduces in a clean build (after bitbake -c cleanall -c cleansstate <recipe>).

What is the reason for this error? The recipe has not been modified from the upstream version.

Speculative answered 13/2, 2018 at 8:32 Comment(1)
Which poky branch do you use? Have you updated it to the current upstream state (i.e. git pull)?Chlordane
H
6

This happens because tasks are evaluated twice, the first time by the cooker, and the second time by bitbake worker. The task hash is calculated twice and if it will not match, meta is considered unstable. Base hash is calculated from variables that are used in the task script. So if you for example use time-related variables like DATETIME, you will get this hash mismatch error. To avoid this error you need to exclude variables from the hash calculation, with VarFlags.

do_something[vardepsexclude]="DATETIME"

here you can find more elaborate explanation. https://www.kc8apf.net/2017/01/tired-of-taskhash-mismatch/

Homologate answered 31/8, 2022 at 12:55 Comment(0)
I
11

the fix I used is go to that recipe and add an empty line in the end, that will help bitbake re-recognize the recipe

Interosculate answered 21/2, 2020 at 18:55 Comment(4)
In particular, i added a line in the image recipe i was bitbaking, that solved.Empyema
What a hacky solution... But that was the only thing that worked!!! The problem occurred during cleansstate in my case...Compensation
I wonder if you could also have run touch <file> to achieve the same result, without modifying the file?Murielmurielle
@JessBowers, you were right, touching the file was enough to fix the issue in my caseEvaporate
S
10

The following is the yocto patch that adds this diagnostic message https://patchwork.openembedded.org/patch/133517/

Here is the commit message, explaining its reasons and a possible way to get further details for the problem:

Bitbake can parse metadata in the cooker and in the worker during builds. If the metadata isn't deterministic, it can change between these two parses and this confuses things a lot. It turns out to be hard to debug these issues currently.

This patch ensures the basehashes from the original parsing are passed into the workers and that these are checked when reparsing for consistency. The user is shown an error message if inconsistencies are found.

There is debug code in siggen.py (see the "Slow but can be useful for debugging mismatched basehashes" commented code), we don't enable this by default due to performance issues. If you run into this message, enable this code and you will find "sigbasedata" files in tmp/stamps which should correspond to the hashes shown in this error message. bitbake-diffsigs on the files should show which variables are changing.

Signed-off-by: Richard Purdie

Scientific answered 24/5, 2018 at 16:55 Comment(5)
So, what's the fix?Germen
Can someone provide an example bitbake-diffsigs command for this case? I found the sigbasedata file, but I don't know what other file to compare it to.Germen
I get it that question mentions "What is the reason for this error? ". This is answered very well here. Thanks for that. However I also expected a solution/workaround so that I can proceed with build.Potemkin
This information seems correct but is not helpful. It's the typical gobbly gook from the yocto team. They seem to have invented a new language ... when one wasn't needed. What is a cooker? what does deterministic imply? What does 'confuses things alot' mean/imply? What is hard to debug? What is basehashes? What inconsistencies? What is siggen.py?Trueblue
@Trueblue "what does deterministic imply?" . Deterministic means two runs with the same data returns the same value. As example func sum(a, b) { return a + b; } is deterministinc. func random(seed) { ... } is not deterministic as to call the function with the same seed parameter - ence the same input data - with give different values on each run.Heterocercal
F
9

I stumbled onto a similar error. For me it happened in the do_install routine. My aim was to store a copy of a file with a ${DATETIME} attached to its name referring to the build time in a specific place.

Apparently the recipes get parsed multiple times during a build and since the time has changed by the second time it got parsed a different ${DATETIME} value was inserted and thus the metadata was recognized as changed.

Favored answered 19/11, 2020 at 9:57 Comment(4)
@Timus for someone familiar with Yocto and Bitbake this is an answer, or at least a very strong hint where to look for one, as what is describes is one of the possible causes for the issue in the question.Hemimorphite
@Timus admittedly, this answer is unusual, in that recipes normally don't include DATETIME, but it's one of the possible causes nonetheless.Hemimorphite
@Timus in case you are curious, Yocto has very strong focus on reproducible builds, to the extent that it even builds the toolchain from sources. Users should use commit hashes, source archive hashes and the like to identify which source it was built from, as in theory source distribution should enable a reproduction. It's a pretty specialized piece of coding.Hemimorphite
@Benedikt, so what is the proper way to do time-stamping in yocto ?Homologate
C
8

Simplest solution: touch <recipename>. Then run cleansstate on your recipe. Then go on as usual from here.

Compensation answered 28/7, 2021 at 8:42 Comment(0)
H
6

This happens because tasks are evaluated twice, the first time by the cooker, and the second time by bitbake worker. The task hash is calculated twice and if it will not match, meta is considered unstable. Base hash is calculated from variables that are used in the task script. So if you for example use time-related variables like DATETIME, you will get this hash mismatch error. To avoid this error you need to exclude variables from the hash calculation, with VarFlags.

do_something[vardepsexclude]="DATETIME"

here you can find more elaborate explanation. https://www.kc8apf.net/2017/01/tired-of-taskhash-mismatch/

Homologate answered 31/8, 2022 at 12:55 Comment(0)
L
5

It helps for me to remove a shared cache for a recipe:

bitbake recipename -c cleansstate

And then, everything works like a charm.

Litch answered 29/10, 2018 at 8:47 Comment(1)
Not a fix for me.Germen
R
1

For what it's worth, doing this cleared it up for me:

devtool modify <recipe>
devtool reset <recipe>
Regeneracy answered 9/6, 2021 at 13:37 Comment(0)
E
1

this also happens if you modify the recipe while you're building...

this means that the error you stated goes off if you edit a recipe file while a build is in progress. If this is your case just finish your edit and re-launch a build, it should work. Happened to me and solved this way.

Erse answered 6/7, 2021 at 14:50 Comment(0)
L
0

This happens when a recipe contains changing data and you try to rebuild it, one way to avoid this is to delete the tmp/ directory [not a good solution] but it is the least possible solution.

Lukin answered 30/3, 2018 at 14:51 Comment(1)
What means "the recipe contains changing data"? Which "data"?Speculative
D
0

For the yocto noobs like me out there. I also found this error to occur if a recipe is appending commented out lines to a task. So my recipes was appending to the do_deploy task but some of the lines had a # before them, it would generate this error when you executed a clean command or not. I.E.:

do_deploy:append () {
  cp a b
# cp b c
}
Dorman answered 21/9, 2023 at 19:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.