From f854d96a293217c32955c477f4ae575f41ac71b7 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 10 Feb 2023 15:13:23 +0100 Subject: [PATCH 1/3] Add bin to .gitignore Signed-off-by: Evan Lezar --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8ff0871..891783c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp schema/validate +/bin From 5ae9adbe9231a76c3cfc8a81a1afa685817db239 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 9 Feb 2023 13:47:55 +0100 Subject: [PATCH 2/3] 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 --- Makefile | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 775b3d5..6fc1836 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,14 @@ +# Copyright © The CDI Authors +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + GO_CMD := go GO_BUILD := $(GO_CMD) build GO_TEST := $(GO_CMD) test -race -v -cover @@ -8,7 +19,8 @@ GO_VET := $(GO_CMD) vet CDI_PKG := $(shell grep ^module go.mod | sed 's/^module *//g') -BINARIES := bin/cdi bin/validate +CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/)))) +BINARIES := $(patsubst %,bin/%,$(CMDS)) ifneq ($(V),1) Q := @ @@ -45,13 +57,37 @@ vet: # build targets # -bin/%: - $(Q)echo "Building $@..."; \ - $(GO_BUILD) -o $@ ./$(subst bin/,cmd/,$@) +$(BINARIES): bin/%: + $(Q)echo "Building $@..." + $(Q)(cd cmd/$(*) && $(GO_BUILD) -o $(abspath $@) .) + +# +# go module tidy and verify targets +# +.PHONY: mod-tidy $(CMD_MOD_TIDY_TARGETS) mod-tidy-root +.PHONY: mod-verify $(CMD_MOD_VERIFY_TARGETS) mod-verify-root + +CMD_MOD_TIDY_TARGETS := mod-tidy-cdi mod-tidy-validate +CMD_MOD_VERIFY_TARGETS := mod-verify-cdi mod-verify-validate + +mod-tidy-root: + $(Q)echo "Running $@..."; \ + $(GO_CMD) mod tidy + +$(CMD_MOD_TIDY_TARGETS): mod-tidy-%: mod-tidy-root + $(Q)echo "Running $@... in $(abspath ./cmd/$(*))"; \ + (cd $(abspath ./cmd/$(*)) && $(GO_CMD) mod tidy) + +mod-verify-root: mod-tidy-root + $(Q)echo "Running $@..."; \ + $(GO_CMD) mod verify -bin/cdi: - $(Q)echo "Building $@..."; \ - cd cmd/cdi; $(GO_BUILD) -o $(abspath $@) . +$(CMD_MOD_VERIFY_TARGETS): mod-verify-%: mod-tidy-% mod-verify-root + $(Q)echo "Running $@... in $(abspath ./cmd/$(*))"; \ + (cd $(abspath ./cmd/$(*)) && pwd && $(GO_CMD) mod verify) + +mod-verify: $(CMD_MOD_VERIFY_TARGETS) +mod-tidy: $(CMD_MOD_TIDY_TARGETS) # # cleanup targets @@ -83,7 +119,13 @@ test-schema: bin/validate # dependencies # -bin/validate: cmd/validate/validate.go $(wildcard schema/*.json) +bin/validate: $(wildcard schema/*.json) $(wildcard cmd/validate/*.go cmd/validate/cmd/*.go) $(shell \ + for dir in \ + $$(cd ./cmd/validate; $(GO_CMD) list -f '{{ join .Deps "\n"}}' ./... | \ + grep $(CDI_PKG)/pkg/ | \ + sed 's:$(CDI_PKG):.:g'); do \ + find $$dir -name \*.go; \ + done | sort | uniq) # quasi-automatic dependency for bin/cdi 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 \ sed 's:$(CDI_PKG):.:g'); do \ find $$dir -name \*.go; \ done | sort | uniq) + From b86c2084c76f4e6354909344d0f6d766850942c4 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 9 Feb 2023 14:04:35 +0100 Subject: [PATCH 3/3] Make cmd/validate a separate module Signed-off-by: Evan Lezar --- cmd/validate/go.mod | 15 +++++++++++++++ cmd/validate/go.sum | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 cmd/validate/go.mod create mode 100644 cmd/validate/go.sum diff --git a/cmd/validate/go.mod b/cmd/validate/go.mod new file mode 100644 index 0000000..fe66b09 --- /dev/null +++ b/cmd/validate/go.mod @@ -0,0 +1,15 @@ +module github.com/container-orchestrated-devices/container-device-interface/cmd/validate + +go 1.19 + +require github.com/container-orchestrated-devices/container-device-interface v0.0.0 + +require ( + github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/xeipuuv/gojsonschema v1.2.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect +) + +replace github.com/container-orchestrated-devices/container-device-interface => ../.. diff --git a/cmd/validate/go.sum b/cmd/validate/go.sum new file mode 100644 index 0000000..f55abdd --- /dev/null +++ b/cmd/validate/go.sum @@ -0,0 +1,28 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= +github.com/opencontainers/runc v1.1.2 h1:2VSZwLx5k/BfsBxMMipG/LYUnmqOD/BPkIVgQUcTlLw= +github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb h1:1xSVPOd7/UA+39/hXEGnBJ13p6JFB0E1EvQFlrRDOXI= +github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626 h1:DmNGcqH3WDbV5k8OJ+esPWbqUOX5rMLR2PMvziDMJi0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= +golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c h1:DHcbWVXeY+0Y8HHKR+rbLwnoh2F4tNCY7rTiHJ30RmA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=