From cb01eaa7f7332819c8b85119a75f069a92ff7be3 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Thu, 22 Apr 2021 20:06:34 +0300 Subject: [PATCH] Pull request: all: imp go version setting and detection Merge in DNS/adguard-home from imp-make to master Squashed commit of the following: commit 9ecb3422a55f5d010000bf4253a2766fefa67173 Author: Ainar Garipov Date: Thu Apr 22 19:59:36 2021 +0300 all: fix spelling commit c136f6562af80a67e627b472621ac68763f85fde Author: Ainar Garipov Date: Thu Apr 22 19:50:07 2021 +0300 all: imp go version setting and detection --- Makefile | 24 +++++++++++++----------- scripts/make/go-lint.sh | 27 +++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 52cb1d57..9e62684d 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,15 @@ CHANNEL = development CLIENT_BETA_DIR = client2 CLIENT_DIR = client -COMMIT = $$(git rev-parse --short HEAD) +COMMIT = $$( git rev-parse --short HEAD ) DIST_DIR = dist -# TODO(a.garipov): Find out a way to make this work in GNU Make. +# Don't name this macro "GO", because GNU Make apparenly makes it an +# exported environment variable with the literal value of "${GO:-go}", +# which is not what we need. Use a dot in the name to make sure that +# users don't have an environment variable with the same name. # -# GO = $${GO:-go} -# -GO = go +# See https://unix.stackexchange.com/q/646255/105635. +GO.MACRO = $${GO:-go} GOPROXY = https://goproxy.cn|https://proxy.golang.org|direct GPG_KEY = devteam@adguard.com GPG_KEY_PASSPHRASE = not-a-real-password @@ -37,9 +39,9 @@ ENV = env\ GPG_KEY='$(GPG_KEY)'\ GPG_KEY_PASSPHRASE='$(GPG_KEY_PASSPHRASE)'\ DIST_DIR='$(DIST_DIR)'\ - GO='$(GO)'\ + GO="$(GO.MACRO)"\ GOPROXY='$(GOPROXY)'\ - PATH="$${PWD}/bin:$$($(GO) env GOPATH)/bin:$${PATH}"\ + PATH="$${PWD}/bin:$$( "$(GO.MACRO)" env GOPATH )/bin:$${PATH}"\ RACE='$(RACE)'\ SIGN='$(SIGN)'\ VERBOSE='$(VERBOSE)'\ @@ -97,10 +99,10 @@ go-check: go-tools go-lint go-test # A quick check to make sure that all supported operating systems can be # typechecked and built successfully. go-os-check: - env GOOS='darwin' $(GO) vet ./internal/... - env GOOS='freebsd' $(GO) vet ./internal/... - env GOOS='linux' $(GO) vet ./internal/... - env GOOS='windows' $(GO) vet ./internal/... + env GOOS='darwin' "$(GO.MACRO)" vet ./internal/... + env GOOS='freebsd' "$(GO.MACRO)" vet ./internal/... + env GOOS='linux' "$(GO.MACRO)" vet ./internal/... + env GOOS='windows' "$(GO.MACRO)" vet ./internal/... openapi-lint: ; cd ./openapi/ && $(YARN) test openapi-show: ; cd ./openapi/ && $(YARN) start diff --git a/scripts/make/go-lint.sh b/scripts/make/go-lint.sh index 4ba752aa..1846d0da 100644 --- a/scripts/make/go-lint.sh +++ b/scripts/make/go-lint.sh @@ -27,7 +27,7 @@ set -f -u # Deferred Helpers -not_found_msg=' +readonly not_found_msg=' looks like a binary not found error. make sure you have installed the linter binaries using: @@ -49,6 +49,29 @@ trap not_found EXIT +# Warnings + +readonly go_min_version='go1.15' +readonly go_min_version_prefix="go version ${go_min_version}" +readonly go_version_msg=" +warning: your go version 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}' +" +case "$( "$GO" version )" +in +("$go_min_version_prefix"*) + # Go on. + ;; +(*) + echo "$go_version_msg" 1>&2 + ;; +esac + + + # Simple Analyzers # blocklist_imports is a simple check against unwanted packages. @@ -99,7 +122,7 @@ exit_on_output() ( cmd="$1" shift - output="$("$cmd" "$@" 2>&1)" + output="$( "$cmd" "$@" 2>&1 )" exitcode="$?" if [ "$exitcode" != '0' ] then