reproducible: Move class function code into library

To try and avoid parse/memory overhead of functions within bitbake,
move the bulk of the reproducibility functions to the function library.

(From OE-Core rev: f2fd1c9d75e774c8a5271cdc1ec6f65c4492f941)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2021-10-14 12:17:55 +01:00
parent 4f8eec834a
commit a28891c779
3 changed files with 36 additions and 36 deletions

View File

@@ -12,7 +12,7 @@ inherit logging
OE_EXTRA_IMPORTS ?= ""
OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa ${OE_EXTRA_IMPORTS}"
OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible ${OE_EXTRA_IMPORTS}"
OE_IMPORTS[type] = "list"
PACKAGECONFIG_CONFARGS ??= ""

View File

@@ -91,19 +91,8 @@ addtask do_deploy_source_date_epoch_setscene
addtask do_deploy_source_date_epoch before do_configure after do_patch
python create_source_date_epoch_stamp() {
import oe.reproducible
epochfile = d.getVar('SDE_FILE')
tmp_file = "%s.new" % epochfile
source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S'))
bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
bb.utils.mkdirhier(d.getVar('SDE_DIR'))
with open(tmp_file, 'w') as f:
f.write(str(source_date_epoch))
os.rename(tmp_file, epochfile)
oe.reproducible.epochfile_write(source_date_epoch, d.getVar('SDE_FILE'), d)
}
EPOCHTASK = "do_deploy_source_date_epoch"
@@ -112,29 +101,7 @@ EPOCHTASK = "do_deploy_source_date_epoch"
do_unpack[postfuncs] += "create_source_date_epoch_stamp"
def get_source_date_epoch_value(d):
epochfile = d.getVar('SDE_FILE')
cached, efile = d.getVar('__CACHED_SOURCE_DATE_EPOCH') or (None, None)
if cached and efile == epochfile:
return cached
if cached and epochfile != efile:
bb.debug(1, "Epoch file changed from %s to %s" % (efile, epochfile))
source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK'))
try:
with open(epochfile, 'r') as f:
s = f.read()
try:
source_date_epoch = int(s)
except ValueError:
bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s)
source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK'))
bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
except FileNotFoundError:
bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch))
d.setVar('__CACHED_SOURCE_DATE_EPOCH', (str(source_date_epoch), epochfile))
return str(source_date_epoch)
return oe.reproducible.epochfile_read(d.getVar('SDE_FILE'), d)
export SOURCE_DATE_EPOCH ?= "${@get_source_date_epoch_value(d)}"
BB_HASHBASE_WHITELIST += "SOURCE_DATE_EPOCH"

View File

@@ -106,3 +106,36 @@ def get_source_date_epoch(d, sourcedir):
fixed_source_date_epoch(d) # Last resort
)
def epochfile_read(epochfile, d):
cached, efile = d.getVar('__CACHED_SOURCE_DATE_EPOCH') or (None, None)
if cached and efile == epochfile:
return cached
if cached and epochfile != efile:
bb.debug(1, "Epoch file changed from %s to %s" % (efile, epochfile))
source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK'))
try:
with open(epochfile, 'r') as f:
s = f.read()
try:
source_date_epoch = int(s)
except ValueError:
bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s)
source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK'))
bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
except FileNotFoundError:
bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch))
d.setVar('__CACHED_SOURCE_DATE_EPOCH', (str(source_date_epoch), epochfile))
return str(source_date_epoch)
def epochfile_write(source_date_epoch, epochfile, d):
bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
bb.utils.mkdirhier(os.path.dirname(epochfile))
tmp_file = "%s.new" % epochfile
with open(tmp_file, 'w') as f:
f.write(str(source_date_epoch))
os.rename(tmp_file, epochfile)