summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/reproducible.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-10-14 12:17:55 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-10-16 17:41:59 +0100
commita28891c779fa85818a1572abfa8450e5930c01ca (patch)
tree607afa1b7df4f4e4607a52c8cb9414d8a8027a4e /meta/lib/oe/reproducible.py
parent4f8eec834a8f8686f37f418e43110f746df6f552 (diff)
downloadpoky-a28891c779fa85818a1572abfa8450e5930c01ca.tar.gz
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>
Diffstat (limited to 'meta/lib/oe/reproducible.py')
-rw-r--r--meta/lib/oe/reproducible.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/meta/lib/oe/reproducible.py b/meta/lib/oe/reproducible.py
index 204b9bd734..a5000574cf 100644
--- a/meta/lib/oe/reproducible.py
+++ b/meta/lib/oe/reproducible.py
@@ -106,3 +106,36 @@ def get_source_date_epoch(d, sourcedir):
106 fixed_source_date_epoch(d) # Last resort 106 fixed_source_date_epoch(d) # Last resort
107 ) 107 )
108 108
109def epochfile_read(epochfile, d):
110 cached, efile = d.getVar('__CACHED_SOURCE_DATE_EPOCH') or (None, None)
111 if cached and efile == epochfile:
112 return cached
113
114 if cached and epochfile != efile:
115 bb.debug(1, "Epoch file changed from %s to %s" % (efile, epochfile))
116
117 source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK'))
118 try:
119 with open(epochfile, 'r') as f:
120 s = f.read()
121 try:
122 source_date_epoch = int(s)
123 except ValueError:
124 bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s)
125 source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK'))
126 bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
127 except FileNotFoundError:
128 bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch))
129
130 d.setVar('__CACHED_SOURCE_DATE_EPOCH', (str(source_date_epoch), epochfile))
131 return str(source_date_epoch)
132
133def epochfile_write(source_date_epoch, epochfile, d):
134
135 bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch)
136 bb.utils.mkdirhier(os.path.dirname(epochfile))
137
138 tmp_file = "%s.new" % epochfile
139 with open(tmp_file, 'w') as f:
140 f.write(str(source_date_epoch))
141 os.rename(tmp_file, epochfile)