summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2020-01-31 13:04:16 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-02-02 16:57:23 +0000
commitb3313a10a3eb93f0a3710a35de0404fb49cd6202 (patch)
tree8347d610b8e586b9c1823a2a146b011cf206d1b3
parent472507b8c446dcfe3cb08deecfbca4e5928ca504 (diff)
downloadopenembedded-core-contrib-b3313a10a3eb93f0a3710a35de0404fb49cd6202.tar.gz
classes/reproducible_build: Read SDE file later
Defers the resolution of the SOURCE_DATE_EPOCH until the variable needs to be actually realized with a value. The previous method of loading the value in anonymous python had issues because it could occur before other anonymous python functions that affect the location of the epoch file, such as when a recipe uses AUTOINC/AUTOREV or allarch.bbclass. Also adds more logging to help diagnose issues in the future. [YOCTO #13763] Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/reproducible_build.bbclass40
1 files changed, 31 insertions, 9 deletions
diff --git a/meta/classes/reproducible_build.bbclass b/meta/classes/reproducible_build.bbclass
index 39b6e40cac..750eb950f2 100644
--- a/meta/classes/reproducible_build.bbclass
+++ b/meta/classes/reproducible_build.bbclass
@@ -44,10 +44,12 @@ SDE_DEPLOYDIR = "${WORKDIR}/deploy-source-date-epoch"
SSTATETASKS += "do_deploy_source_date_epoch"
do_deploy_source_date_epoch () {
- echo "Deploying SDE to ${SDE_DIR}."
mkdir -p ${SDE_DEPLOYDIR}
if [ -e ${SDE_FILE} ]; then
+ echo "Deploying SDE from ${SDE_FILE} -> ${SDE_DEPLOYDIR}."
cp -p ${SDE_FILE} ${SDE_DEPLOYDIR}/__source_date_epoch.txt
+ else
+ echo "${SDE_FILE} not found!"
fi
}
@@ -56,7 +58,11 @@ python do_deploy_source_date_epoch_setscene () {
bb.utils.mkdirhier(d.getVar('SDE_DIR'))
sde_file = os.path.join(d.getVar('SDE_DEPLOYDIR'), '__source_date_epoch.txt')
if os.path.exists(sde_file):
- os.rename(sde_file, d.getVar('SDE_FILE'))
+ target = d.getVar('SDE_FILE')
+ bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target))
+ os.rename(sde_file, target)
+ else:
+ bb.debug(1, "%s not found!" % sde_file)
}
do_deploy_source_date_epoch[dirs] = "${SDE_DEPLOYDIR}"
@@ -164,16 +170,32 @@ python do_create_source_date_epoch_stamp() {
f.write(str(source_date_epoch))
}
+def get_source_date_epoch_value(d):
+ cached = d.getVar('__CACHED_SOURCE_DATE_EPOCH')
+ if cached:
+ return cached
+
+ epochfile = d.getVar('SDE_FILE')
+ source_date_epoch = 0
+ if os.path.isfile(epochfile):
+ 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 0" % s)
+ source_date_epoch = 0
+ bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
+ else:
+ 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))
+ return str(source_date_epoch)
+
+export SOURCE_DATE_EPOCH ?= "${@get_source_date_epoch_value(d)}"
BB_HASHBASE_WHITELIST += "SOURCE_DATE_EPOCH"
python () {
if d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1':
d.appendVarFlag("do_unpack", "postfuncs", " do_create_source_date_epoch_stamp")
- epochfile = d.getVar('SDE_FILE')
- source_date_epoch = "0"
- if os.path.isfile(epochfile):
- with open(epochfile, 'r') as f:
- source_date_epoch = f.read()
- bb.debug(1, "SOURCE_DATE_EPOCH: %s" % source_date_epoch)
- d.setVar('SOURCE_DATE_EPOCH', source_date_epoch)
}