Bring in all the other helper code
[multicloud/k8s.git] / src / k8splugin / Makefile
1 # SPDX-license-identifier: Apache-2.0
2 ##############################################################################
3 # Copyright (c) 2018 Intel Corporation
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 GOPATH := $(shell realpath "$(PWD)/../../")
11
12 export GOPATH ...
13 export GO111MODULE=on
14
15 .PHONY: plugins
16
17
18 all: clean plugins
19         CGO_ENABLED=1 GOOS=linux GOARCH=amd64
20         @go build -a -tags netgo -o ./k8plugin ./cmd/main.go
21
22 # The following is done this way as each patch on CI runs build and each merge runs deploy. So for build we don't need to build binary and hence
23 # no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with
24 # mock plugin errors out for unit tests. So the seperation avoids the error.
25
26 build: clean plugins test cover
27 deploy: build
28
29 .PHONY: test
30 test: unit integration
31
32 .PHONY: unit
33 unit:
34         @go test -v -tags 'unit' ./...
35
36 .PHONY: integration
37 integration: clean
38         @go build -tags 'integration' -buildmode=plugin -o ./mock_files/mock_plugins/mockplugin.so ./mock_files/mock_plugins/mockplugin.go
39         @go build -tags 'integration' -buildmode=plugin -o ./mock_files/mock_plugins/mocknetworkplugin.so ./mock_files/mock_plugins/mocknetworkplugin.go
40         @go test -v -tags 'integration' ./...
41
42 format:
43         @go fmt ./...
44
45 plugins:
46         @find plugins -maxdepth 1 -type d -not -path plugins -exec sh -c "ls {}/plugin.go | xargs go build -buildmode=plugin -a -tags netgo -o $(basename {}).so" \;
47
48 clean:
49         @find . -name "*so" -delete
50         @rm -f k8plugin
51
52 .PHONY: cover
53 cover:
54         @go test -tags 'unit' ./... -coverprofile=coverage.out
55         @go tool cover -html=coverage.out -o coverage.html