blob: ee27e10e1d7bb129d35f4c2df578729f10ac6b7a [file] [log] [blame]
Joey Armstrongdd334492023-07-09 17:59:02 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong6a9013e2024-02-01 17:56:57 -05003# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrongdd334492023-07-09 17:59:02 -04004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.d
16# -----------------------------------------------------------------------
17
18$(if $(DEBUG),$(warning ENTER))
19
20# Per-repository
21include $(ONF_MAKEDIR)/docker/config/$(--repo-name--).mk
22
23# ------------------- ##
24# ---] GLOBALS [--- ##
25# ------------------- ##
26VOLTHA_TOOLS_VERSION ?= 2.4.0
27
28# ---------------------------------
29# Induce error for misconfiguration
30# ---------------------------------
31go-cobertura-docker-mount ?= $(error go-cobertura-docker-mount= is required)
32protoc-sh-docker-mount ?= $(error protoc-sh-docker-mount= is required)
33
34# ---------------------------
35# Macros: command refactoring
36# ---------------------------
37docker-iam ?= --user $$(id -u):$$(id -g)# # override for local use
38docker-run = docker run --rm $(docker-iam)# # Docker command stem
39docker-run-is = $(docker-run) $(is-stdin)# # Attach streams when interactive
40docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount
41
42# -----------------------------------------------------------------------
43# --interactive: Attach streams when stdout (fh==0) defined
44# --tty : Always create a pseudo-tty else jenkins:docker is silent
45# -----------------------------------------------------------------------
46is-stdin = $(shell test -t 0 && { echo '--interactive'; })
47is-stdin += --tty
48
49# Docker volume mounts: container:/app/release <=> localhost:{pwd}/release
50vee-golang = -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg
51vee-citools = voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}
52
53# ---------------
54# Tool Containers
55# ---------------
56docker-go-stem = $(docker-run-app) -v gocache:/.cache $(vee-golang) $(vee-citools)-golang
57
58# -----------------------------------------------------------------------
59# Usage: GO := $(call get-cmd-docker-go)
60# -----------------------------------------------------------------------
61get-cmd-docker-go = $(docker-go-stem) go
62GO ?= $(call get-cmd-docker-go)
63
64# -----------------------------------------------------------------------
65# Usage: GO_SH := $(call get-docker-go-sh,./my.env.temp)
66# - populate my.env.temp with shell content to pass in
67# -----------------------------------------------------------------------
68get-cmd-docker-go-sh = $(docker-go-stem) $(if $(1),--env-file $(1)) sh -c
69GO_SH ?= $(call get-cmd-docker-go-sh,./my.env.temp)
70
71# -----------------------------------------------------------------------
72# Usage: PROTOC := $(call get-cmd-docker-protoc)
73# -----------------------------------------------------------------------
74get-cmd-docker-protoc = $(docker-run-app) $(vee-citools)-protoc protoc
75PROTOC ?= $(call get-cmd-docker-protoc)
76
77# -----------------------------------------------------------------------
78# Usage: PROTOC_SH := $(call get-cmd-docker-protoc-sh)
79# -----------------------------------------------------------------------
80get-cmd-docker-protoc-sh =\
81 $(strip \
82 $(docker-run-is) \
83 $(if $(protc-sh-docker-mount), \
84 -v ${CURDIR}:$(protoc-sh-docker-mount) \
85 --workdir=$(protoc-sh-docker-mount) \
86 ) \
87 $(vee-citools)-protoc \
88 sh -c \
89 )
90PROTOC_SH ?= $(call get-cmd-docker-protoc-sh)
91
92# get-docker-protoc-sh = $(strip )
93#PROTOC_SH = $(docker-run-is)
94#ifdef protc-sh-docker-mount
95# PROTOC_SH += -v ${CURDIR}:$(protoc-sh-docker-mount)
96# PROTOC_SH += --workdir=$(protoc-sh-docker-mount)
97#endif # protoc-sh-docker-mount
98#PROTOC_SH += $(vee-citools)-protoc sh -c
99
100# Usage: GO_JUNIT_REPORT := $(call get-docker-go-junit-repo)
101# get-docker-go-junit-repo = $(docker-run-app) $(vee-citools)-go-junit-report go-junit-report
102# GO_JUNIT_REPORT ?= $(call get-docker-go-junit-repo)
103
104# -----------------------------------------------------------------------
105# get-docker-gocover-cobertura = $(docker-run-app)/src/github.com/opencord/voltha-openolt-adapter $(vee-citools)-gocover-cobertura gocover-cobertura
106# GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura)
107
108## -----------------------------------------------------------------------
109## Coverage report: junit
110## -----------------------------------------------------------------------
111## Usage: GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
112## -----------------------------------------------------------------------
113get-go-junit-report-cmd =\
114 $(strip \
115 $(docker-run) \
116 -v ${CURDIR}:/app \
117 -i $(vee-citools)-go-junit-report go-junit-report \
118 )
119GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
120
121## -----------------------------------------------------------------------
122## Coverage report: cobertura
123## -----------------------------------------------------------------------
124## Usage: GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura-cmd)
125## -----------------------------------------------------------------------
126get-docker-go-cobertura-cmd =\
127 $(strip \
128 $(docker-run)\
129 -v ${CURDIR}:$(go-cobertura-docker-mount)\
130 -i $(vee-citools)-gocover-cobertura gocover-cobertura\
131 )
132GOCOVER_COBERTURA ?= $(call get-docker-go-cobertura-cmd)
133
134## -----------------------------------------------------------------------
135##
136## -----------------------------------------------------------------------
137get-cmd-docker-golangci-lint =\
138 $(strip \
139 $(docker-run-app) \
140 -v gocache:/.cache \
141 $(vee-golang)\
142 $(vee-citools)-golangci-lint\
143 golangci-lint\
144 )
145GOLANGCI_LINT ?= $(call get-cmd-docker-golangci-lint)
146
147## -----------------------------------------------------------------------
148##
149## -----------------------------------------------------------------------
150get-docker-hadolint =\
151 $(strip \
152 $(docker-run-app) \
153 $(vee-citools)-hadolint \
154 hadolint \
155 )
156HADOLINT ?= $(call get-docker-hadolint)
157
158$(if $(DEBUG),$(warning LEAVE))
159
160# [EOF]