|
| 1 | +GO_CMD := go |
| 2 | +GO_BUILD := $(GO_CMD) build |
| 3 | +GO_TEST := $(GO_CMD) test -v -cover |
| 4 | + |
| 5 | +GO_LINT := golint -set_exit_status |
| 6 | +GO_FMT := gofmt |
| 7 | +GO_VET := $(GO_CMD) vet |
| 8 | + |
| 9 | +CDI_PKG := $(shell grep ^module go.mod | sed 's/^module *//g') |
| 10 | +GO_MODS := $(shell $(GO_CMD) list ./...) |
| 11 | +GO_PKGS := $(shell $(GO_CMD) list ./... | grep -v cmd/ | sed 's:$(CDI_PKG):.:g') |
| 12 | + |
| 13 | +BINARIES := bin/cdi |
| 14 | + |
| 15 | +ifneq ($(V),1) |
| 16 | + Q := @ |
| 17 | +endif |
| 18 | + |
| 19 | + |
| 20 | +# |
| 21 | +# top-level targets |
| 22 | +# |
| 23 | + |
| 24 | +all: build |
| 25 | + |
| 26 | +build: $(BINARIES) |
| 27 | + |
| 28 | +clean: clean-binaries clean-schema |
| 29 | + |
| 30 | +test: test-gopkgs test-schema |
| 31 | + |
| 32 | +# |
| 33 | +# targets for running test prior to filing a PR |
| 34 | +# |
| 35 | + |
| 36 | +pre-pr-checks pr-checks: test fmt lint vet |
| 37 | + |
| 38 | + |
| 39 | +fmt format: |
| 40 | + $(Q)report=$$($(GO_FMT) -s -d -w $$(find . -name *.go)); \ |
| 41 | + if [ -n "$$report" ]; then \ |
| 42 | + echo "$$report"; \ |
| 43 | + exit 1; \ |
| 44 | + fi |
| 45 | + |
| 46 | +lint: |
| 47 | + $(Q)status=0; for f in $$(find . -name \*.go); do \ |
| 48 | + $(GO_LINT) $$f || status=1; \ |
| 49 | + done; \ |
| 50 | + exit $$status |
| 51 | + |
| 52 | +vet: |
| 53 | + $(Q)$(GO_VET) $(GO_MODS) |
| 54 | + |
| 55 | +# |
| 56 | +# build targets |
| 57 | +# |
| 58 | + |
| 59 | +bin/%: |
| 60 | + $(Q)echo "Building $@..."; \ |
| 61 | + $(GO_BUILD) -o $@ ./$(subst bin/,cmd/,$@) |
| 62 | + |
| 63 | +# |
| 64 | +# cleanup targets |
| 65 | +# |
| 66 | + |
| 67 | +# clean up binaries |
| 68 | +clean-binaries: |
| 69 | + $(Q) rm -f $(BINARIES) |
| 70 | + |
| 71 | +# clean up schema validator |
| 72 | +clean-schema: |
| 73 | + $(Q)rm -f schema/validate |
| 74 | + |
| 75 | +# |
| 76 | +# test targets |
| 77 | +# |
| 78 | + |
| 79 | +# tests for go packages |
| 80 | +test-gopkgs: |
| 81 | + $(Q)status=0; for pkg in $(GO_PKGS); do \ |
| 82 | + $(GO_TEST) $$pkg; \ |
| 83 | + if [ $$? != 0 ]; then \ |
| 84 | + echo "*** Test FAILED for package $$pkg."; \ |
| 85 | + status=1; \ |
| 86 | + fi; \ |
| 87 | + done; \ |
| 88 | + exit $$status |
| 89 | + |
| 90 | +# tests for CDI Spec JSON schema |
| 91 | +test-schema: |
| 92 | + $(Q)echo "Building in schema..."; \ |
| 93 | + $(MAKE) -C schema test |
| 94 | + |
| 95 | + |
| 96 | +# |
| 97 | +# dependencies |
| 98 | +# |
| 99 | + |
| 100 | +# quasi-automatic dependency for bin/cdi |
| 101 | +bin/cdi: $(wildcard cmd/cdi/*.go cmd/cdi/cmd/*.go) $(shell \ |
| 102 | + for dir in \ |
| 103 | + $$($(GO_CMD) list -f '{{ join .Deps "\n"}}' ./cmd/cdi/... | \ |
| 104 | + grep $(CDI_PKG)/pkg/ | \ |
| 105 | + sed 's:$(CDI_PKG):.:g'); do \ |
| 106 | + find $$dir -name \*.go; \ |
| 107 | + done | sort | uniq) |
0 commit comments