diff options
author | Alexander Couzens <lynxis@fe80.eu> | 2017-06-18 02:21:21 +0200 |
---|---|---|
committer | Alexander Couzens <lynxis@fe80.eu> | 2017-06-19 14:34:52 +0200 |
commit | c47a1a3527d988b637c1daee573cbe0170ef73c6 (patch) | |
tree | 0c101781d043cf4b9fc1d4637725154c234b7d04 /tools/firmware-utils/src/addpattern.c | |
parent | 77dc6a2ae7c94ac3d496ebab589d4574ac7169d0 (diff) | |
download | upstream-c47a1a3527d988b637c1daee573cbe0170ef73c6.tar.gz upstream-c47a1a3527d988b637c1daee573cbe0170ef73c6.tar.bz2 upstream-c47a1a3527d988b637c1daee573cbe0170ef73c6.zip |
firmware-utils: honor env SOURCE_DATE_EPOCH
Use the timestamp from the enviroment SOURCE_DATE_EPOCH
if set instead of the build time.
Fixes reproducible builds for certain firmware images.
Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Diffstat (limited to 'tools/firmware-utils/src/addpattern.c')
-rw-r--r-- | tools/firmware-utils/src/addpattern.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tools/firmware-utils/src/addpattern.c b/tools/firmware-utils/src/addpattern.c index 2ecc7ffd75..9bc4865335 100644 --- a/tools/firmware-utils/src/addpattern.c +++ b/tools/firmware-utils/src/addpattern.c @@ -58,6 +58,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> #include <time.h> #include <unistd.h> #include <sys/stat.h> @@ -141,6 +142,20 @@ void usage(void) exit(EXIT_FAILURE); } +static time_t source_date_epoch = -1; +static void set_source_date_epoch() { + char *env = getenv("SOURCE_DATE_EPOCH"); + char *endptr = env; + errno = 0; + if (env && *env) { + source_date_epoch = strtoull(env, &endptr, 10); + if (errno || (endptr && *endptr != '\0')) { + fprintf(stderr, "Invalid SOURCE_DATE_EPOCH"); + exit(1); + } + } +} + struct board_info *find_board(char *id) { struct board_info *board; @@ -273,7 +288,10 @@ int main(int argc, char **argv) usage(); } - if (time(&t) == (time_t)(-1)) { + set_source_date_epoch(); + if (source_date_epoch != -1) { + t = source_date_epoch; + } else if ((time(&t) == (time_t)(-1))) { fprintf(stderr, "time call failed\n"); return EXIT_FAILURE; } |