[PATCH] use SOURCE_DATE_EPOCH for timestamp if available (original) (raw)

Denys Vlasenko vda.linux at googlemail.com
Sat Jun 5 16:15:29 UTC 2021


Applied, thank you

On Fri, May 14, 2021 at 12:15 AM Paul Spooren <mail at aparcar.org> wrote:

The SOURCEDATEEPOCH is an effort of the Reproducible Builds organization to make timestamps/build dates in compiled tools deterministic over several repetitive builds. Busybox shows by default the build date timestamp which changes whenever compiled. To have a reasonable accurate build date while staying reproducible, it's possible to use the *date of last source modification* rather than the current time and date. Further information on SOURCEDATEEPOCH are available online [1]. This patch modifies confdata.c so that the content of the SOURCEDATEEPOCH env variable is used as timestamp. To be independent of different timezones between builds, whenever SOURCEDATEEPOCH is defined the GMT time is used. [1]: https://reproducible-builds.org/docs/source-date-epoch/ Signed-off-by: Paul Spooren <mail at aparcar.org> --- scripts/kconfig/confdata.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index b05b96e45..73c25e3a8 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -342,6 +342,8 @@ int confwrite(const char *name) timet now; int usetimestamp = 1; char *env; + char *sourcedateepoch; + struct tm *buildtime; dirname[0] = 0; if (name && name[0]) { @@ -378,7 +380,16 @@ int confwrite(const char *name) } sym = symlookup("KERNELVERSION", 0); symcalcvalue(sym); - time(&now); + + sourcedateepoch = getenv("SOURCEDATEEPOCH"); + if (sourcedateepoch && *sourcedateepoch) { + now = strtoull(sourcedateepoch, NULL, 10); + buildtime = gmtime(&now); + } else { + time(&now); + buildtime = localtime(&now); + } + env = getenv("KCONFIGNOTIMESTAMP"); if (env && *env) usetimestamp = 0; @@ -398,14 +409,14 @@ int confwrite(const char *name) if (usetimestamp) { _sizet ret = _ strftime(buf, sizeof(buf), "#define AUTOCONFTIMESTAMP " - ""%Y-%m-%d %H:%M:%S %Z"\n", localtime(&now)); + ""%Y-%m-%d %H:%M:%S %Z"\n", buildtime); /* if user has Factory timezone or some other odd install, the * %Z above will overflow the string leaving us with undefined * results ... so let's try again without the timezone. */ if (ret == 0) strftime(buf, sizeof(buf), "#define AUTOCONFTIMESTAMP " - ""%Y-%m-%d %H:%M:%S"\n", localtime(&now)); + ""%Y-%m-%d %H:%M:%S"\n", buildtime); } else { /* bbox */ strcpy(buf, "#define AUTOCONFTIMESTAMP ""\n"); } -- 2.30.2


busybox mailing list busybox at busybox.net http://lists.busybox.net/mailman/listinfo/busybox



More information about the busybox mailing list