Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | help: |
David Bainbridge | c4029aa | 2019-09-26 18:56:39 +0000 | [diff] [blame] | 2 | @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 Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 6 | @echo "lint - run static code analysis" |
| 7 | @echo "test - run unity tests" |
David Bainbridge | c4029aa | 2019-09-26 18:56:39 +0000 | [diff] [blame] | 8 | @echo "clean - remove temporary and generated files" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 9 | |
| 10 | internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 11 | @echo "/*" > $@ |
| 12 | @echo " * Copyright 2019-present Open Networking Foundation" >> $@ |
| 13 | @echo " *" >> $@ |
| 14 | @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@ |
| 15 | @echo " * you may not use this file except in compliance with the License." >> $@ |
| 16 | @echo " * You may obtain a copy of the License at" >> $@ |
| 17 | @echo " *" >> $@ |
| 18 | @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@ |
| 19 | @echo " *" >> $@ |
| 20 | @echo " * Unless required by applicable law or agreed to in writing, software" >> $@ |
| 21 | @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@ |
| 22 | @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@ |
| 23 | @echo " * See the License for the specific language governing permissions and" >> $@ |
| 24 | @echo " * limitations under the License." >> $@ |
| 25 | @echo " */" >> $@ |
| 26 | @echo "package commands" >> $@ |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 27 | @echo "" >> $@ |
| 28 | @echo "var V1Descriptor = []byte{" >> $@ |
| 29 | hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v1.pb | fold -w 60 -s >> $@ |
| 30 | @echo "}" >> $@ |
| 31 | @go fmt $@ |
| 32 | |
| 33 | internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 34 | @echo "/*" > $@ |
| 35 | @echo " * Copyright 2019-present Open Networking Foundation" >> $@ |
| 36 | @echo " *" >> $@ |
| 37 | @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@ |
| 38 | @echo " * you may not use this file except in compliance with the License." >> $@ |
| 39 | @echo " * You may obtain a copy of the License at" >> $@ |
| 40 | @echo " *" >> $@ |
| 41 | @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@ |
| 42 | @echo " *" >> $@ |
| 43 | @echo " * Unless required by applicable law or agreed to in writing, software" >> $@ |
| 44 | @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@ |
| 45 | @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@ |
| 46 | @echo " * See the License for the specific language governing permissions and" >> $@ |
| 47 | @echo " * limitations under the License." >> $@ |
| 48 | @echo " */" >> $@ |
| 49 | @echo "package commands" >> $@ |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 50 | @echo "" >> $@ |
| 51 | @echo "var V2Descriptor = []byte{" >> $@ |
| 52 | hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v2.pb | fold -w 60 -s >> $@ |
| 53 | @echo "}" >> $@ |
| 54 | @go fmt $@ |
| 55 | |
| 56 | encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go |
| 57 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 58 | VERSION=$(shell cat ./VERSION) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 59 | GITCOMMIT=$(shell git rev-parse HEAD) |
| 60 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 61 | GITDIRTY=false |
| 62 | else |
| 63 | GITDIRTY=true |
| 64 | endif |
| 65 | GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g') |
| 66 | HOST_OS=$(shell uname -s | tr A-Z a-z) |
| 67 | ifeq ($(shell uname -m),x86_64) |
| 68 | HOST_ARCH ?= amd64 |
| 69 | else |
| 70 | HOST_ARCH ?= $(shell uname -m) |
| 71 | endif |
| 72 | BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 73 | |
| 74 | LDFLAGS=-ldflags \ |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 75 | '-X "github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \ |
| 76 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \ |
| 77 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \ |
| 78 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \ |
| 79 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \ |
| 80 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \ |
| 81 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"' |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 82 | |
| 83 | # Release related items |
| 84 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 85 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 86 | RELEASE_DIR ?= release |
| 87 | RELEASE_NAME ?= voltctl |
| 88 | RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64 |
| 89 | RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel)) |
| 90 | |
| 91 | # Functions to extract the OS/ARCH |
| 92 | rel_ver = $(word 2, $(subst -, ,$(notdir $@))) |
| 93 | rel_os = $(word 3, $(subst -, ,$(notdir $@))) |
| 94 | rel_arch = $(word 4, $(subst -, ,$(notdir $@))) |
| 95 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 96 | # Default is GO111MODULE=auto, which will refuse to use go mod if running |
| 97 | # go less than 1.13.0 and repo is checked out in gopath. For now, force |
| 98 | # module usage. |
| 99 | export GO111MODULE=on |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 100 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 101 | $(RELEASE_BINS): |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 102 | mkdir -p $(RELEASE_DIR) |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 103 | GOOS=$(rel_os) GOARCH=$(rel_arch) \ |
| 104 | go build -mod=vendor -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 105 | |
| 106 | release: $(RELEASE_BINS) |
| 107 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 108 | build: |
| 109 | go build -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 110 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 111 | install: |
| 112 | go install -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 113 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 114 | run: |
| 115 | go run -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go $(CMD) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 116 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 117 | lint-style: |
| 118 | ifeq (,$(shell which gofmt)) |
| 119 | go get -u github.com/golang/go/src/cmd/gofmt |
| 120 | endif |
| 121 | @echo -n "Running style check ... " |
| 122 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 123 | if [ ! -z "$$gofmt_out" ]; then \ |
| 124 | echo "$$gofmt_out" ;\ |
| 125 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 126 | exit 1 ;\ |
| 127 | fi |
| 128 | @echo "OK" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 129 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 130 | lint-sanity: |
| 131 | @echo -n "Running sanity check ... " |
| 132 | @go vet -mod=vendor ./... |
| 133 | @echo "OK" |
| 134 | |
| 135 | lint: lint-style lint-sanity |
| 136 | |
| 137 | test: |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 138 | @mkdir -p ./tests/results |
| 139 | @set +e; \ |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 140 | go test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 141 | RETURN=$$? ;\ |
| 142 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 143 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 144 | exit $$RETURN |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 145 | |
| 146 | view-coverage: |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame^] | 147 | go tool cover -html ./tests/results/go-test-coverage.out |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 148 | |
| 149 | clean: |
| 150 | rm -rf voltctl voltctl.cp release |