Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 1 | # Makefile for cordctl |
| 2 | |
| 3 | # Set bash for fail quickly |
| 4 | SHELL = bash -eu -o pipefail |
| 5 | |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 6 | ifeq ($(GOPATH),) |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 7 | $(error Please set your GOPATH) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 8 | endif |
| 9 | |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 10 | VERSION ?= $(shell cat $(GOPATH)/src/github.com/opencord/cordctl/VERSION) |
Scott Baker | 85e3690 | 2019-07-01 10:36:23 -0700 | [diff] [blame^] | 11 | GOVERSION = $(shell go version 2>&1 | awk '{print $$3;}' ) |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 12 | |
| 13 | GITCOMMIT ?= $(shell git log --pretty=format:"%h" -n 1) |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame] | 14 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 15 | GITDIRTY := false |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame] | 16 | else |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 17 | GITDIRTY := true |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame] | 18 | endif |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 19 | |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 20 | # build target creates binaries for host OS and arch |
| 21 | HOST_OS ?= $(shell uname -s | tr A-Z a-z) |
| 22 | |
| 23 | # uname and golang disagree on name of CPU architecture |
| 24 | ifeq ($(shell uname -m),x86_64) |
| 25 | HOST_ARCH ?= amd64 |
| 26 | else |
| 27 | HOST_ARCH ?= $(shell uname -m) |
| 28 | endif |
| 29 | |
| 30 | BUILDTIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 31 | |
| 32 | LDFLAGS = -ldflags \ |
Matteo Scandolo | 722930f | 2019-05-21 15:55:31 -0700 | [diff] [blame] | 33 | "-X github.com/opencord/cordctl/cli/version.Version=$(VERSION) \ |
| 34 | -X github.com/opencord/cordctl/cli/version.GitCommit=$(GITCOMMIT) \ |
| 35 | -X github.com/opencord/cordctl/cli/version.GitDirty=$(GITDIRTY) \ |
| 36 | -X github.com/opencord/cordctl/cli/version.GoVersion=$(GOVERSION) \ |
| 37 | -X github.com/opencord/cordctl/cli/version.Os=$$GOOS \ |
| 38 | -X github.com/opencord/cordctl/cli/version.Arch=$$GOARCH \ |
| 39 | -X github.com/opencord/cordctl/cli/version.BuildTime=$(BUILDTIME)" |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 40 | |
Scott Baker | 14c8f18 | 2019-05-22 18:05:29 -0700 | [diff] [blame] | 41 | # Settings for running with mock server |
| 42 | TEST_PROTOSET = $(shell pwd)/mock/xos-core.protoset |
| 43 | TEST_MOCK_DIR = $(shell pwd)/mock |
| 44 | TEST_SERVER = localhost:50051 |
| 45 | TEST_USERNAME = admin@opencord.org |
| 46 | TEST_PASSWORD = letmein |
| 47 | |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 48 | help: |
| 49 | |
| 50 | build: dependencies |
Matteo Scandolo | 722930f | 2019-05-21 15:55:31 -0700 | [diff] [blame] | 51 | export GOOS=$(HOST_OS) ;\ |
| 52 | export GOARCH=$(HOST_ARCH) ;\ |
| 53 | go build $(LDFLAGS) cmd/cordctl.go |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 54 | |
| 55 | dependencies: |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 56 | [ -d "vendor" ] || dep ensure |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 57 | |
| 58 | lint: dependencies |
| 59 | find $(GOPATH)/src/github.com/opencord/cordctl -name "*.go" -not -path '$(GOPATH)/src/github.com/opencord/cordctl/vendor/*' | xargs gofmt -l |
| 60 | go vet ./... |
| 61 | dep check |
| 62 | |
| 63 | test: dependencies |
| 64 | @mkdir -p ./tests/results |
Scott Baker | 14c8f18 | 2019-05-22 18:05:29 -0700 | [diff] [blame] | 65 | @set +e; \ |
| 66 | CORDCTL_PROTOSET=$(TEST_PROTOSET)\ |
| 67 | CORDCTL_SERVER=$(TEST_SERVER) \ |
| 68 | CORDCTL_MOCK_DIR=$(TEST_MOCK_DIR) \ |
| 69 | CORDCTL_USERNAME=$(TEST_USERNAME) \ |
| 70 | CORDCTL_PASSWORD=$(TEST_PASSWORD) \ |
| 71 | go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 72 | RETURN=$$? ;\ |
| 73 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 74 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
Scott Baker | 14c8f18 | 2019-05-22 18:05:29 -0700 | [diff] [blame] | 75 | cd mock; \ |
| 76 | docker-compose down; \ |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 77 | exit $$RETURN |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 78 | |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 79 | # Release related items |
| 80 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 81 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 82 | RELEASE_DIR ?= release |
| 83 | RELEASE_NAME ?= cordctl |
| 84 | RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64 |
| 85 | RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(rel)) |
| 86 | |
| 87 | # Functions to extract the OS/ARCH |
| 88 | rel_os = $(word 2, $(subst -, ,$(notdir $@))) |
| 89 | rel_arch = $(word 3, $(subst -, ,$(notdir $@))) |
| 90 | |
| 91 | $(RELEASE_BINS): dependencies |
Matteo Scandolo | 722930f | 2019-05-21 15:55:31 -0700 | [diff] [blame] | 92 | export GOOS=$(rel_os) ;\ |
| 93 | export GOARCH=$(rel_arch) ;\ |
| 94 | go build -v $(LDFLAGS) -o "$@" cmd/cordctl.go |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 95 | |
| 96 | release: $(RELEASE_BINS) |
| 97 | |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 98 | clean: |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 99 | rm -f cordctl $(RELEASE_BINS) |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 100 | rm -rf vendor |
| 101 | rm -f Gopkg.lock |
Zack Williams | f354d5c | 2019-05-20 16:56:45 -0700 | [diff] [blame] | 102 | |