Skip to content

Commit 55fd8c9

Browse files
authored
GODRIVER-2837 Backport safe Makefile to the release branch. (#1256)
1 parent a2c92f9 commit 55fd8c9

File tree

4 files changed

+54
-106
lines changed

4 files changed

+54
-106
lines changed

.evergreen/config.yml

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,6 @@ functions:
171171
git submodule init
172172
git submodule update
173173
174-
install-linters:
175-
- command: shell.exec
176-
params:
177-
working_dir: src/go.mongodb.org/mongo-driver
178-
script: |
179-
${PREPARE_SHELL}
180-
181-
# Install linters. Use "go install" instead of "go get" to prevent modifying the go.mod
182-
# file.
183-
go install github.com/golangci/golangci-lint/cmd/[email protected]
184-
go install github.com/walle/lll/...@latest
185-
186174
upload-mo-artifacts:
187175
- command: shell.exec
188176
params:
@@ -314,7 +302,7 @@ functions:
314302
working_dir: src/go.mongodb.org/mongo-driver
315303
script: |
316304
${PREPARE_SHELL}
317-
${BUILD_ENV|} make ${targets} BUILD_TAGS="-tags \"cse gssapi\""
305+
${BUILD_ENV|} make ${targets} BUILD_TAGS=${BUILD_TAGS|"-tags \"cse gssapi\""}
318306
319307
run-tests:
320308
- command: shell.exec
@@ -1045,7 +1033,6 @@ tasks:
10451033
- name: sa-fmt
10461034
tags: ["static-analysis"]
10471035
commands:
1048-
- func: install-linters
10491036
- func: run-make
10501037
vars:
10511038
targets: check-fmt
@@ -1060,7 +1047,6 @@ tasks:
10601047
- name: sa-lint
10611048
tags: ["static-analysis"]
10621049
commands:
1063-
- func: install-linters
10641050
- func: run-make
10651051
vars:
10661052
targets: "lint add-license"
@@ -1079,13 +1065,6 @@ tasks:
10791065
targets: driver-benchmark
10801066
- func: send-perf-data
10811067

1082-
- name: sa-build-examples
1083-
tags: ["static-analysis"]
1084-
commands:
1085-
- func: run-make
1086-
vars:
1087-
targets: build-examples
1088-
10891068
- name: test-standalone-noauth-nossl
10901069
tags: ["test", "standalone"]
10911070
commands:
@@ -1786,7 +1765,9 @@ tasks:
17861765
commands:
17871766
- func: run-make
17881767
vars:
1789-
targets: "build"
1768+
# The build target runs the build-tests dependency, which actually builds and runs the
1769+
# tests. That won't work with Go 1.13, so omit that task.
1770+
targets: "build -o build-tests"
17901771
# Use GO111MODULE=off to disable modules, as go versions less than
17911772
# 1.16 will complain about the retract directives in go.mod.
17921773
BUILD_ENV: "GO111MODULE=off PATH=/opt/golang/go1.13/bin:$PATH GOROOT=/opt/golang/go1.13"
@@ -1797,31 +1778,40 @@ tasks:
17971778
commands:
17981779
- func: run-make
17991780
vars:
1800-
targets: "build build-tests"
1781+
targets: "build"
18011782

18021783
- name: linux-32-bit
18031784
tags: ["compile-check"]
18041785
commands:
18051786
- func: run-make
18061787
vars:
1807-
targets: "build-no-tags"
1788+
# The build target runs the build-tests dependency, which actually builds and runs the
1789+
# tests. That won't work for cross-compiled binaries, so omit that task.
1790+
targets: "build -o build-tests"
18081791
BUILD_ENV: "GOARCH=386"
1792+
BUILD_TAGS: ""
18091793

18101794
- name: linux-arm64
18111795
tags: ["compile-check"]
18121796
commands:
18131797
- func: run-make
18141798
vars:
1815-
targets: "build-no-tags"
1799+
# The build target runs the build-tests dependency, which actually builds and runs the
1800+
# tests. That won't work for cross-compiled binaries, so omit that task.
1801+
targets: "build -o build-tests"
18161802
BUILD_ENV: "GOARCH=arm64"
1803+
BUILD_TAGS: ""
18171804

18181805
- name: linux-s390x
18191806
tags: ["compile-check"]
18201807
commands:
18211808
- func: run-make
18221809
vars:
1823-
targets: "build-no-tags"
1810+
# The build target runs the build-tests dependency, which actually builds and runs the
1811+
# tests. That won't work for cross-compiled binaries, so omit that task.
1812+
targets: "build -o build-tests"
18241813
BUILD_ENV: "GOARCH=ppc64le"
1814+
BUILD_TAGS: ""
18251815

18261816
- name: "atlas-test"
18271817
commands:

Makefile

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,35 @@
1-
# We list packages with shell scripts and loop through them to avoid testing with ./...
2-
# Running go test ./... will run tests in all packages concurrently which can lead to
3-
# unexpected errors.
4-
#
5-
# TODO(GODRIVER-2093): Use ./... to run tests in all packages with parallelism and remove
6-
# these PKG variables and loops from all make targets.
7-
PKGS = $(shell etc/list_pkgs.sh)
8-
TEST_PKGS = $(shell etc/list_test_pkgs.sh)
9-
101
ATLAS_URIS = "$(ATLAS_FREE)" "$(ATLAS_REPLSET)" "$(ATLAS_SHARD)" "$(ATLAS_TLS11)" "$(ATLAS_TLS12)" "$(ATLAS_FREE_SRV)" "$(ATLAS_REPLSET_SRV)" "$(ATLAS_SHARD_SRV)" "$(ATLAS_TLS11_SRV)" "$(ATLAS_TLS12_SRV)" "$(ATLAS_SERVERLESS)" "$(ATLAS_SERVERLESS_SRV)"
11-
GODISTS=linux/amd64 linux/386 linux/arm64 linux/arm linux/s390x
122
TEST_TIMEOUT = 1800
133

144
### Utility targets. ###
155
.PHONY: default
16-
default: add-license build build-examples check-env check-fmt check-modules lint test-short
6+
default: add-license build check-fmt check-modules lint test-short
177

8+
# Find all .go files not in the vendor directory and try to write a license notice. Then check for
9+
# any changes made with -G. to ignore permissions changes. Exit with a non-zero exit code if there
10+
# is a diff.
1811
.PHONY: add-license
1912
add-license:
20-
# Find all .go files not in the vendor directory and try to write a license notice.
2113
find . -path ./vendor -prune -o -type f -name "*.go" -print | xargs ./etc/add_license.sh
22-
# Check for any changes made with -G. to ignore permissions changes. Exit with a non-zero
23-
# exit code if there is a diff.
2414
git diff -G. --quiet
2515

2616
.PHONY: build
27-
build:
28-
go build $(BUILD_TAGS) $(PKGS)
29-
30-
.PHONY: build-examples
31-
build-examples:
32-
go build $(BUILD_TAGS) ./examples/...
33-
34-
.PHONY: build-no-tags
35-
build-no-tags:
36-
go build $(PKGS)
17+
build: build-tests
18+
go build $(BUILD_TAGS) ./...
3719

20+
# Use ^$ to match no tests so that no tests are actually run but all tests are
21+
# compiled. Run with -short to ensure none of the TestMain functions try to
22+
# connect to a server.
3823
.PHONY: build-tests
3924
build-tests:
40-
for TEST in $(TEST_PKGS); do \
41-
go test $(BUILD_TAGS) -c $$TEST ; \
42-
if [ $$? -ne 0 ]; \
43-
then \
44-
exit 1; \
45-
fi \
46-
done
25+
go test -short $(BUILD_TAGS) -run ^$$ ./...
26+
27+
.PHONY: install-lll
28+
install-lll:
29+
go install github.com/walle/lll/...@latest
4730

4831
.PHONY: check-fmt
49-
check-fmt:
32+
check-fmt: install-lll
5033
etc/check_fmt.sh
5134

5235
# check-modules runs "go mod tidy" then "go mod vendor" and exits with a non-zero exit code if there
@@ -71,15 +54,21 @@ doc:
7154
fmt:
7255
go fmt ./...
7356

57+
.PHONY: install-golangci-lint
58+
install-golangci-lint:
59+
go install github.com/golangci/golangci-lint/cmd/[email protected]
60+
61+
# Lint with various GOOS and GOARCH targets to catch static analysis failures that may only affect
62+
# specific operating systems or architectures. For example, staticcheck will only check for 64-bit
63+
# alignment of atomically accessed variables on 32-bit architectures (see
64+
# https://staticcheck.io/docs/checks#SA1027)
7465
.PHONY: lint
75-
lint:
76-
for dist in $(GODISTS); do \
77-
goos=$$(echo $$dist | cut -d/ -f 1) ; \
78-
goarch=$$(echo $$dist | cut -d/ -f 2) ; \
79-
command="GOOS=$$goos GOARCH=$$goarch golangci-lint run --config .golangci.yml ./..." ; \
80-
echo $$command ; \
81-
eval $$command ; \
82-
done
66+
lint: install-golangci-lint
67+
GOOS=linux GOARCH=amd64 golangci-lint run --config .golangci.yml ./...
68+
GOOS=linux GOARCH=386 golangci-lint run --config .golangci.yml ./...
69+
GOOS=linux GOARCH=arm64 golangci-lint run --config .golangci.yml ./...
70+
GOOS=linux GOARCH=arm golangci-lint run --config .golangci.yml ./...
71+
GOOS=linux GOARCH=s390x golangci-lint run --config .golangci.yml ./...
8372

8473
.PHONY: update-notices
8574
update-notices:
@@ -88,25 +77,19 @@ update-notices:
8877
### Local testing targets. ###
8978
.PHONY: test
9079
test:
91-
for TEST in $(TEST_PKGS) ; do \
92-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s $$TEST ; \
93-
done
80+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -p 1 ./...
9481

9582
.PHONY: test-cover
9683
test-cover:
97-
for TEST in $(TEST_PKGS) ; do \
98-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -cover $(COVER_ARGS) $$TEST ; \
99-
done
84+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -cover $(COVER_ARGS) -p 1 ./...
10085

10186
.PHONY: test-race
10287
test-race:
103-
for TEST in $(TEST_PKGS) ; do \
104-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -race $$TEST ; \
105-
done
88+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -race -p 1 ./...
10689

10790
.PHONY: test-short
10891
test-short:
109-
go test $(BUILD_TAGS) -timeout 60s -short $(TEST_PKGS)
92+
go test $(BUILD_TAGS) -timeout 60s -short ./...
11093

11194
### Evergreen specific targets. ###
11295
.PHONY: build-aws-ecs-test
@@ -115,9 +98,7 @@ build-aws-ecs-test:
11598

11699
.PHONY: evg-test
117100
evg-test:
118-
for TEST in $(TEST_PKGS); do \
119-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s $$TEST >> test.suite ; \
120-
done
101+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s -p 1 ./... >> test.suite
121102

122103
.PHONY: evg-test-atlas
123104
evg-test-atlas:
@@ -186,9 +167,9 @@ evg-test-serverless:
186167
.PHONY: evg-test-versioned-api
187168
evg-test-versioned-api:
188169
# Versioned API related tests are in the mongo, integration and unified packages.
189-
for TEST_PKG in ./mongo ./mongo/integration ./mongo/integration/unified; do \
190-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s $$TEST_PKG >> test.suite ; \
191-
done
170+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo >> test.suite
171+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration >> test.suite
172+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration/unified >> test.suite
192173

193174
.PHONY: build-gcpkms-test
194175
build-gcpkms-test:

etc/list_pkgs.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

etc/list_test_pkgs.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)