Pull request: all: imp scripts

Merge in DNS/adguard-home from imp-sh to master

Squashed commit of the following:

commit 477832e11eca2ef7ac0071b5da938dacb2ed617d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 20:24:34 2021 +0300

    scripts: rm dbg

commit dbb4b8c783f607781b980dcd57d78085c9022e72
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 20:21:20 2021 +0300

    all: imp code, compat, docs

commit e6e4375d67ad1c213efb04411e3ba0bc6293f936
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 19:33:48 2021 +0300

    all: imp scripts
This commit is contained in:
Ainar Garipov
2021-05-19 20:31:20 +03:00
parent b3d28408cd
commit 6f7fd33afd
17 changed files with 473 additions and 321 deletions

View File

@@ -2,41 +2,47 @@
# AdGuard Home Build Script
#
# The commentary in this file is written with the assumption that the
# reader only has superficial knowledge of the POSIX shell language and
# alike. Experienced readers may find it overly verbose.
# The commentary in this file is written with the assumption that the reader
# only has superficial knowledge of the POSIX shell language and alike.
# Experienced readers may find it overly verbose.
# The default verbosity level is 0. Show every command that is run and 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
# The default verbosity level is 0. Show every command that is run and
# 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.
readonly verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '1' ]
then
env
set -x
readonly v_flags='-v'
readonly x_flags='-x'
v_flags='-v'
x_flags='-x'
elif [ "$verbose" -gt '0' ]
then
set -x
readonly v_flags='-v'
readonly x_flags=''
v_flags='-v'
x_flags=''
else
set +x
readonly v_flags=''
readonly x_flags=''
v_flags=''
x_flags=''
fi
readonly x_flags v_flags
# Exit the script if a pipeline fails (-e), prevent accidental filename
# expansion (-f), and consider undefined variables as errors (-u).
set -e -f -u
# Allow users to set the Go version.
readonly go="${GO:-go}"
go="${GO:-go}"
readonly go
# Require the channel to be set and validate the value.
readonly channel="$CHANNEL"
channel="$CHANNEL"
readonly channel
case "$channel"
in
('development'|'edge'|'beta'|'release')
@@ -52,15 +58,19 @@ esac
# Require the version to be set.
#
# TODO(a.garipov): Additional validation?
readonly version="$VERSION"
version="$VERSION"
readonly version
# Set date and time of the current build unless already set.
readonly buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}"
buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}"
readonly buildtime
# Set the linker flags accordingly: set the release channel and the current
# version as well as goarm and gomips variable values, if the variables are set
# and are not empty.
version_pkg='github.com/AdguardTeam/AdGuardHome/internal/version'
readonly version_pkg
# Set the linker flags accordingly: set the release channel and the
# current version as well as goarm and gomips variable values, if the
# variables are set and are not empty.
readonly version_pkg='github.com/AdguardTeam/AdGuardHome/internal/version'
ldflags="-s -w"
ldflags="${ldflags} -X ${version_pkg}.version=${version}"
ldflags="${ldflags} -X ${version_pkg}.channel=${channel}"
@@ -74,39 +84,47 @@ then
fi
# Allow users to limit the build's parallelism.
readonly parallelism="${PARALLELISM:-}"
if [ "$parallelism" != '' ]
parallelism="${PARALLELISM:-}"
readonly parallelism
if [ "${parallelism}" != '' ]
then
readonly par_flags="-p ${parallelism}"
par_flags="-p ${parallelism}"
else
readonly par_flags=''
par_flags=''
fi
readonly par_flags
# Allow users to specify a different output name.
readonly out="${OUT:-}"
out="${OUT:-}"
readonly out
if [ "$out" != '' ]
then
readonly out_flags="-o ${out}"
out_flags="-o ${out}"
else
readonly out_flags=''
out_flags=''
fi
readonly out_flags
# Allow users to enable the race detector. Unfortunately, that means
# that CGo must be enabled.
readonly race="${RACE:-0}"
if [ "$race" = '0' ]
# Allow users to enable the race detector. Unfortunately, that means that cgo
# must be enabled.
if [ "${RACE:-0}" -eq '0' ]
then
readonly cgo_enabled='0'
readonly race_flags=''
cgo_enabled='0'
race_flags=''
else
readonly cgo_enabled='1'
readonly race_flags='--race'
cgo_enabled='1'
race_flags='--race'
fi
readonly cgo_enabled race_flags
export CGO_ENABLED="$cgo_enabled"
export GO111MODULE='on'
CGO_ENABLED="$cgo_enabled"
GO111MODULE='on'
export CGO_ENABLED GO111MODULE
readonly build_flags="${BUILD_FLAGS:-$race_flags --trimpath $out_flags $par_flags $v_flags $x_flags}"
build_flags="${BUILD_FLAGS:-$race_flags --trimpath $out_flags $par_flags $v_flags $x_flags}"
readonly build_flags
# Don't use quotes with flag variables to get word splitting.
"$go" generate $v_flags $x_flags ./main.go