package: Fix pkgdata determinism issues
PATCH 1/4 package: Fix pkgdata determinism issues
pkgdata output isn't entirely deterministic since the sorting of some of the variables can change. This likely doesn't have any real world effect but fix this with some additional sorting as it allows better hash equivalency of task output.
--- meta/classes/package.bbclass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
meta/classes/package.bbclass +4 -4
@@ -1690,11 +1690,11 @@ fi val = write_if_exists(sf, pkg, var) write_if_exists(sf, pkg, 'FILERPROVIDESFLIST') - for dfile in (d.getVar('FILERPROVIDESFLIST:' + pkg) or "").split(): + for dfile in sorted((d.getVar('FILERPROVIDESFLIST:' + pkg) or "").split()): write_if_exists(sf, pkg, 'FILERPROVIDES:' + dfile) write_if_exists(sf, pkg, 'FILERDEPENDSFLIST') - for dfile in (d.getVar('FILERDEPENDSFLIST:' + pkg) or "").split(): + for dfile in sorted((d.getVar('FILERDEPENDSFLIST:' + pkg) or "").split()): write_if_exists(sf, pkg, 'FILERDEPENDS:' + dfile) sf.write('%s:%s: %d\n' % ('PKGSIZE', pkg, total_size))
@@ -1797,9 +1797,9 @@ python package_do_filedeps() { d.appendVar(key, " " + " ".join(requires[file])) for pkg in requires_files: - d.setVar("FILERDEPENDSFLIST:" + pkg, " ".join(requires_files[pkg])) + d.setVar("FILERDEPENDSFLIST:" + pkg, " ".join(sorted(requires_files[pkg]))) for pkg in provides_files: - d.setVar("FILERPROVIDESFLIST:" + pkg, " ".join(provides_files[pkg])) + d.setVar("FILERPROVIDESFLIST:" + pkg, " ".join(sorted(provides_files[pkg]))) } SHLIBSDIRS = "${WORKDIR_PKGDATA}/${MLPREFIX}shlibs2"
Signature · 1 line
2.32.0
PATCH 2/4 sstate: Ensure SDE is accounted for in task timestamps
When creating packages we build them with --clamp-mtime and use SOURCE_DATE_EPOCH as the maximum mtime. This makes the end packages reproducible. The data stored in sstate for do_package and the package tasks doesn't benefit from this though and have varying timestamps. This means their outhash varies and means hash equivalance isn't effective at all and doesn't work as intended/desired.
We could create the sstate archives with the same clamping however that would lead to different results depending on whether a task was installed from sstate or not. Making that differ is a path to madness. It also wouldn't fix the outhash of the task to be determninistic without clamping of the date in the hash calculation code.
Instead, iterate over the files in sstate output and clamp them at the code level. This isn't ideal but does make the file timestamps determnistic everywhere and means we don't have to change the hash calculation code.
This issue can be clearly seen looking at the do_package outhash for a recipe which you then re-run the package task for after adding something like whitespace to the install task. The outhash shouldn't change but currently does.
--- meta/classes/sstate.bbclass | 12 ++++++++++++ 1 file changed, 12 insertions(+)
meta/classes/sstate.bbclass +12 -0
@@ -640,10 +640,17 @@ python sstate_hardcode_path () { def sstate_package(ss, d): import oe.path + import time tmpdir = d.getVar('TMPDIR') + def fixtimestamp(root, path): + f = os.path.join(root, path) + if os.lstat(f).st_mtime > sde: + os.utime(f, (sde, sde), follow_symlinks=False) + sstatebuild = d.expand("${WORKDIR}/sstate-build-%s/" % ss['task']) + sde = int(d.getVar("SOURCE_DATE_EPOCH") or time.time()) d.setVar("SSTATE_CURRTASK", ss['task']) bb.utils.remove(sstatebuild, recurse=True) bb.utils.mkdirhier(sstatebuild)
@@ -656,6 +663,7 @@ def sstate_package(ss, d): # to sstate tasks but there aren't many of these so better just avoid them entirely. for walkroot, dirs, files in os.walk(state[1]): for file in files + dirs: + fixtimestamp(walkroot, file) srcpath = os.path.join(walkroot, file) if not os.path.islink(srcpath): continue
@@ -677,6 +685,10 @@ def sstate_package(ss, d): bb.utils.mkdirhier(plain) bb.utils.mkdirhier(pdir) bb.utils.rename(plain, pdir) + fixtimestamp(pdir, "") + for walkroot, dirs, files in os.walk(pdir): + for file in files + dirs: + fixtimestamp(walkroot, file) d.setVar('SSTATE_BUILDDIR', sstatebuild) d.setVar('SSTATE_INSTDIR', sstatebuild)
Signature · 1 line
2.32.0
PATCH 3/4 bash: Ensure deterministic build
In reply to Richard PurdieBash keeps a count of the number of times make was invoked on a directory and changes the output versioning accordingly. We want deterministic output so disable this behaviour.
--- meta/recipes-extended/bash/bash.inc | 5 +++++ 1 file changed, 5 insertions(+)
meta/recipes-extended/bash/bash.inc +5 -0
@@ -62,6 +62,11 @@ do_compile_ptest () { oe_runmake buildtest } +do_install:prepend () { + # Ensure determinism as this counter increases for each make call + rm -f ${B}/.build +} + do_install:append () { # Move /usr/bin/bash to /bin/bash, if need if [ "${base_bindir}" != "${bindir}" ]; then
Signature · 1 line
2.32.0
PATCH 4/4 sstatesig: Allow exclusion of the root directory for do_package
In reply to Richard PurdieThe package task references WORKDIR at it's top level and we can't easily make the timestamp for that determnistic due to writes to files there and in other subdirs. We could try and force it to a specific value but it is easier to just remove it from the package task, we don't need it there or care about it in this case.
--- meta/lib/oe/sstatesig.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
meta/lib/oe/sstatesig.py +4 -1
@@ -491,8 +491,10 @@ def OEOuthashBasic(path, sigfile, task, d): if "package_write_" in task or task == "package_qa": include_owners = False include_timestamps = False + include_root = True if task == "package": include_timestamps = d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1' + include_root = False extra_content = d.getVar('HASHEQUIV_HASH_VERSION') try:
@@ -603,7 +605,8 @@ def OEOuthashBasic(path, sigfile, task, d): update_hash("\n") # Process this directory and all its child files - process(root) + if include_root or root != ".": + process(root) for f in files: if f == 'fixmepath': continue
Signature · 1 line
2.32.0