Pull request: all: improve build reproducibility

Updates #2959.

Squashed commit of the following:

commit 2178c73835454b75b6b0790322df3975e1d14f10
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Apr 30 19:34:39 2021 +0300

    all: improve build reproducibility
This commit is contained in:
Ainar Garipov 2021-04-30 19:51:23 +03:00
parent 9846eeb1d8
commit 1402145cdd
2 changed files with 10 additions and 8 deletions

View File

@ -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.

View File

@ -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