Skip to content

Commit af32687

Browse files
authored
Merge pull request #108 from elezar/add-mod-tidy-tooling
Add a vendor make target for updating go module files
2 parents 951edbb + b86c208 commit af32687

File tree

4 files changed

+95
-8
lines changed

4 files changed

+95
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.swp
22
schema/validate
3+
/bin

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+

cmd/validate/go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/container-orchestrated-devices/container-device-interface/cmd/validate
2+
3+
go 1.19
4+
5+
require github.com/container-orchestrated-devices/container-device-interface v0.0.0
6+
7+
require (
8+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
9+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
10+
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
11+
gopkg.in/yaml.v2 v2.4.0 // indirect
12+
sigs.k8s.io/yaml v1.3.0 // indirect
13+
)
14+
15+
replace github.com/container-orchestrated-devices/container-device-interface => ../..

cmd/validate/go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
5+
github.com/opencontainers/runc v1.1.2 h1:2VSZwLx5k/BfsBxMMipG/LYUnmqOD/BPkIVgQUcTlLw=
6+
github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb h1:1xSVPOd7/UA+39/hXEGnBJ13p6JFB0E1EvQFlrRDOXI=
7+
github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626 h1:DmNGcqH3WDbV5k8OJ+esPWbqUOX5rMLR2PMvziDMJi0=
8+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
12+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
13+
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
14+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
15+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
16+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
17+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
18+
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
19+
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
20+
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
21+
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c h1:DHcbWVXeY+0Y8HHKR+rbLwnoh2F4tNCY7rTiHJ30RmA=
22+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
23+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
24+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
25+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
26+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
27+
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
28+
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

0 commit comments

Comments
 (0)