diff options
Diffstat (limited to 'meta/classes/reproducible_build.bbclass')
-rw-r--r-- | meta/classes/reproducible_build.bbclass | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/meta/classes/reproducible_build.bbclass b/meta/classes/reproducible_build.bbclass deleted file mode 100644 index f06e00d70d..0000000000 --- a/meta/classes/reproducible_build.bbclass +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | # reproducible_build.bbclass | ||
2 | # | ||
3 | # Sets SOURCE_DATE_EPOCH in each component's build environment. | ||
4 | # Upstream components (generally) respect this environment variable, | ||
5 | # using it in place of the "current" date and time. | ||
6 | # See https://reproducible-builds.org/specs/source-date-epoch/ | ||
7 | # | ||
8 | # After sources are unpacked but before they are patched, we set a reproducible value for SOURCE_DATE_EPOCH. | ||
9 | # This value should be reproducible for anyone who builds the same revision from the same sources. | ||
10 | # | ||
11 | # There are 4 ways we determine SOURCE_DATE_EPOCH: | ||
12 | # | ||
13 | # 1. Use the value from __source_date_epoch.txt file if this file exists. | ||
14 | # This file was most likely created in the previous build by one of the following methods 2,3,4. | ||
15 | # Alternatively, it can be provided by a recipe via SRC_URI. | ||
16 | # | ||
17 | # If the file does not exist: | ||
18 | # | ||
19 | # 2. If there is a git checkout, use the last git commit timestamp. | ||
20 | # Git does not preserve file timestamps on checkout. | ||
21 | # | ||
22 | # 3. Use the mtime of "known" files such as NEWS, CHANGLELOG, ... | ||
23 | # This works for well-kept repositories distributed via tarball. | ||
24 | # | ||
25 | # 4. Use the modification time of the youngest file in the source tree, if there is one. | ||
26 | # This will be the newest file from the distribution tarball, if any. | ||
27 | # | ||
28 | # 5. Fall back to a fixed timestamp. | ||
29 | # | ||
30 | # Once the value of SOURCE_DATE_EPOCH is determined, it is stored in the recipe's SDE_FILE. | ||
31 | # If none of these mechanisms are suitable, replace the do_deploy_source_date_epoch task | ||
32 | # with recipe-specific functionality to write the appropriate SOURCE_DATE_EPOCH into the SDE_FILE. | ||
33 | # | ||
34 | # If this file is found by other tasks, the value is exported in the SOURCE_DATE_EPOCH variable. | ||
35 | # SOURCE_DATE_EPOCH is set for all tasks that might use it (do_configure, do_compile, do_package, ...) | ||
36 | |||
37 | BUILD_REPRODUCIBLE_BINARIES ??= '1' | ||
38 | inherit ${@oe.utils.ifelse(d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1', 'reproducible_build_simple', '')} | ||
39 | |||
40 | SDE_DIR = "${WORKDIR}/source-date-epoch" | ||
41 | SDE_FILE = "${SDE_DIR}/__source_date_epoch.txt" | ||
42 | SDE_DEPLOYDIR = "${WORKDIR}/deploy-source-date-epoch" | ||
43 | |||
44 | # A SOURCE_DATE_EPOCH of '0' might be misinterpreted as no SDE | ||
45 | export SOURCE_DATE_EPOCH_FALLBACK ??= "1302044400" | ||
46 | |||
47 | SSTATETASKS += "do_deploy_source_date_epoch" | ||
48 | |||
49 | do_deploy_source_date_epoch () { | ||
50 | mkdir -p ${SDE_DEPLOYDIR} | ||
51 | if [ -e ${SDE_FILE} ]; then | ||
52 | echo "Deploying SDE from ${SDE_FILE} -> ${SDE_DEPLOYDIR}." | ||
53 | cp -p ${SDE_FILE} ${SDE_DEPLOYDIR}/__source_date_epoch.txt | ||
54 | else | ||
55 | echo "${SDE_FILE} not found!" | ||
56 | fi | ||
57 | } | ||
58 | |||
59 | python do_deploy_source_date_epoch_setscene () { | ||
60 | sstate_setscene(d) | ||
61 | bb.utils.mkdirhier(d.getVar('SDE_DIR')) | ||
62 | sde_file = os.path.join(d.getVar('SDE_DEPLOYDIR'), '__source_date_epoch.txt') | ||
63 | if os.path.exists(sde_file): | ||
64 | target = d.getVar('SDE_FILE') | ||
65 | bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target)) | ||
66 | os.rename(sde_file, target) | ||
67 | else: | ||
68 | bb.debug(1, "%s not found!" % sde_file) | ||
69 | } | ||
70 | |||
71 | do_deploy_source_date_epoch[dirs] = "${SDE_DEPLOYDIR}" | ||
72 | do_deploy_source_date_epoch[sstate-plaindirs] = "${SDE_DEPLOYDIR}" | ||
73 | addtask do_deploy_source_date_epoch_setscene | ||
74 | addtask do_deploy_source_date_epoch before do_configure after do_patch | ||
75 | |||
76 | python create_source_date_epoch_stamp() { | ||
77 | import oe.reproducible | ||
78 | |||
79 | epochfile = d.getVar('SDE_FILE') | ||
80 | # If it exists we need to regenerate as the sources may have changed | ||
81 | if os.path.isfile(epochfile): | ||
82 | bb.debug(1, "Deleting existing SOURCE_DATE_EPOCH from: %s" % epochfile) | ||
83 | os.remove(epochfile) | ||
84 | |||
85 | source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S')) | ||
86 | |||
87 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) | ||
88 | bb.utils.mkdirhier(d.getVar('SDE_DIR')) | ||
89 | with open(epochfile, 'w') as f: | ||
90 | f.write(str(source_date_epoch)) | ||
91 | } | ||
92 | |||
93 | def get_source_date_epoch_value(d): | ||
94 | cached = d.getVar('__CACHED_SOURCE_DATE_EPOCH') | ||
95 | if cached: | ||
96 | return cached | ||
97 | |||
98 | epochfile = d.getVar('SDE_FILE') | ||
99 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) | ||
100 | if os.path.isfile(epochfile): | ||
101 | with open(epochfile, 'r') as f: | ||
102 | s = f.read() | ||
103 | try: | ||
104 | source_date_epoch = int(s) | ||
105 | # workaround for old sstate with SDE_FILE content being 0 - use SOURCE_DATE_EPOCH_FALLBACK | ||
106 | if source_date_epoch == 0 : | ||
107 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) | ||
108 | bb.warn("SOURCE_DATE_EPOCH value from sstate '%s' is deprecated/invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK '%s'" % (s, source_date_epoch)) | ||
109 | except ValueError: | ||
110 | bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s) | ||
111 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) | ||
112 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) | ||
113 | else: | ||
114 | bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch)) | ||
115 | |||
116 | d.setVar('__CACHED_SOURCE_DATE_EPOCH', str(source_date_epoch)) | ||
117 | return str(source_date_epoch) | ||
118 | |||
119 | export SOURCE_DATE_EPOCH ?= "${@get_source_date_epoch_value(d)}" | ||
120 | BB_HASHBASE_WHITELIST += "SOURCE_DATE_EPOCH" | ||
121 | |||
122 | python () { | ||
123 | if d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1': | ||
124 | d.appendVarFlag("do_unpack", "postfuncs", " create_source_date_epoch_stamp") | ||
125 | } | ||