reproducible: Switch to last chance SDE fallback
RFC 1/1 reproducible: Switch to last chance SDE fallback
Instead of trying to shove a non-zero SDE into the deployed sstate files which has bad interactions, let it naturally resolve to 0 and do a "last chance" correction to the fallback SOURCE_DATE_EPOCH.
Also, stop exporting the fallback source date epoch since we don't want to invalidate *all* tasks when it changes. Instead, make do_unpack depend on the fallback value to invalidate all the downstream tasks when it changes.
Finally, we need to make sure that do_deploy_source_date_epoch() gets rerun when the actual SDE value changes. Introduce a new variable (SOURCE_DATE_EPOCH_DEP) that this task (and others like it) can depend on when they need to be invalidated by a change in the source date epoch value.
--- meta/classes/reproducible_build.bbclass | 23 ++++++++++++++--------- meta/lib/oe/reproducible.py | 8 ++------ 2 files changed, 16 insertions(+), 15 deletions(-)
meta/classes/reproducible_build.bbclass +14 -9
@@ -42,7 +42,13 @@ SDE_FILE = "${SDE_DIR}/__source_date_epoch.txt" SDE_DEPLOYDIR = "${WORKDIR}/deploy-source-date-epoch" # A SOURCE_DATE_EPOCH of '0' might be misinterpreted as no SDE -export SOURCE_DATE_EPOCH_FALLBACK ??= "1302044400" +SOURCE_DATE_EPOCH_FALLBACK ??= "1302044400" + +# Some tasks do actually depend on the value of the source date epoch, even +# though it is generally excluded from task signatures. For those tasks, they +# can add a vardep on this variable +SOURCE_DATE_EPOCH_DEP = "${SOURCE_DATE_EPOCH}" +SOURCE_DATE_EPOCH_DEP[vardepvalue] = "${SOURCE_DATE_EPOCH_DEP}" SSTATETASKS += "do_deploy_source_date_epoch"
@@ -55,6 +61,7 @@ do_deploy_source_date_epoch () { echo "${SDE_FILE} not found!" fi } +do_deploy_source_date_epoch[vardeps] += "SOURCE_DATE_EPOCH_DEP" python do_deploy_source_date_epoch_setscene () { sstate_setscene(d)
@@ -96,19 +103,15 @@ def get_source_date_epoch_value(d): return cached epochfile = d.getVar('SDE_FILE') - source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) + source_date_epoch = 0 if os.path.isfile(epochfile): with open(epochfile, 'r') as f: s = f.read() try: source_date_epoch = int(s) - # workaround for old sstate with SDE_FILE content being 0 - use SOURCE_DATE_EPOCH_FALLBACK - if source_date_epoch == 0 : - source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) - bb.warn("SOURCE_DATE_EPOCH value from sstate '%s' is deprecated/invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK '%s'" % (s, source_date_epoch)) 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.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to default" % 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))
@@ -116,10 +119,12 @@ def get_source_date_epoch_value(d): 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)}" +export SOURCE_DATE_EPOCH ?= "${@get_source_date_epoch_value(d) or d.getVar('SOURCE_DATE_EPOCH_FALLBACK')}" BB_HASHBASE_WHITELIST += "SOURCE_DATE_EPOCH" python () { if d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1': d.appendVarFlag("do_unpack", "postfuncs", " create_source_date_epoch_stamp") + # Make sure to invalidate all downstream tasks is the SOURCE_DATE_EPOCH_FALLBACK value changes + d.appendVarFlag("do_unpack", "vardeps", "SOURCE_DATE_EPOCH_FALLBACK") }
meta/lib/oe/reproducible.py +2 -6
@@ -90,12 +90,8 @@ def get_source_date_epoch_from_youngest_file(d, sourcedir): bb.debug(1, "Newest file found: %s" % newest_file) return source_date_epoch -def fixed_source_date_epoch(d): +def fixed_source_date_epoch(): bb.debug(1, "No tarball or git repo found to determine SOURCE_DATE_EPOCH") - source_date_epoch = d.getVar('SOURCE_DATE_EPOCH_FALLBACK') - if source_date_epoch: - bb.debug(1, "Using SOURCE_DATE_EPOCH_FALLBACK") - return int(source_date_epoch) return 0 def get_source_date_epoch(d, sourcedir):
@@ -103,6 +99,6 @@ def get_source_date_epoch(d, sourcedir): get_source_date_epoch_from_git(d, sourcedir) or get_source_date_epoch_from_known_files(d, sourcedir) or get_source_date_epoch_from_youngest_file(d, sourcedir) or - fixed_source_date_epoch(d) # Last resort + fixed_source_date_epoch() # Last resort )
Signature · 1 line
2.30.0
Quoted 33 lines · Joshua Watt
Instead of trying to shove a non-zero SDE into the deployed sstate files which has bad interactions, let it naturally resolve to 0 and do a "last chance" correction to the fallback
SOURCE_DATE_EPOCH.Also, stop exporting the fallback source date epoch since we don't want to invalidate *all* tasks when it changes. Instead, make
do_unpackdepend on the fallback value to invalidate all the downstream tasks when it changes.Finally, we need to make sure that
do_deploy_source_date_epoch()gets rerun when the actual SDE value changes. Introduce a new variable (SOURCE_DATE_EPOCH_DEP) that this task (and others like it) can depend on when they need to be invalidated by a change in the source date epoch value.Signed-off-by Joshua Watt <[email protected]>---
meta/classes/reproducible_build.bbclass | 23 ++++++++++++++---------
meta/lib/oe/reproducible.py | 8 ++------2 files changed, 16 insertions(+), 15 deletions(-)meta/classes/reproducible_build.bbclass +0
-0@@ -42,7 +42,13 @@ SDE_FILE = "${SDE_DIR}/__source_date_epoch.txt"SDE_DEPLOYDIR = "${WORKDIR}/deploy-source-date-epoch"
# A
SOURCE_DATE_EPOCHof '0' might be misinterpreted as no SDE
meta/classes/reproducible_build.bbclass SDE_FILE = "${SDE_DIR}/__source_date_epoch.txt" · line 51
Quoted 8 lines
meta/classes/reproducible_build.bbclass +7
-1-export SOURCE_DATE_EPOCH_FALLBACK ??= "1302044400" +SOURCE_DATE_EPOCH_FALLBACK ??= "1302044400" + +# Some tasks do actually depend on the value of the source date epoch, even +# though it is generally excluded from task signatures. For those tasks, they +# can add a vardep on this variable +SOURCE_DATE_EPOCH_DEP = "${SOURCE_DATE_EPOCH}" +SOURCE_DATE_EPOCH_DEP[vardepvalue] = "${SOURCE_DATE_EPOCH_DEP}"
Just for the mailing list record, I believe the above would not allow task checksums to be calculated in advance which is why we didn't do this originally. It would certainly make some things easier if we could do that but I'm not sure it would be possible. The sstate tests in oe-selftest would likely flag this problem as they're designed to detect this.
Cheers,
Richard