mediatek: add support for TOTOLINK A8000RU
[openwrt/staging/nbd.git] / package / utils / busybox / patches / 530-use-SOURCE_DATE_EPOCH-for-timestamp-if-available.patch
1 From 59f773ee81a8945321f4aa20abc5e9577e6483e4 Mon Sep 17 00:00:00 2001
2 From: Paul Spooren <mail@aparcar.org>
3 Date: Thu, 13 May 2021 11:25:34 +0200
4 Subject: [PATCH] use SOURCE_DATE_EPOCH for timestamp if available
5
6 The SOURCE_DATE_EPOCH is an effort of the Reproducible Builds
7 organization to make timestamps/build dates in compiled tools
8 deterministic over several repetitive builds.
9
10 Busybox shows by default the build date timestamp which changes whenever
11 compiled. To have a reasonable accurate build date while staying
12 reproducible, it's possible to use the *date of last source
13 modification* rather than the current time and date.
14
15 Further information on SOURCE_DATE_EPOCH are available online [1].
16
17 This patch modifies `confdata.c` so that the content of the
18 SOURCE_DATE_EPOCH env variable is used as timestamp.
19
20 To be independent of different timezones between builds, whenever
21 SOURCE_DATE_EPOCH is defined the GMT time is used.
22
23 [1]: https://reproducible-builds.org/docs/source-date-epoch/
24
25 Signed-off-by: Paul Spooren <mail@aparcar.org>
26 ---
27 scripts/kconfig/confdata.c | 17 ++++++++++++++---
28 1 file changed, 14 insertions(+), 3 deletions(-)
29
30 diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
31 index b05b96e45..73c25e3a8 100644
32 --- a/scripts/kconfig/confdata.c
33 +++ b/scripts/kconfig/confdata.c
34 @@ -342,6 +342,8 @@ int conf_write(const char *name)
35 time_t now;
36 int use_timestamp = 1;
37 char *env;
38 + char *source_date_epoch;
39 + struct tm *build_time;
40
41 dirname[0] = 0;
42 if (name && name[0]) {
43 @@ -378,7 +380,16 @@ int conf_write(const char *name)
44 }
45 sym = sym_lookup("KERNELVERSION", 0);
46 sym_calc_value(sym);
47 - time(&now);
48 +
49 + source_date_epoch = getenv("SOURCE_DATE_EPOCH");
50 + if (source_date_epoch && *source_date_epoch) {
51 + now = strtoull(source_date_epoch, NULL, 10);
52 + build_time = gmtime(&now);
53 + } else {
54 + time(&now);
55 + build_time = localtime(&now);
56 + }
57 +
58 env = getenv("KCONFIG_NOTIMESTAMP");
59 if (env && *env)
60 use_timestamp = 0;
61 @@ -398,14 +409,14 @@ int conf_write(const char *name)
62 if (use_timestamp) {
63 size_t ret = \
64 strftime(buf, sizeof(buf), "#define AUTOCONF_TIMESTAMP "
65 - "\"%Y-%m-%d %H:%M:%S %Z\"\n", localtime(&now));
66 + "\"%Y-%m-%d %H:%M:%S %Z\"\n", build_time);
67 /* if user has Factory timezone or some other odd install, the
68 * %Z above will overflow the string leaving us with undefined
69 * results ... so let's try again without the timezone.
70 */
71 if (ret == 0)
72 strftime(buf, sizeof(buf), "#define AUTOCONF_TIMESTAMP "
73 - "\"%Y-%m-%d %H:%M:%S\"\n", localtime(&now));
74 + "\"%Y-%m-%d %H:%M:%S\"\n", build_time);
75 } else { /* bbox */
76 strcpy(buf, "#define AUTOCONF_TIMESTAMP \"\"\n");
77 }
78 --
79 2.30.2
80