Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 17 | # set default shell |
| 18 | SHELL = bash -e -o pipefail |
| 19 | |
| 20 | # Variables |
| 21 | VERSION ?= $(shell cat ./VERSION) |
| 22 | |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 23 | DOCKER_LABEL_VCS_DIRTY = false |
| 24 | ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 25 | DOCKER_LABEL_VCS_DIRTY = true |
| 26 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 27 | ## Docker related |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 28 | DOCKER_EXTRA_ARGS ?= |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 29 | DOCKER_REGISTRY ?= |
| 30 | DOCKER_REPOSITORY ?= |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 31 | DOCKER_TAG ?= ${VERSION} |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 32 | ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG} |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 33 | |
| 34 | ## Docker labels. Only set ref and commit date if committed |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 35 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 36 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 37 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 38 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 39 | |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 40 | DOCKER_BUILD_ARGS ?= \ |
| 41 | ${DOCKER_EXTRA_ARGS} \ |
| 42 | --build-arg org_label_schema_version="${VERSION}" \ |
| 43 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 44 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 45 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 46 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 47 | --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}" |
| 48 | |
| 49 | DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \ |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 50 | --build-arg LOCAL_PROTOS=${LOCAL_PROTOS} |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 51 | |
David K. Bainbridge | 8eb6cd6 | 2019-08-22 13:17:29 -0700 | [diff] [blame] | 52 | .PHONY: docker-build local-protos local-voltha |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 53 | |
| 54 | # This should to be the first and default target in this Makefile |
| 55 | help: |
| 56 | @echo "Usage: make [<target>]" |
| 57 | @echo "where available targets are:" |
| 58 | @echo |
Zack Williams | 95504be | 2019-09-03 14:17:24 -0700 | [diff] [blame] | 59 | @echo "docker-build : Build openolt adapter docker image" |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 60 | @echo "help : Print this help" |
| 61 | @echo "docker-push : Push the docker images to an external repository" |
| 62 | @echo "lint : Run lint verification, depenancy, gofmt and reference check" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 63 | @echo "sca : Runs various SCA through golangci-lint tool" |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 64 | @echo "test : Run unit tests, if any" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 65 | @echo |
| 66 | |
| 67 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 68 | ## Local Development Helpers |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 69 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 70 | local-protos: |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 71 | ifdef LOCAL_PROTOS |
| 72 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 73 | cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 74 | endif |
| 75 | |
David K. Bainbridge | 8eb6cd6 | 2019-08-22 13:17:29 -0700 | [diff] [blame] | 76 | local-voltha: |
| 77 | ifdef LOCAL_VOLTHA |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 78 | mkdir -p vendor/github.com/opencord/voltha-go/ |
| 79 | cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/ |
| 80 | rm -rf vendor/github.com/opencord/voltha-go/vendor |
| 81 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 82 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 83 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 84 | ## Docker targets |
| 85 | |
Zack Williams | 95504be | 2019-09-03 14:17:24 -0700 | [diff] [blame] | 86 | docker-build: local-protos local-voltha |
David K. Bainbridge | 8eb6cd6 | 2019-08-22 13:17:29 -0700 | [diff] [blame] | 87 | docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME} -f docker/Dockerfile.openolt . |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 88 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 89 | docker-push: |
| 90 | docker push ${ADAPTER_IMAGENAME} |
| 91 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 92 | ## lint and unit tests |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 93 | |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 94 | lint-style: |
| 95 | ifeq (,$(shell which gofmt)) |
| 96 | go get -u github.com/golang/go/src/cmd/gofmt |
| 97 | endif |
| 98 | @echo "Running style check..." |
| 99 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 100 | if [ ! -z "$$gofmt_out" ]; then \ |
| 101 | echo "$$gofmt_out" ;\ |
| 102 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 103 | exit 1 ;\ |
| 104 | fi |
| 105 | @echo "Style check OK" |
| 106 | |
| 107 | lint-sanity: |
| 108 | @echo "Running sanity check..." |
| 109 | @go vet ./... |
| 110 | @echo "Sanity check OK" |
| 111 | |
| 112 | lint-dep: |
| 113 | @echo "Running dependency check..." |
| 114 | @dep check |
| 115 | @echo "Dependency check OK" |
| 116 | |
| 117 | lint: lint-style lint-sanity lint-dep |
| 118 | |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 119 | # Rules to automatically install golangci-lint |
| 120 | GOLANGCI_LINT_TOOL?=$(shell which golangci-lint) |
| 121 | ifeq (,$(GOLANGCI_LINT_TOOL)) |
| 122 | GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint |
| 123 | golangci_lint_tool_install: |
| 124 | # Same version as installed by Jenkins ci-management |
| 125 | # Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint |
| 126 | curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0 |
| 127 | else |
| 128 | golangci_lint_tool_install: |
| 129 | endif |
| 130 | |
| 131 | # Rules to automatically install go-junit-report |
| 132 | GO_JUNIT_REPORT?=$(shell which go-junit-report) |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 133 | ifeq (,$(GO_JUNIT_REPORT)) |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 134 | GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
| 135 | go_junit_install: |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 136 | go get -u github.com/jstemmer/go-junit-report |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 137 | else |
| 138 | go_junit_install: |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 139 | endif |
| 140 | |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 141 | # Rules to automatically install gocover-covertura |
| 142 | GOCOVER_COBERTURA?=$(shell which gocover-cobertura) |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 143 | ifeq (,$(GOCOVER_COBERTURA)) |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 144 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 145 | gocover_cobertura_install: |
| 146 | go get -u github.com/t-yuki/gocover-cobertura |
| 147 | else |
| 148 | gocover_cobertura_install: |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 149 | endif |
| 150 | |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 151 | test: go_junit_install gocover_cobertura_install |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 152 | @mkdir -p ./tests/results |
| 153 | |
| 154 | @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
| 155 | RETURN=$$? ;\ |
| 156 | $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 157 | $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 158 | exit $$RETURN |
| 159 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 160 | GOLANGCI_LINT_TOOL:=$(shell which golangci-lint) |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 161 | sca: golangci_lint_tool_install |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 162 | @mkdir -p ./sca-report |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 163 | GO111MODULE=on golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 164 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 165 | clean: |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 166 | rm -rf sca-report |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 167 | |
| 168 | distclean: clean |
| 169 | rm -rf ${VENVDIR} |
Scott Baker | a4cd50d | 2019-10-15 16:53:38 -0700 | [diff] [blame^] | 170 | rm -rf ./sca_report |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 171 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 172 | # end file |