From 23c9f528db34cc619157c4bb2e672a32e7b681df Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 2 Apr 2021 13:44:55 +0300 Subject: [PATCH] Pull request: all: add race build mode Squashed commit of the following: commit 37ca2962b0c7ee870d07aee5043edcdeb2b2c2ad Author: Ainar Garipov Date: Fri Apr 2 13:27:32 2021 +0300 all: run tests with race enabled commit 20af1abb95f65c8fa46f6e00172ab8f54a785285 Author: Ainar Garipov Date: Fri Apr 2 13:14:36 2021 +0300 all: add race build mode --- Makefile | 7 ++++++- scripts/make/go-build.sh | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0eb2f8c5a02..863fef90c81 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ GPG_KEY = devteam@adguard.com GPG_KEY_PASSPHRASE = not-a-real-password NPM = npm NPM_FLAGS = --prefix $(CLIENT_DIR) +RACE = 0 SIGN = 1 VERBOSE = 0 VERSION = v0.0.0 @@ -30,6 +31,7 @@ ENV = env\ GO='$(GO)'\ GOPROXY='$(GOPROXY)'\ PATH="$${PWD}/bin:$$($(GO) env GOPATH)/bin:$${PATH}"\ + RACE='$(RACE)'\ SIGN='$(SIGN)'\ VERBOSE='$(VERBOSE)'\ VERSION='$(VERSION)'\ @@ -75,9 +77,12 @@ js-beta-test: ; # TODO(v.abdulmyanov): Add tests for the new client. go-build: ; $(ENV) "$(SHELL)" ./scripts/make/go-build.sh go-deps: ; $(ENV) "$(SHELL)" ./scripts/make/go-deps.sh go-lint: ; $(ENV) "$(SHELL)" ./scripts/make/go-lint.sh -go-test: ; $(ENV) "$(SHELL)" ./scripts/make/go-test.sh go-tools: ; $(ENV) "$(SHELL)" ./scripts/make/go-tools.sh +# TODO(a.garipov): Think about making RACE='1' the default for all +# targets. +go-test: ; $(ENV) RACE='1' "$(SHELL)" ./scripts/make/go-test.sh + go-check: go-tools go-lint go-test openapi-lint: ; cd ./openapi/ && $(YARN) test diff --git a/scripts/make/go-build.sh b/scripts/make/go-build.sh index 353ea7e2a40..aad1ab8aea6 100644 --- a/scripts/make/go-build.sh +++ b/scripts/make/go-build.sh @@ -91,10 +91,22 @@ else readonly out_flags='' fi -# Don't use cgo. Use modules. -export CGO_ENABLED='0' GO111MODULE='on' +# Allow users to enable the race detector. Unfortunately, that means +# that CGo must be enabled. +readonly race="${RACE:-0}" +if [ "$race" = '0' ] +then + readonly cgo_enabled='0' + readonly race_flags='' +else + readonly cgo_enabled='1' + readonly race_flags='--race' +fi + +export CGO_ENABLED="$cgo_enabled" +export GO111MODULE='on' -readonly build_flags="${BUILD_FLAGS:-$out_flags $par_flags\ +readonly build_flags="${BUILD_FLAGS:-$race_flags $out_flags $par_flags\ $v_flags $x_flags}" # Don't use quotes with flag variables to get word splitting.