Skip to content

Commit 5ae9adb

Browse files
committed
Add mod-tidy and mod-verify make targets to ensure that all go modules are up to date
This change adds mod-tidy and mod-verify make targets that mirror what is done for containerd. This should ensure that the module files in the root as well as in subfolders are up to date. Signed-off-by: Evan Lezar <[email protected]>
1 parent f854d96 commit 5ae9adb

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

Makefile

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Copyright © The CDI Authors
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
112
GO_CMD := go
213
GO_BUILD := $(GO_CMD) build
314
GO_TEST := $(GO_CMD) test -race -v -cover
@@ -8,7 +19,8 @@ GO_VET := $(GO_CMD) vet
819

920
CDI_PKG := $(shell grep ^module go.mod | sed 's/^module *//g')
1021

11-
BINARIES := bin/cdi bin/validate
22+
CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/))))
23+
BINARIES := $(patsubst %,bin/%,$(CMDS))
1224

1325
ifneq ($(V),1)
1426
Q := @
@@ -45,13 +57,37 @@ vet:
4557
# build targets
4658
#
4759

48-
bin/%:
49-
$(Q)echo "Building $@..."; \
50-
$(GO_BUILD) -o $@ ./$(subst bin/,cmd/,$@)
60+
$(BINARIES): bin/%:
61+
$(Q)echo "Building $@..."
62+
$(Q)(cd cmd/$(*) && $(GO_BUILD) -o $(abspath $@) .)
63+
64+
#
65+
# go module tidy and verify targets
66+
#
67+
.PHONY: mod-tidy $(CMD_MOD_TIDY_TARGETS) mod-tidy-root
68+
.PHONY: mod-verify $(CMD_MOD_VERIFY_TARGETS) mod-verify-root
69+
70+
CMD_MOD_TIDY_TARGETS := mod-tidy-cdi mod-tidy-validate
71+
CMD_MOD_VERIFY_TARGETS := mod-verify-cdi mod-verify-validate
72+
73+
mod-tidy-root:
74+
$(Q)echo "Running $@..."; \
75+
$(GO_CMD) mod tidy
76+
77+
$(CMD_MOD_TIDY_TARGETS): mod-tidy-%: mod-tidy-root
78+
$(Q)echo "Running $@... in $(abspath ./cmd/$(*))"; \
79+
(cd $(abspath ./cmd/$(*)) && $(GO_CMD) mod tidy)
80+
81+
mod-verify-root: mod-tidy-root
82+
$(Q)echo "Running $@..."; \
83+
$(GO_CMD) mod verify
5184

52-
bin/cdi:
53-
$(Q)echo "Building $@..."; \
54-
cd cmd/cdi; $(GO_BUILD) -o $(abspath $@) .
85+
$(CMD_MOD_VERIFY_TARGETS): mod-verify-%: mod-tidy-% mod-verify-root
86+
$(Q)echo "Running $@... in $(abspath ./cmd/$(*))"; \
87+
(cd $(abspath ./cmd/$(*)) && pwd && $(GO_CMD) mod verify)
88+
89+
mod-verify: $(CMD_MOD_VERIFY_TARGETS)
90+
mod-tidy: $(CMD_MOD_TIDY_TARGETS)
5591

5692
#
5793
# cleanup targets
@@ -83,7 +119,13 @@ test-schema: bin/validate
83119
# dependencies
84120
#
85121

86-
bin/validate: cmd/validate/validate.go $(wildcard schema/*.json)
122+
bin/validate: $(wildcard schema/*.json) $(wildcard cmd/validate/*.go cmd/validate/cmd/*.go) $(shell \
123+
for dir in \
124+
$$(cd ./cmd/validate; $(GO_CMD) list -f '{{ join .Deps "\n"}}' ./... | \
125+
grep $(CDI_PKG)/pkg/ | \
126+
sed 's:$(CDI_PKG):.:g'); do \
127+
find $$dir -name \*.go; \
128+
done | sort | uniq)
87129

88130
# quasi-automatic dependency for bin/cdi
89131
bin/cdi: $(wildcard cmd/cdi/*.go cmd/cdi/cmd/*.go) $(shell \
@@ -93,3 +135,4 @@ bin/cdi: $(wildcard cmd/cdi/*.go cmd/cdi/cmd/*.go) $(shell \
93135
sed 's:$(CDI_PKG):.:g'); do \
94136
find $$dir -name \*.go; \
95137
done | sort | uniq)
138+

0 commit comments

Comments
 (0)