Pull request 2147: all: upd deps, go, scripts

Squashed commit of the following:

commit 425f1bd28074d22890629d06f43257e0353ce3d5
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Feb 8 20:15:58 2024 +0300

    all: upd deps, go, scripts
This commit is contained in:
Ainar Garipov
2024-02-08 20:39:18 +03:00
parent 02ea4a362c
commit 332621f268
62 changed files with 249 additions and 174 deletions

View File

@@ -87,6 +87,22 @@ Optional environment:
* `VERSION`: release version. Will be set by `version.sh` if it is unset or
if it has the default `Makefile` value of `v0.0.0`.
We're using Go's [forward compatibility mechanism][go-toolchain] for updating
the Go version. This means that if your `go` version is 1.21+ but is different
from the one required by AdGuard Home, the `go` tool will automatically download
the required version.
If you want to use the version installed on your builder, run:
```sh
go get go@$YOUR_VERSION
go mod tidy
```
and call `make` with `GOTOOLCHAIN=local`.
[go-toolchain]: https://go.dev/blog/toolchain
### `clean.sh`: Cleanup

View File

@@ -9,12 +9,12 @@ import (
"net/http"
"net/url"
"os"
"slices"
"strings"
"text/template"
"time"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/exp/slices"
)
func main() {

View File

@@ -6,7 +6,9 @@ set -e -f -u
# Bump this number every time a significant change is made to this
# script.
#
# AdGuard-Project-Version: 1
# AdGuard-Project-Version: 2
# TODO(a.garipov): Add pre-merge-commit.
# Only show interactive prompts if there a terminal is attached to
# stdout. While this technically doesn't guarantee that reading from

View File

@@ -30,33 +30,6 @@ set -f -u
# Warnings
go_version="$( "${GO:-go}" version )"
readonly go_version
go_min_version='go1.20.12'
go_version_msg="
warning: your go version (${go_version}) is different from the recommended minimal one (${go_min_version}).
if you have the version installed, please set the GO environment variable.
for example:
export GO='${go_min_version}'
"
readonly go_min_version go_version_msg
case "$go_version"
in
('go version'*"$go_min_version"*)
# Go on.
;;
(*)
echo "$go_version_msg" 1>&2
;;
esac
# Simple analyzers
# blocklist_imports is a simple check against unwanted packages. The following
@@ -74,18 +47,22 @@ esac
#
# See https://github.com/golang/go/issues/45200.
#
# * Package sort is replaced by golang.org/x/exp/slices.
# * Package sort is replaced by package slices.
#
# * Package unsafe is… unsafe.
#
# * Package golang.org/x/exp/slices has been moved into stdlib.
#
# * Package golang.org/x/net/context has been moved into stdlib.
#
# Currently, the only standard exception are files generated from protobuf
# schemas, which use package reflect. If your project needs more exceptions,
# add and document them.
#
# TODO(a.garipov): Add deprecated packages golang.org/x/exp/maps and
# golang.org/x/exp/slices once all projects switch to Go 1.21.
# TODO(a.garipov): Add goilbs/log.
#
# TODO(a.garipov): Add deprecated package golang.org/x/exp/maps once all
# projects switch to Go 1.22.
blocklist_imports() {
git grep\
-e '[[:space:]]"errors"$'\
@@ -94,6 +71,7 @@ blocklist_imports() {
-e '[[:space:]]"reflect"$'\
-e '[[:space:]]"sort"$'\
-e '[[:space:]]"unsafe"$'\
-e '[[:space:]]"golang.org/x/exp/slices"$'\
-e '[[:space:]]"golang.org/x/net/context"$'\
-n\
-- '*.go'\
@@ -124,12 +102,10 @@ underscores() {
underscore_files="$(
git ls-files '*_*.go'\
| grep -F\
-e '_big.go'\
-e '_bsd.go'\
-e '_darwin.go'\
-e '_freebsd.go'\
-e '_linux.go'\
-e '_little.go'\
-e '_next.go'\
-e '_openbsd.go'\
-e '_others.go'\

View File

@@ -51,9 +51,9 @@ readonly count_flags cover_flags shuffle_flags timeout_flags
"$go" test\
"$count_flags"\
"$cover_flags"\
"$shuffle_flags"\
"$race_flags"\
"$shuffle_flags"\
"$timeout_flags"\
"$x_flags"\
"$v_flags"\
"$x_flags"\
./...

View File

@@ -30,8 +30,6 @@ set -e -f -u
go="${GO:-go}"
readonly go
# TODO(a.garipov): Add goconst?
# Remove only the actual binaries in the bin/ directory, as developers may add
# their own scripts there. Most commonly, a script named “go” for tools that
# call the go binary and need a particular version.

View File

@@ -0,0 +1,33 @@
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a significant change is made to this script.
#
# AdGuard-Project-Version: 1
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '1' ]
then
env
set -x
x_flags='-x=1'
elif [ "$verbose" -gt '0' ]
then
set -x
x_flags='-x=0'
else
set +x
x_flags='-x=0'
fi
readonly x_flags
set -e -f -u
go="${GO:-go}"
readonly go
cd ./internal/tools/
"$go" get -u
"$go" mod tidy

View File

@@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"time"
@@ -15,7 +16,6 @@ import (
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/ioutil"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/exp/slices"
)
// download and save all translations.

View File

@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"time"
@@ -18,7 +19,6 @@ import (
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)
const (