blob: 6cfcc89bb8a5c8e427ce6cf072bb06d17fe9aeab [file] [log] [blame]
Zack Williams86f87202018-10-05 10:36:32 -07001# Copyright 2018-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Zack Williams2abf3932019-08-05 14:07:05 -070015VERSION ?= $(shell cat ./VERSION)
16BBSIM_DEPS = $(wildcard ./*.go)
Zack Williams86f87202018-10-05 10:36:32 -070017
Kailashd88258b2019-07-01 21:27:48 -070018## Docker related
Zack Williams2abf3932019-08-05 14:07:05 -070019DOCKER_REGISTRY ?= ""
20DOCKER_REPOSITORY ?= voltha/
Kailashd88258b2019-07-01 21:27:48 -070021DOCKER_BUILD_ARGS ?=
22DOCKER_TAG ?= ${VERSION}
Zack Williams2abf3932019-08-05 14:07:05 -070023BBSIM_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-bbsim:${DOCKER_TAG}
Kailashd88258b2019-07-01 21:27:48 -070024
25## Docker labels. Only set ref and commit date if committed
26DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
27DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
28DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
29DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
30
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020031GRPC_GW_PATH ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)
Zdravko Bozakov078a2712019-07-19 23:25:15 +020032PROTO_PATH ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos)
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020033
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -040034bbsim: dep bbsimapi
Matteo Scandolof7b260d2019-07-31 13:43:02 -070035 GO111MODULE=on go build -i -v -o $@
Zack Williams86f87202018-10-05 10:36:32 -070036
Matteo Scandolof7b260d2019-07-31 13:43:02 -070037dep:
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020038 GO111MODULE=on go get -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.9.5
Matteo Scandolof7b260d2019-07-31 13:43:02 -070039 GO111MODULE=on go mod download all
Zack Williams86f87202018-10-05 10:36:32 -070040
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020041
42bbsimapi: dep api/bbsim.pb.go api/bbsim.pb.gw.go
43 @echo using ${GRPC_GW_PATH}
44
45api/bbsim.pb.go api/bbsim.pb.gw.go: api/bbsim.proto
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020046 @protoc -I ./api \
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020047 -I${GRPC_GW_PATH}/third_party/googleapis/ \
48 -I${GRPC_GW_PATH}/ \
Zdravko Bozakov078a2712019-07-19 23:25:15 +020049 -I${PROTO_PATH}/protos/ \
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020050 --go_out=plugins=grpc:api/ \
51 --grpc-gateway_out=logtostderr=true,allow_delete_body=true:api/ \
Shad Ansari3f525132019-06-23 06:16:28 +000052 api/bbsim.proto
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020053
54swagger: ## Generate swagger documentation for BBsim API
55 @protoc -I ./api \
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020056 -I${GRPC_GW_PATH}/third_party/googleapis/ \
57 -I${GRPC_GW_PATH}/ \
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020058 --swagger_out=logtostderr=true,allow_delete_body=true:api/swagger/ \
Zdravko Bozakov078a2712019-07-19 23:25:15 +020059 api/bbsim.proto
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020060
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -040061test: dep bbsimapi
Matteo Scandolof7b260d2019-07-31 13:43:02 -070062 GO111MODULE=on go test -v ./...
63 GO111MODULE=on go test -v ./... -cover
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090064
65fmt:
66 go fmt ./...
67
68vet:
69 go vet ./...
70
71lint:
72 gometalinter --vendor --exclude ../../golang.org --skip protos --sort path --sort line ./...
Zack Williams86f87202018-10-05 10:36:32 -070073
74clean:
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020075 @rm -vf bbsim \
Zdravko Bozakovd52eaee2019-09-18 12:24:13 +020076 api/bbsim.pb.go \
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020077 api/bbsim.pb.gw.go \
78 api/swagger/*.json
Zack Williams86f87202018-10-05 10:36:32 -070079
Kailashd88258b2019-07-01 21:27:48 -070080docker-build:
Zack Williams2abf3932019-08-05 14:07:05 -070081 docker build ${DOCKER_BUILD_ARGS} -t ${BBSIM_IMAGENAME} .
Matteo Scandolof7b260d2019-07-31 13:43:02 -070082
83docker-save:
Zack Williams2abf3932019-08-05 14:07:05 -070084 docker save ${BBSIM_IMAGENAME} -o voltha-bbsim_${DOCKER_TAG}.tgz
Kailashd88258b2019-07-01 21:27:48 -070085
86docker-push:
Zack Williams2abf3932019-08-05 14:07:05 -070087 docker push ${BBSIM_IMAGENAME}