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