Merge "Improve Namespaces UTs"
[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 DEPENDENCIES := github.com/golang/dep/cmd/dep
12
13 export GOPATH ...
14
15 .PHONY: plugins
16
17
18 all: clean dep
19         CGO_ENABLED=1 GOOS=linux GOARCH=amd64
20         @find plugins -type d -not -path plugins -exec sh -c "ls {}/plugin.go | xargs go build -buildmode=plugin -a -tags netgo -o $(basename {}).so" \;
21         @go build -a -tags netgo -o ./k8plugin ./cmd/main.go
22
23 # 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
24 # no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with
25 # mock plugin errors out for unit tests. So the seperation avoids the error.
26
27 build: clean dep plugins test cover
28 deploy: build
29
30 .PHONY: test
31 test: unit integration
32
33 .PHONY: unit
34 unit:
35         @go test -v -tags 'unit' ./...
36
37 .PHONY: integration
38 integration: clean
39         @go build -buildmode=plugin -o ./mock_files/mock_plugins/mockplugin.so ./mock_files/mock_plugins/mockplugin.go
40         @go test -v -tags 'integration' ./...
41
42 format:
43         @go fmt ./...
44
45 plugins:
46         @find plugins -type d -not -path plugins -exec sh -c "ls {}/plugin.go | xargs go build -buildmode=plugin -o $(basename {}).so" \;
47
48 dep:
49         @go get -u $(DEPENDENCIES)
50         $(GOPATH)/bin/dep ensure
51
52 clean:
53         find . -name "*so" -delete
54         @rm -f k8plugin
55
56 .PHONY: cover
57 cover:
58         @go test -tags 'unit' ./... -coverprofile=coverage.out
59         @go tool cover -html=coverage.out -o coverage.html