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 | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 6 | @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 Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 9 | @echo "lint - run static code analysis" |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 10 | @echo "sca - Runs various SCA through golangci-lint tool" |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 11 | @echo "test - run unity tests" |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 12 | @echo "check - runs targets that should be run before a commit" |
David Bainbridge | c4029aa | 2019-09-26 18:56:39 +0000 | [diff] [blame] | 13 | @echo "clean - remove temporary and generated files" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 14 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 15 | internal/pkg/commands/%_pb.go: assets/protosets/%.pb |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 16 | @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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 32 | @echo "" >> $@ |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 33 | @echo "var $(shell echo $(subst .pb,,$(subst assets/protosets/voltha_,,$<)) |tr '[:lower:]' '[:upper:]')Descriptor = []byte{" >> $@ |
| 34 | hexdump -ve '1/1 "0x%02x,"' $< | fold -w 60 -s >> $@ |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 35 | @echo "}" >> $@ |
| 36 | @go fmt $@ |
| 37 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 38 | encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go internal/pkg/commands/voltha_v3_pb.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 39 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 40 | SHELL=bash -e -o pipefail |
| 41 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 42 | VERSION=$(shell cat ./VERSION) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 43 | GITCOMMIT=$(shell git rev-parse HEAD) |
| 44 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 45 | GITDIRTY=false |
| 46 | else |
| 47 | GITDIRTY=true |
| 48 | endif |
| 49 | GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g') |
| 50 | HOST_OS=$(shell uname -s | tr A-Z a-z) |
| 51 | ifeq ($(shell uname -m),x86_64) |
| 52 | HOST_ARCH ?= amd64 |
| 53 | else |
| 54 | HOST_ARCH ?= $(shell uname -m) |
| 55 | endif |
| 56 | BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 57 | |
| 58 | LDFLAGS=-ldflags \ |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 59 | '-X "github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \ |
| 60 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \ |
| 61 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \ |
| 62 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \ |
| 63 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \ |
| 64 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \ |
| 65 | -X "github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"' |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 66 | |
| 67 | # Release related items |
| 68 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 69 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 70 | RELEASE_DIR ?= release |
| 71 | RELEASE_NAME ?= voltctl |
Ciprian Barbu | 72bdf89 | 2020-01-29 13:42:48 +0200 | [diff] [blame] | 72 | RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64 |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 73 | RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel)) |
| 74 | |
| 75 | # Functions to extract the OS/ARCH |
| 76 | rel_ver = $(word 2, $(subst -, ,$(notdir $@))) |
| 77 | rel_os = $(word 3, $(subst -, ,$(notdir $@))) |
| 78 | rel_arch = $(word 4, $(subst -, ,$(notdir $@))) |
| 79 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 80 | # Default is GO111MODULE=auto, which will refuse to use go mod if running |
| 81 | # go less than 1.13.0 and repo is checked out in gopath. For now, force |
| 82 | # module usage. |
| 83 | export GO111MODULE=on |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 84 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 85 | $(RELEASE_BINS): |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 86 | mkdir -p $(RELEASE_DIR) |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 87 | GOOS=$(rel_os) GOARCH=$(rel_arch) \ |
| 88 | go build -mod=vendor -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 89 | |
| 90 | release: $(RELEASE_BINS) |
| 91 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 92 | build: |
| 93 | go build -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 94 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 95 | install: |
| 96 | go install -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 97 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 98 | run: |
| 99 | go run -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go $(CMD) |
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 | lint-style: |
| 102 | ifeq (,$(shell which gofmt)) |
| 103 | go get -u github.com/golang/go/src/cmd/gofmt |
| 104 | endif |
| 105 | @echo -n "Running style check ... " |
| 106 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 107 | if [ ! -z "$$gofmt_out" ]; then \ |
| 108 | echo "$$gofmt_out" ;\ |
| 109 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 110 | exit 1 ;\ |
| 111 | fi |
| 112 | @echo "OK" |
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 | lint-sanity: |
| 115 | @echo -n "Running sanity check ... " |
| 116 | @go vet -mod=vendor ./... |
| 117 | @echo "OK" |
| 118 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 119 | lint-mod: |
Scott Baker | 4a35a70 | 2019-11-26 08:17:33 -0800 | [diff] [blame] | 120 | go version |
| 121 | @echo "Running dependency check..." |
| 122 | @go mod verify |
| 123 | @echo "Dependency check OK. Running vendor check..." |
| 124 | @git status > /dev/null |
| 125 | @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Staged or modified files must be committed before running this test" && echo "`git status`" && exit 1) |
| 126 | @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files must be cleaned up before running this test" && echo "`git status`" && exit 1) |
| 127 | go mod tidy |
| 128 | go mod vendor |
| 129 | @git status > /dev/null |
| 130 | @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Modified files detected after running go mod tidy / go mod vendor" && echo "`git status`" && exit 1) |
| 131 | @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && echo "`git status`" && exit 1) |
| 132 | @echo "Vendor check OK." |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 133 | |
| 134 | lint: lint-style lint-sanity lint-mod |
| 135 | |
| 136 | GOLANGCI_LINT_OUT_FORMAT ?= junit-xml |
| 137 | GOLANGCI_LINT_TOOL:=$(shell which golangci-lint) |
| 138 | sca: |
| 139 | ifeq (,$(GOLANGCI_LINT_TOOL)) |
| 140 | @echo "Please install golangci-lint tool to run sca" |
| 141 | exit 1 |
| 142 | endif |
| 143 | @rm -rf ./sca-report |
| 144 | @mkdir -p ./sca-report |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 145 | $(GOLANGCI_LINT_TOOL) run --deadline 20m --out-format $(GOLANGCI_LINT_OUT_FORMAT) ./... 2>&1 | tee ./sca-report/sca-report.xml |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 146 | |
| 147 | test: |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 148 | @mkdir -p ./tests/results |
| 149 | @set +e; \ |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 150 | 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] | 151 | RETURN=$$? ;\ |
| 152 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 153 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 154 | exit $$RETURN |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 155 | |
| 156 | view-coverage: |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 157 | go tool cover -html ./tests/results/go-test-coverage.out |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 158 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 159 | check: lint sca test |
| 160 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 161 | clean: |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 162 | rm -rf voltctl voltctl.cp release sca-report |