blob: 62332d70613791892f3089a83ab9d5ea606bb058 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001help:
David Bainbridgec4029aa2019-09-26 18:56:39 +00002 @echo "release - build binaries using cross compliing for the support architectures"
3 @echo "build - build the binary as a local executable"
4 @echo "install - build and install the binary into \$$GOPATH/bin"
5 @echo "run - runs voltctl using the command specified as \$$CMD"
David Bainbridge12f036f2019-10-15 22:09:04 +00006 @echo "lint-style - Verify code is properly gofmt-ed"
7 @echo "lint-sanity - Verify that 'go vet' doesn't report any issues"
8 @echo "lint-mod - Verify the integrity of the 'mod' files"
David Bainbridge86971522019-09-26 22:09:39 +00009 @echo "lint - run static code analysis"
David Bainbridge12f036f2019-10-15 22:09:04 +000010 @echo "sca - Runs various SCA through golangci-lint tool"
David Bainbridge86971522019-09-26 22:09:39 +000011 @echo "test - run unity tests"
David Bainbridge12f036f2019-10-15 22:09:04 +000012 @echo "check - runs targets that should be run before a commit"
David Bainbridgec4029aa2019-09-26 18:56:39 +000013 @echo "clean - remove temporary and generated files"
Zack Williamse940c7a2019-08-21 14:25:39 -070014
15internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070016 @echo "/*" > $@
17 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
18 @echo " *" >> $@
19 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
20 @echo " * you may not use this file except in compliance with the License." >> $@
21 @echo " * You may obtain a copy of the License at" >> $@
22 @echo " *" >> $@
23 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
24 @echo " *" >> $@
25 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
26 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
27 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
28 @echo " * See the License for the specific language governing permissions and" >> $@
29 @echo " * limitations under the License." >> $@
30 @echo " */" >> $@
31 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070032 @echo "" >> $@
33 @echo "var V1Descriptor = []byte{" >> $@
34 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v1.pb | fold -w 60 -s >> $@
35 @echo "}" >> $@
36 @go fmt $@
37
38internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070039 @echo "/*" > $@
40 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
41 @echo " *" >> $@
42 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
43 @echo " * you may not use this file except in compliance with the License." >> $@
44 @echo " * You may obtain a copy of the License at" >> $@
45 @echo " *" >> $@
46 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
47 @echo " *" >> $@
48 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
49 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
50 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
51 @echo " * See the License for the specific language governing permissions and" >> $@
52 @echo " * limitations under the License." >> $@
53 @echo " */" >> $@
54 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070055 @echo "" >> $@
56 @echo "var V2Descriptor = []byte{" >> $@
57 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v2.pb | fold -w 60 -s >> $@
58 @echo "}" >> $@
59 @go fmt $@
60
61encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go
62
David Bainbridge12f036f2019-10-15 22:09:04 +000063SHELL=bash -e -o pipefail
64
David Bainbridge86971522019-09-26 22:09:39 +000065VERSION=$(shell cat ./VERSION)
Zack Williamse940c7a2019-08-21 14:25:39 -070066GITCOMMIT=$(shell git rev-parse HEAD)
67ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
68GITDIRTY=false
69else
70GITDIRTY=true
71endif
72GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
73HOST_OS=$(shell uname -s | tr A-Z a-z)
74ifeq ($(shell uname -m),x86_64)
75 HOST_ARCH ?= amd64
76else
77 HOST_ARCH ?= $(shell uname -m)
78endif
79BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
80
81LDFLAGS=-ldflags \
Scott Baker2b0ad652019-08-21 14:57:07 -070082 '-X "github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \
83 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \
84 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \
85 -X "github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \
86 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \
87 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \
88 -X "github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"'
Zack Williamse940c7a2019-08-21 14:25:39 -070089
90# Release related items
91# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
92# Inspired by: https://github.com/kubernetes/minikube/releases
93RELEASE_DIR ?= release
94RELEASE_NAME ?= voltctl
95RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64
96RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel))
97
98# Functions to extract the OS/ARCH
99rel_ver = $(word 2, $(subst -, ,$(notdir $@)))
100rel_os = $(word 3, $(subst -, ,$(notdir $@)))
101rel_arch = $(word 4, $(subst -, ,$(notdir $@)))
102
David Bainbridge86971522019-09-26 22:09:39 +0000103# Default is GO111MODULE=auto, which will refuse to use go mod if running
104# go less than 1.13.0 and repo is checked out in gopath. For now, force
105# module usage.
106export GO111MODULE=on
Zack Williamse940c7a2019-08-21 14:25:39 -0700107
David Bainbridge86971522019-09-26 22:09:39 +0000108$(RELEASE_BINS):
Zack Williamse940c7a2019-08-21 14:25:39 -0700109 mkdir -p $(RELEASE_DIR)
David Bainbridge86971522019-09-26 22:09:39 +0000110 GOOS=$(rel_os) GOARCH=$(rel_arch) \
111 go build -mod=vendor -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go
Zack Williamse940c7a2019-08-21 14:25:39 -0700112
113release: $(RELEASE_BINS)
114
David Bainbridge86971522019-09-26 22:09:39 +0000115build:
116 go build -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go
Zack Williamse940c7a2019-08-21 14:25:39 -0700117
David Bainbridge86971522019-09-26 22:09:39 +0000118install:
119 go install -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go
Zack Williamse940c7a2019-08-21 14:25:39 -0700120
David Bainbridge86971522019-09-26 22:09:39 +0000121run:
122 go run -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go $(CMD)
Zack Williamse940c7a2019-08-21 14:25:39 -0700123
David Bainbridge86971522019-09-26 22:09:39 +0000124lint-style:
125ifeq (,$(shell which gofmt))
126 go get -u github.com/golang/go/src/cmd/gofmt
127endif
128 @echo -n "Running style check ... "
129 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
130 if [ ! -z "$$gofmt_out" ]; then \
131 echo "$$gofmt_out" ;\
132 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
133 exit 1 ;\
134 fi
135 @echo "OK"
Zack Williamse940c7a2019-08-21 14:25:39 -0700136
David Bainbridge86971522019-09-26 22:09:39 +0000137lint-sanity:
138 @echo -n "Running sanity check ... "
139 @go vet -mod=vendor ./...
140 @echo "OK"
141
David Bainbridge12f036f2019-10-15 22:09:04 +0000142lint-mod:
143 @echo -n "Running dependency check ... "
144 @echo -n $(shell go mod verify)
145 @echo " ... OK"
146
147lint: lint-style lint-sanity lint-mod
148
149GOLANGCI_LINT_OUT_FORMAT ?= junit-xml
150GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
151sca:
152ifeq (,$(GOLANGCI_LINT_TOOL))
153 @echo "Please install golangci-lint tool to run sca"
154 exit 1
155endif
156 @rm -rf ./sca-report
157 @mkdir -p ./sca-report
158 $(GOLANGCI_LINT_TOOL) run --out-format $(GOLANGCI_LINT_OUT_FORMAT) ./... 2>&1 | tee ./sca-report/sca-report.xml
David Bainbridge86971522019-09-26 22:09:39 +0000159
160test:
Scott Baker2b0ad652019-08-21 14:57:07 -0700161 @mkdir -p ./tests/results
162 @set +e; \
David Bainbridge86971522019-09-26 22:09:39 +0000163 go test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
Scott Baker2b0ad652019-08-21 14:57:07 -0700164 RETURN=$$? ;\
165 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
166 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
167 exit $$RETURN
Zack Williamse940c7a2019-08-21 14:25:39 -0700168
169view-coverage:
David Bainbridge86971522019-09-26 22:09:39 +0000170 go tool cover -html ./tests/results/go-test-coverage.out
Zack Williamse940c7a2019-08-21 14:25:39 -0700171
David Bainbridge12f036f2019-10-15 22:09:04 +0000172check: lint sca test
173
Zack Williamse940c7a2019-08-21 14:25:39 -0700174clean:
David Bainbridge12f036f2019-10-15 22:09:04 +0000175 rm -rf voltctl voltctl.cp release sca-report