diff options
author | Bernhard M. Wiedemann <bwiedemann@suse.de> | 2019-12-05 16:51:26 +0100 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2020-08-12 07:43:14 +0000 |
commit | 55ae848ce4158ee2d49bcd83d65e9194621f931f (patch) | |
tree | 74f2a7b56757b0cfe16f9bd49557f607aac3bb73 /src/scripts | |
parent | a699926a0dde50586510cd697b4cafc6cc51ab9e (diff) |
build: Allow to override build date with SOURCE_DATE_EPOCH
and make host and user overridable
in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
Also switch to UTC to be independent of timezone.
Also use ISO 8601 date format to be easier to parse.
This is similar to c9f40227836b827b71a6cbc4744d4b7151b2fcef
and df82ec8fe7d91467c8b479bba74c761c0a6ffc59
which was lost in the move away from automake.
Note: This date call is designed to work with different flavors
of date (GNU, BSD and others).
If only GNU (Linux) support is needed, the patch can be simplified.
This PR was done while working on reproducible builds for openSUSE.
Type: fix
Change-Id: If4cab12320e6b5fcb1f2842fac5d745b33b01ed7
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
(cherry picked from commit 3d14f036199d9b3098268821424b4e6f5e8f46dc)
Diffstat (limited to 'src/scripts')
-rwxr-xr-x | src/scripts/generate_version_h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/scripts/generate_version_h b/src/scripts/generate_version_h index f4705489c87..59123684d8d 100755 --- a/src/scripts/generate_version_h +++ b/src/scripts/generate_version_h @@ -1,4 +1,9 @@ #!/bin/bash +: ${VPP_BUILD_USER:=$(whoami)} +: ${VPP_BUILD_HOST:=$(hostname)} +DATE_FMT="+%Y-%m-%dT%H:%M:%S" +SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}" +VPP_BUILD_DATE=$(date -u -d "@$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u "$DATE_FMT") cat > ${1} << __EOF__ /* @@ -19,9 +24,9 @@ cat > ${1} << __EOF__ #ifndef included_vpp_app_version_h #define included_vpp_app_version_h -#define VPP_BUILD_DATE "$(date)" -#define VPP_BUILD_USER "$(whoami)" -#define VPP_BUILD_HOST "$(hostname)" +#define VPP_BUILD_DATE "$VPP_BUILD_DATE" +#define VPP_BUILD_USER "$VPP_BUILD_USER" +#define VPP_BUILD_HOST "$VPP_BUILD_HOST" #define VPP_BUILD_TOPDIR "$(git rev-parse --show-toplevel 2> /dev/null)" #define VPP_BUILD_VER "$(scripts/version)" #endif |