diff --git a/scripts/README.md b/scripts/README.md index 68831ab6..d6ad3ada 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -65,7 +65,7 @@ Optional environment: verbosity level `2` in `go-build.sh`, set this to `3` when calling `build-release.sh`. * `VERSION`: release version. Will be set by `version.sh` if it is unset or - it has the default `Makefile` value of `v0.0.0`. + if it has the default `Makefile` value of `v0.0.0`. ### `clean.sh`: Cleanup @@ -78,6 +78,8 @@ Required environment: ### `go-build.sh`: Build The Backend Optional environment: + * `BUILD_TIME`: If set, overrides the build time information. Useful for + reproducible builds. * `GOARM`: ARM processor options for the Go compiler. * `GOMIPS`: ARM processor options for the Go compiler. * `GO`: set an alternarive name for the Go compiler. diff --git a/scripts/make/go-build.sh b/scripts/make/go-build.sh index 610e9ab0..1f7bcc96 100644 --- a/scripts/make/go-build.sh +++ b/scripts/make/go-build.sh @@ -10,7 +10,7 @@ # every package that is processed if the caller requested verbosity # level greater than 0. Also show subcommands if the requested # verbosity level is greater than 1. Otherwise, do nothing. -verbose="${VERBOSE:-0}" +readonly verbose="${VERBOSE:-0}" if [ "$verbose" -gt '1' ] then env @@ -33,10 +33,10 @@ fi set -e -f -u # Allow users to set the Go version. -go="${GO:-go}" +readonly go="${GO:-go}" # Require the channel to be set and validate the value. -channel="$CHANNEL" +readonly channel="$CHANNEL" case "$channel" in ('development'|'edge'|'beta'|'release') @@ -52,10 +52,10 @@ esac # Require the version to be set. # # TODO(a.garipov): Additional validation? -version="$VERSION" +readonly version="$VERSION" -# Set date and time of the current build. -buildtime="$(date -u +%FT%TZ%z)" +# Set date and time of the current build unless already set. +readonly buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}" # Set the linker flags accordingly: set the release channel and the # current version as well as goarm and gomips variable values, if the @@ -106,7 +106,7 @@ fi export CGO_ENABLED="$cgo_enabled" export GO111MODULE='on' -readonly build_flags="${BUILD_FLAGS:-$race_flags $out_flags $par_flags $v_flags $x_flags}" +readonly build_flags="${BUILD_FLAGS:-$race_flags --trimpath $out_flags $par_flags $v_flags $x_flags}" # Don't use quotes with flag variables to get word splitting. "$go" generate $v_flags $x_flags ./main.go