Skip to content

Commit 948c5e9

Browse files
Merge pull request containers#13870 from kolyshkin/makefile-cleanups
Makefile: simplify for modern Go
2 parents 7093885 + 6531170 commit 948c5e9

File tree

6 files changed

+43
-108
lines changed

6 files changed

+43
-108
lines changed

Diff for: .cirrus.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ env:
77
####
88
# Name of the ultimate destination branch for this CI run, PR or post-merge.
99
DEST_BRANCH: "main"
10+
# Sane (default) value for GOPROXY and GOSUMDB.
11+
GOPROXY: "https://proxy.golang.org,direct"
12+
GOSUMDB: "sum.golang.org"
1013
# Overrides default location (/tmp/cirrus) for repo clone
1114
GOPATH: &gopath "/var/tmp/go"
12-
GOBIN: "${GOPATH}/bin"
1315
GOCACHE: "${GOPATH}/cache"
1416
GOSRC: &gosrc "/var/tmp/go/src/github.com/containers/podman"
1517
CIRRUS_WORKING_DIR: *gosrc

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ tags
4040
result
4141
# Necessary to prevent hack/tree-status.sh false-positive
4242
/*runner_stats.log
43-
.install.goimports
4443
.generate-bindings

Diff for: Makefile

+31-81
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020
### Variables & Definitions
2121
###
2222

23-
export GOPROXY=https://proxy.golang.org
24-
2523
GO ?= go
2624
GO_LDFLAGS:= $(shell if $(GO) version|grep -q gccgo ; then echo "-gccgoflags"; else echo "-ldflags"; fi)
2725
GOCMD = CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO)
2826
COVERAGE_PATH ?= .coverage
2927
DESTDIR ?=
3028
EPOCH_TEST_COMMIT ?= $(shell git merge-base $${DEST_BRANCH:-main} HEAD)
3129
HEAD ?= HEAD
32-
CHANGELOG_BASE ?= HEAD~
33-
CHANGELOG_TARGET ?= HEAD
3430
PROJECT := github.com/containers/podman
3531
GIT_BASE_BRANCH ?= origin/main
3632
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
@@ -69,8 +65,6 @@ PRE_COMMIT = $(shell command -v bin/venv/bin/pre-commit ~/.local/bin/pre-commit
6965
# triggered.
7066
SOURCES = $(shell find . -path './.*' -prune -o \( \( -name '*.go' -o -name '*.c' \) -a ! -name '*_test.go' \) -print)
7167

72-
BUILDFLAGS := -mod=vendor $(BUILDFLAGS)
73-
7468
BUILDTAGS_CROSS ?= containers_image_openpgp exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_overlay
7569
CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker)
7670
OCI_RUNTIME ?= ""
@@ -90,10 +84,8 @@ GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),${COMMIT
9084
DATE_FMT = %s
9185
ifdef SOURCE_DATE_EPOCH
9286
BUILD_INFO ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")
93-
ISODATE ?= $(shell date -d "@$(SOURCE_DATE_EPOCH)" --iso-8601)
9487
else
9588
BUILD_INFO ?= $(shell date "+$(DATE_FMT)")
96-
ISODATE ?= $(shell date --iso-8601)
9789
endif
9890
LIBPOD := ${PROJECT}/v4/libpod
9991
GOFLAGS ?= -trimpath
@@ -120,22 +112,10 @@ RELEASE_NUMBER = $(shell echo "$(RELEASE_VERSION)" | sed -e 's/^v\(.*\)/\1/')
120112
# If non-empty, logs all output from server during remote system testing
121113
PODMAN_SERVER_LOG ?=
122114

123-
# If GOPATH not specified, use one in the local directory
124-
ifeq ($(GOPATH),)
125-
export GOPATH := $(HOME)/go
126-
unexport GOBIN
127-
endif
128-
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
129-
GOPKGDIR := $(FIRST_GOPATH)/src/$(PROJECT)
130-
GOPKGBASEDIR ?= $(shell dirname "$(GOPKGDIR)")
131-
132-
GOBIN := $(shell $(GO) env GOBIN)
133-
ifeq ($(GOBIN),)
134-
GOBIN := $(FIRST_GOPATH)/bin
135-
endif
136-
115+
# Ensure GOBIN is not set so the default (`go env GOPATH`/bin) is used.
116+
override undefine GOBIN
137117
# This must never include the 'hack' directory
138-
export PATH := $(PATH):$(GOBIN)
118+
export PATH := $(shell $(GO) env GOPATH)/bin:$(PATH)
139119

140120
GOMD2MAN ?= $(shell command -v go-md2man || echo './test/tools/build/go-md2man')
141121

@@ -223,15 +203,8 @@ help: ## (Default) Print listing of key targets with their descriptions
223203
### Linting/Formatting/Code Validation targets
224204
###
225205

226-
.gopathok:
227-
ifeq ("$(wildcard $(GOPKGDIR))","")
228-
mkdir -p "$(GOPKGBASEDIR)"
229-
ln -sfn "$(CURDIR)" "$(GOPKGDIR)"
230-
endif
231-
touch $@
232-
233206
.PHONY: .gitvalidation
234-
.gitvalidation: .gopathok
207+
.gitvalidation:
235208
@echo "Validating vs commit '$(call err_if_empty,EPOCH_TEST_COMMIT)'"
236209
GIT_CHECK_EXCLUDE="./vendor:./test/tools/vendor:docs/make.bat:test/buildah-bud/buildah-tests.diff" ./test/tools/build/git-validation -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..$(HEAD)
237210

@@ -245,46 +218,34 @@ endif
245218
$(PRE_COMMIT) run -a
246219

247220
.PHONY: golangci-lint
248-
golangci-lint: .gopathok .install.golangci-lint
221+
golangci-lint: .install.golangci-lint
249222
hack/golangci-lint.sh run
250223

251-
.PHONY: gofmt
252-
gofmt: ## Verify the source code gofmt
253-
find . -name '*.go' -type f \
254-
-not \( \
255-
-name '.golangci.yml' -o \
256-
-name 'Makefile' -o \
257-
-path './vendor/*' -prune -o \
258-
-path './test/tools/vendor/*' -prune -o \
259-
-path './contrib/*' -prune \
260-
\) -exec gofmt -d -e -s -w {} \+
261-
git diff --exit-code
262-
263224
.PHONY: test/checkseccomp/checkseccomp
264-
test/checkseccomp/checkseccomp: .gopathok $(wildcard test/checkseccomp/*.go)
225+
test/checkseccomp/checkseccomp: $(wildcard test/checkseccomp/*.go)
265226
$(GOCMD) build $(BUILDFLAGS) $(GO_LDFLAGS) '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./test/checkseccomp
266227

267228
.PHONY: test/testvol/testvol
268-
test/testvol/testvol: .gopathok $(wildcard test/testvol/*.go)
229+
test/testvol/testvol: $(wildcard test/testvol/*.go)
269230
$(GOCMD) build $(BUILDFLAGS) $(GO_LDFLAGS) '$(LDFLAGS_PODMAN)' -o $@ ./test/testvol
270231

271232
.PHONY: volume-plugin-test-image
272233
volume-plugin-test-img:
273234
podman build -t quay.io/libpod/volume-plugin-test-img -f Containerfile-testvol .
274235

275236
.PHONY: test/goecho/goecho
276-
test/goecho/goecho: .gopathok $(wildcard test/goecho/*.go)
237+
test/goecho/goecho: $(wildcard test/goecho/*.go)
277238
$(GOCMD) build $(BUILDFLAGS) $(GO_LDFLAGS) '$(LDFLAGS_PODMAN)' -o $@ ./test/goecho
278239

279-
test/version/version: .gopathok version/version.go
240+
test/version/version: version/version.go
280241
$(GO) build -o $@ ./test/version/
281242

282243
.PHONY: codespell
283244
codespell:
284245
codespell -S bin,vendor,.git,go.sum,.cirrus.yml,"RELEASE_NOTES.md,*.xz,*.gz,*.ps1,*.tar,swagger.yaml,*.tgz,bin2img,*ico,*.png,*.1,*.5,copyimg,*.orig,apidoc.go" -L uint,iff,od,seeked,splitted,marge,ERRO,hist,ether -w
285246

286247
.PHONY: validate
287-
validate: gofmt lint .gitvalidation validate.completions man-page-check swagger-check tests-included tests-expect-exit
248+
validate: lint .gitvalidation validate.completions man-page-check swagger-check tests-included tests-expect-exit
288249

289250
.PHONY: build-all-new-commits
290251
build-all-new-commits:
@@ -293,9 +254,9 @@ build-all-new-commits:
293254

294255
.PHONY: vendor
295256
vendor:
296-
GO111MODULE=on $(GO) mod tidy
297-
GO111MODULE=on $(GO) mod vendor
298-
GO111MODULE=on $(GO) mod verify
257+
$(GO) mod tidy
258+
$(GO) mod vendor
259+
$(GO) mod verify
299260

300261
.PHONY: vendor-in-container
301262
vendor-in-container:
@@ -309,7 +270,7 @@ vendor-in-container:
309270
###
310271

311272
# Make sure to warn in case we're building without the systemd buildtag.
312-
bin/podman: .gopathok $(SOURCES) go.mod go.sum
273+
bin/podman: $(SOURCES) go.mod go.sum
313274
ifeq (,$(findstring systemd,$(BUILDTAGS)))
314275
@echo "Podman is being compiled without the systemd build tag. \
315276
Install libsystemd on Ubuntu or systemd-devel on rpm based \
@@ -325,14 +286,14 @@ endif
325286
$(SRCBINDIR):
326287
mkdir -p $(SRCBINDIR)
327288

328-
$(SRCBINDIR)/podman$(BINSFX): $(SRCBINDIR) .gopathok $(SOURCES) go.mod go.sum
289+
$(SRCBINDIR)/podman$(BINSFX): $(SRCBINDIR) $(SOURCES) go.mod go.sum
329290
$(GOCMD) build \
330291
$(BUILDFLAGS) \
331292
$(GO_LDFLAGS) '$(LDFLAGS_PODMAN)' \
332293
-tags "${REMOTETAGS}" \
333294
-o $@ ./cmd/podman
334295

335-
$(SRCBINDIR)/podman-remote-static: $(SRCBINDIR) .gopathok $(SOURCES) go.mod go.sum
296+
$(SRCBINDIR)/podman-remote-static: $(SRCBINDIR) $(SOURCES) go.mod go.sum
336297
CGO_ENABLED=0 \
337298
GOOS=$(GOOS) \
338299
GOARCH=$(GOARCH) \
@@ -368,7 +329,7 @@ podman-remote-windows: ## Build podman-remote for Windows
368329
bin/windows/podman.exe
369330

370331
.PHONY: podman-winpath
371-
podman-winpath: .gopathok $(SOURCES) go.mod go.sum
332+
podman-winpath: $(SOURCES) go.mod go.sum
372333
CGO_ENABLED=0 \
373334
GOOS=windows \
374335
$(GO) build \
@@ -395,7 +356,7 @@ podman-mac-helper: ## Build podman-mac-helper for macOS
395356
-o bin/darwin/podman-mac-helper \
396357
./cmd/podman-mac-helper
397358

398-
bin/rootlessport: .gopathok $(SOURCES) go.mod go.sum
359+
bin/rootlessport: $(SOURCES) go.mod go.sum
399360
CGO_ENABLED=$(CGO_ENABLED) \
400361
$(GO) build \
401362
$(BUILDFLAGS) \
@@ -411,11 +372,11 @@ rootlessport: bin/rootlessport
411372
.PHONY: generate-bindings
412373
generate-bindings:
413374
ifneq ($(GOOS),darwin)
414-
GO111MODULE=off $(GOCMD) generate ./pkg/bindings/... ;
375+
$(GOCMD) generate ./pkg/bindings/... ;
415376
endif
416377

417378
# DO NOT USE: use local-cross instead
418-
bin/podman.cross.%: .gopathok
379+
bin/podman.cross.%:
419380
TARGET="$*"; \
420381
GOOS="$${TARGET%%.*}"; \
421382
GOARCH="$${TARGET##*.}"; \
@@ -455,7 +416,7 @@ completions: podman podman-remote
455416
### Documentation targets
456417
###
457418

458-
pkg/api/swagger.yaml: .gopathok
419+
pkg/api/swagger.yaml:
459420
make -C pkg/api
460421

461422
$(MANPAGES): %: %.md .install.md2man docdir
@@ -531,7 +492,7 @@ run-docker-py-tests:
531492
.PHONY: localunit
532493
localunit: test/goecho/goecho test/version/version
533494
rm -rf ${COVERAGE_PATH} && mkdir -p ${COVERAGE_PATH}
534-
UNIT=1 $(GOBIN)/ginkgo \
495+
UNIT=1 ginkgo \
535496
-r \
536497
$(TESTFLAGS) \
537498
--skipPackage test/e2e,pkg/apparmor,pkg/bindings,hack,pkg/machine/e2e \
@@ -550,8 +511,8 @@ test: localunit localintegration remoteintegration localsystem remotesystem ##
550511

551512
.PHONY: ginkgo-run
552513
ginkgo-run:
553-
ACK_GINKGO_RC=true $(GOBIN)/ginkgo version
554-
ACK_GINKGO_RC=true $(GOBIN)/ginkgo -v $(TESTFLAGS) -tags "$(TAGS)" $(GINKGOTIMEOUT) -cover -flakeAttempts 3 -progress -trace -noColor -nodes 3 -debug test/e2e/. $(HACK)
514+
ACK_GINKGO_RC=true ginkgo version
515+
ACK_GINKGO_RC=true ginkgo -v $(TESTFLAGS) -tags "$(TAGS)" $(GINKGOTIMEOUT) -cover -flakeAttempts 3 -progress -trace -noColor -nodes 3 -debug test/e2e/. $(HACK)
555516

556517
.PHONY: ginkgo
557518
ginkgo:
@@ -569,7 +530,7 @@ remoteintegration: test-binaries ginkgo-remote
569530

570531
.PHONY: localbenchmarks
571532
localbenchmarks: test-binaries
572-
PATH=$(PATH):$(shell pwd)/hack ACK_GINKGO_RC=true $(GOBIN)/ginkgo \
533+
PATH=$(PATH):$(shell pwd)/hack ACK_GINKGO_RC=true ginkgo \
573534
-focus "Podman Benchmark Suite" \
574535
-tags "$(BUILDTAGS) benchmarks" -noColor \
575536
-noisySkippings=false -noisyPendings=false \
@@ -759,7 +720,7 @@ package-install: package ## Install rpm packages
759720
/usr/bin/podman info # will catch a broken conmon
760721

761722
.PHONY: install
762-
install: .gopathok install.bin install.remote install.man install.systemd ## Install binaries to system locations
723+
install: install.bin install.remote install.man install.systemd ## Install binaries to system locations
763724

764725
.PHONY: install.catatonit
765726
install.catatonit:
@@ -865,14 +826,12 @@ install.tools: .install.ginkgo .install.golangci-lint .install.bats ## Install n
865826
make -C test/tools
866827

867828
.PHONY: .install.ginkgo
868-
.install.ginkgo: .gopathok
869-
if [ ! -x "$(GOBIN)/ginkgo" ]; then \
870-
$(GO) install $(BUILDFLAGS) ./vendor/github.com/onsi/ginkgo/ginkgo ; \
871-
fi
829+
.install.ginkgo:
830+
$(GO) install $(BUILDFLAGS) ./vendor/github.com/onsi/ginkgo/ginkgo
872831

873832
.PHONY: .install.golangci-lint
874-
.install.golangci-lint: .gopathok
875-
VERSION=1.45.2 GOBIN=$(GOBIN) ./hack/install_golangci.sh
833+
.install.golangci-lint:
834+
VERSION=1.45.2 ./hack/install_golangci.sh
876835

877836
.PHONY: .install.md2man
878837
.install.md2man:
@@ -881,7 +840,7 @@ install.tools: .install.ginkgo .install.golangci-lint .install.bats ## Install n
881840
fi
882841

883842
.PHONY: .install.bats
884-
.install.bats: .gopathok
843+
.install.bats:
885844
VERSION=v1.1.0 ./hack/install_bats.sh
886845

887846
.PHONY: .install.pre-commit
@@ -890,13 +849,6 @@ install.tools: .install.ginkgo .install.golangci-lint .install.bats ## Install n
890849
python3 -m pip install --user pre-commit; \
891850
fi
892851

893-
# $BUILD_TAGS variable is used in hack/golangci-lint.sh
894-
.PHONY: install.libseccomp.sudo
895-
install.libseccomp.sudo:
896-
rm -rf ../../seccomp/libseccomp
897-
git clone https://github.com/seccomp/libseccomp ../../seccomp/libseccomp
898-
cd ../../seccomp/libseccomp && git checkout --detach $(LIBSECCOMP_COMMIT) && ./autogen.sh && ./configure --prefix=/usr && make all && make install
899-
900852
.PHONY: uninstall
901853
uninstall:
902854
for i in $(filter %.1,$(MANPAGES_DEST)); do \
@@ -927,7 +879,6 @@ clean-binaries: ## Remove platform/architecture specific binary files
927879
.PHONY: clean
928880
clean: clean-binaries ## Clean all make artifacts
929881
rm -rf \
930-
.gopathok \
931882
_output \
932883
$(wildcard podman-*.msi) \
933884
$(wildcard podman-remote*.zip) \
@@ -943,7 +894,6 @@ clean: clean-binaries ## Clean all make artifacts
943894
libpod/pod_ffjson.go \
944895
libpod/container_easyjson.go \
945896
libpod/pod_easyjson.go \
946-
.install.goimports \
947897
docs/build \
948898
.venv
949899
make -C docs clean

Diff for: contrib/cirrus/pr-should-include-tests

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ filtered_changes=$(git diff --name-only $base $head |
3434
fgrep -vx .cirrus.yml |
3535
fgrep -vx .pre-commit-config.yaml |
3636
fgrep -vx .gitignore |
37-
fgrep -vx Makefile |
3837
fgrep -vx go.mod |
3938
fgrep -vx go.sum |
39+
fgrep -vx podman.spec.rpkg |
40+
fgrep -vx .golangci.yml |
41+
egrep -v '/*Makefile$' |
4042
egrep -v '^[^/]+\.md$' |
4143
egrep -v '^.github' |
4244
egrep -v '^contrib/' |

Diff for: pkg/api/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export GO111MODULE=off
2-
31
SWAGGER_OUT ?= swagger.yaml
42

53
validate: ${SWAGGER_OUT}

0 commit comments

Comments
 (0)