diff options
author | Joshua Watt <jpewhacker@gmail.com> | 2020-01-31 13:04:16 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-02-03 00:10:10 +0000 |
commit | 94981725b0cb825c3ec3a4b02414055c2191dd86 (patch) | |
tree | 011f736bc916ac2e76b28062ea90e21ab0662b66 /meta/classes/reproducible_build.bbclass | |
parent | 2b9781da7c6d60f8d0ddb36de2666b1ba702f551 (diff) | |
download | poky-94981725b0cb825c3ec3a4b02414055c2191dd86.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]
(From OE-Core rev: b3313a10a3eb93f0a3710a35de0404fb49cd6202)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/reproducible_build.bbclass')
-rw-r--r-- | meta/classes/reproducible_build.bbclass | 40 |
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" | |||
44 | SSTATETASKS += "do_deploy_source_date_epoch" | 44 | SSTATETASKS += "do_deploy_source_date_epoch" |
45 | 45 | ||
46 | do_deploy_source_date_epoch () { | 46 | do_deploy_source_date_epoch () { |
47 | echo "Deploying SDE to ${SDE_DIR}." | ||
48 | mkdir -p ${SDE_DEPLOYDIR} | 47 | mkdir -p ${SDE_DEPLOYDIR} |
49 | if [ -e ${SDE_FILE} ]; then | 48 | if [ -e ${SDE_FILE} ]; then |
49 | echo "Deploying SDE from ${SDE_FILE} -> ${SDE_DEPLOYDIR}." | ||
50 | cp -p ${SDE_FILE} ${SDE_DEPLOYDIR}/__source_date_epoch.txt | 50 | cp -p ${SDE_FILE} ${SDE_DEPLOYDIR}/__source_date_epoch.txt |
51 | else | ||
52 | echo "${SDE_FILE} not found!" | ||
51 | fi | 53 | fi |
52 | } | 54 | } |
53 | 55 | ||
@@ -56,7 +58,11 @@ python do_deploy_source_date_epoch_setscene () { | |||
56 | bb.utils.mkdirhier(d.getVar('SDE_DIR')) | 58 | bb.utils.mkdirhier(d.getVar('SDE_DIR')) |
57 | sde_file = os.path.join(d.getVar('SDE_DEPLOYDIR'), '__source_date_epoch.txt') | 59 | sde_file = os.path.join(d.getVar('SDE_DEPLOYDIR'), '__source_date_epoch.txt') |
58 | if os.path.exists(sde_file): | 60 | if os.path.exists(sde_file): |
59 | os.rename(sde_file, d.getVar('SDE_FILE')) | 61 | target = d.getVar('SDE_FILE') |
62 | bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target)) | ||
63 | os.rename(sde_file, target) | ||
64 | else: | ||
65 | bb.debug(1, "%s not found!" % sde_file) | ||
60 | } | 66 | } |
61 | 67 | ||
62 | do_deploy_source_date_epoch[dirs] = "${SDE_DEPLOYDIR}" | 68 | do_deploy_source_date_epoch[dirs] = "${SDE_DEPLOYDIR}" |
@@ -164,16 +170,32 @@ python do_create_source_date_epoch_stamp() { | |||
164 | f.write(str(source_date_epoch)) | 170 | f.write(str(source_date_epoch)) |
165 | } | 171 | } |
166 | 172 | ||
173 | def get_source_date_epoch_value(d): | ||
174 | cached = d.getVar('__CACHED_SOURCE_DATE_EPOCH') | ||
175 | if cached: | ||
176 | return cached | ||
177 | |||
178 | epochfile = d.getVar('SDE_FILE') | ||
179 | source_date_epoch = 0 | ||
180 | if os.path.isfile(epochfile): | ||
181 | with open(epochfile, 'r') as f: | ||
182 | s = f.read() | ||
183 | try: | ||
184 | source_date_epoch = int(s) | ||
185 | except ValueError: | ||
186 | bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to 0" % s) | ||
187 | source_date_epoch = 0 | ||
188 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) | ||
189 | else: | ||
190 | bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch)) | ||
191 | |||
192 | d.setVar('__CACHED_SOURCE_DATE_EPOCH', str(source_date_epoch)) | ||
193 | return str(source_date_epoch) | ||
194 | |||
195 | export SOURCE_DATE_EPOCH ?= "${@get_source_date_epoch_value(d)}" | ||
167 | BB_HASHBASE_WHITELIST += "SOURCE_DATE_EPOCH" | 196 | BB_HASHBASE_WHITELIST += "SOURCE_DATE_EPOCH" |
168 | 197 | ||
169 | python () { | 198 | python () { |
170 | if d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1': | 199 | if d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1': |
171 | d.appendVarFlag("do_unpack", "postfuncs", " do_create_source_date_epoch_stamp") | 200 | d.appendVarFlag("do_unpack", "postfuncs", " do_create_source_date_epoch_stamp") |
172 | epochfile = d.getVar('SDE_FILE') | ||
173 | source_date_epoch = "0" | ||
174 | if os.path.isfile(epochfile): | ||
175 | with open(epochfile, 'r') as f: | ||
176 | source_date_epoch = f.read() | ||
177 | bb.debug(1, "SOURCE_DATE_EPOCH: %s" % source_date_epoch) | ||
178 | d.setVar('SOURCE_DATE_EPOCH', source_date_epoch) | ||
179 | } | 201 | } |