blob: e4b0e10a9a46f39965e9b26fcfbe73869ae23a86 [file] [log] [blame]
Phaneendra Manda4c62c802019-03-06 21:37:49 +05301#
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 Jeanneret8b823f62019-05-11 11:01:28 -040017# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ./VERSION)
22
Matt Jeanneretf880eb62019-07-16 20:08:03 -040023DOCKER_LABEL_VCS_DIRTY = false
24ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
25 DOCKER_LABEL_VCS_DIRTY = true
26endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040027## Docker related
Matt Jeanneretf880eb62019-07-16 20:08:03 -040028DOCKER_EXTRA_ARGS ?=
Matt Jeanneret8b823f62019-05-11 11:01:28 -040029DOCKER_REGISTRY ?=
30DOCKER_REPOSITORY ?=
Matt Jeanneret8b823f62019-05-11 11:01:28 -040031DOCKER_TAG ?= ${VERSION}
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040032ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}
Matt Jeanneret8b823f62019-05-11 11:01:28 -040033
34## Docker labels. Only set ref and commit date if committed
Matt Jeanneretf880eb62019-07-16 20:08:03 -040035DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
36DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
37DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
38DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
Matt Jeanneret8b823f62019-05-11 11:01:28 -040039
Matt Jeanneretf880eb62019-07-16 20:08:03 -040040DOCKER_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
49DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
Matt Jeanneretf880eb62019-07-16 20:08:03 -040050 --build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
Phaneendra Manda4c62c802019-03-06 21:37:49 +053051
David K. Bainbridge8eb6cd62019-08-22 13:17:29 -070052.PHONY: docker-build local-protos local-voltha
Phaneendra Manda4c62c802019-03-06 21:37:49 +053053
54# This should to be the first and default target in this Makefile
55help:
56 @echo "Usage: make [<target>]"
57 @echo "where available targets are:"
58 @echo
David K. Bainbridge8eb6cd62019-08-22 13:17:29 -070059 @echo "build : Build openolt adapter docker image"
Matt Jeanneret8b823f62019-05-11 11:01:28 -040060 @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 Gowdru6a80bbd2019-07-02 07:36:09 -070063 @echo "sca : Runs various SCA through golangci-lint tool"
Matt Jeanneret8b823f62019-05-11 11:01:28 -040064 @echo "test : Run unit tests, if any"
Phaneendra Manda4c62c802019-03-06 21:37:49 +053065 @echo
66
67
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040068## Local Development Helpers
Phaneendra Manda4c62c802019-03-06 21:37:49 +053069
Matt Jeanneret8b823f62019-05-11 11:01:28 -040070local-protos:
William Kurkianea869482019-04-09 15:16:11 -040071ifdef LOCAL_PROTOS
72 mkdir -p vendor/github.com/opencord/voltha-protos/go
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040073 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040074endif
75
David K. Bainbridge8eb6cd62019-08-22 13:17:29 -070076local-voltha:
77ifdef LOCAL_VOLTHA
William Kurkianea869482019-04-09 15:16:11 -040078 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
81endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040082
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040083
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040084## Docker targets
85
David K. Bainbridge8eb6cd62019-08-22 13:17:29 -070086build: local-protos local-voltha
87 docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME} -f docker/Dockerfile.openolt .
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040088
Matt Jeanneret8b823f62019-05-11 11:01:28 -040089docker-push:
90 docker push ${ADAPTER_IMAGENAME}
91
Matt Jeanneret8b823f62019-05-11 11:01:28 -040092## lint and unit tests
Phaneendra Manda4c62c802019-03-06 21:37:49 +053093
Matt Jeanneret384d8c92019-05-06 14:27:31 -040094lint-style:
95ifeq (,$(shell which gofmt))
96 go get -u github.com/golang/go/src/cmd/gofmt
97endif
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
107lint-sanity:
108 @echo "Running sanity check..."
109 @go vet ./...
110 @echo "Sanity check OK"
111
112lint-dep:
113 @echo "Running dependency check..."
114 @dep check
115 @echo "Dependency check OK"
116
117lint: lint-style lint-sanity lint-dep
118
119GO_JUNIT_REPORT:=$(shell which go-junit-report)
120GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
121test:
122ifeq (,$(GO_JUNIT_REPORT))
123 go get -u github.com/jstemmer/go-junit-report
124 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
125endif
126
127ifeq (,$(GOCOVER_COBERTURA))
128 go get -u github.com/t-yuki/gocover-cobertura
129 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
130endif
131
132 @mkdir -p ./tests/results
133
134 @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
135 RETURN=$$? ;\
136 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
137 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
138 exit $$RETURN
139
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700140GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
141sca:
142ifeq (,$(GOLANGCI_LINT_TOOL))
143 @echo "Please install golangci-lint tool to run sca"
144 exit 1
145endif
146 @mkdir -p ./sca-report
147 GO111MODULE=on golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml ;\
148 RETURN=$$? ;\
149 exit $$RETURN
150
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400151clean:
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700152 rm -rf sca-report
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400153
154distclean: clean
155 rm -rf ${VENVDIR}
156
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530157# end file