aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile48
-rw-r--r--Makefile.common100
2 files changed, 106 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 031698e..a254ef7 100644
--- a/Makefile
+++ b/Makefile
@@ -11,20 +11,15 @@
11# See the License for the specific language governing permissions and 11# See the License for the specific language governing permissions and
12# limitations under the License. 12# limitations under the License.
13 13
14include Makefile.common
15
14GO ?= GO15VENDOREXPERIMENT=1 go 16GO ?= GO15VENDOREXPERIMENT=1 go
15GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
16GOARCH := $(shell $(GO) env GOARCH) 17GOARCH := $(shell $(GO) env GOARCH)
17GOHOSTARCH := $(shell $(GO) env GOHOSTARCH) 18GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)
18 19
19PROMTOOL ?= $(GOPATH)/bin/promtool 20PROMTOOL ?= $(FIRST_GOPATH)/bin/promtool
20PROMU ?= $(GOPATH)/bin/promu
21STATICCHECK ?= $(GOPATH)/bin/staticcheck
22pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
23 21
24PREFIX ?= $(shell pwd)
25BIN_DIR ?= $(shell pwd)
26DOCKER_IMAGE_NAME ?= node-exporter 22DOCKER_IMAGE_NAME ?= node-exporter
27DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
28MACH ?= $(shell uname -m) 23MACH ?= $(shell uname -m)
29DOCKERFILE ?= Dockerfile 24DOCKERFILE ?= Dockerfile
30 25
@@ -75,10 +70,6 @@ $(eval $(call goarch_pair,mips64el,mipsel))
75 70
76all: style vet staticcheck checkmetrics build test $(cross-test) $(test-e2e) 71all: style vet staticcheck checkmetrics build test $(cross-test) $(test-e2e)
77 72
78style:
79 @echo ">> checking code style"
80 @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
81
82test: collector/fixtures/sys/.unpacked 73test: collector/fixtures/sys/.unpacked
83 @echo ">> running tests" 74 @echo ">> running tests"
84 $(GO) test -short $(test-flags) $(pkgs) 75 $(GO) test -short $(test-flags) $(pkgs)
@@ -107,26 +98,6 @@ checkmetrics: $(PROMTOOL)
107 @echo ">> checking metrics for correctness" 98 @echo ">> checking metrics for correctness"
108 ./checkmetrics.sh $(PROMTOOL) $(e2e-out) 99 ./checkmetrics.sh $(PROMTOOL) $(e2e-out)
109 100
110format:
111 @echo ">> formatting code"
112 @$(GO) fmt $(pkgs)
113
114vet:
115 @echo ">> vetting code"
116 @$(GO) vet $(pkgs)
117
118staticcheck: $(STATICCHECK)
119 @echo ">> running staticcheck"
120 @$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
121
122build: $(PROMU)
123 @echo ">> building binaries"
124 @$(PROMU) build --prefix $(PREFIX)
125
126tarball: $(PROMU)
127 @echo ">> building release tarball"
128 @$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
129
130docker: 101docker:
131ifeq ($(MACH), ppc64le) 102ifeq ($(MACH), ppc64le)
132 $(eval DOCKERFILE=Dockerfile.ppc64le) 103 $(eval DOCKERFILE=Dockerfile.ppc64le)
@@ -138,20 +109,13 @@ test-docker:
138 @echo ">> testing docker image" 109 @echo ">> testing docker image"
139 ./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100 110 ./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100
140 111
141$(GOPATH)/bin/promtool promtool: 112$(FIRST_GOPATH)/bin/promtool promtool:
142 @GOOS= GOARCH= $(GO) get -u github.com/prometheus/prometheus/cmd/promtool 113 @GOOS= GOARCH= $(GO) get -u github.com/prometheus/prometheus/cmd/promtool
143 114
144$(GOPATH)/bin/promu promu: 115.PHONY: test-e2e promtool checkmetrics
145 @GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
146
147$(GOPATH)/bin/staticcheck:
148 @GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
149
150
151.PHONY: all style format build test test-e2e vet tarball docker promtool promu staticcheck checkmetrics
152 116
153# Declaring the binaries at their default locations as PHONY targets is a hack 117# Declaring the binaries at their default locations as PHONY targets is a hack
154# to ensure the latest version is downloaded on every make execution. 118# to ensure the latest version is downloaded on every make execution.
155# If this is not desired, copy/symlink these binaries to a different path and 119# If this is not desired, copy/symlink these binaries to a different path and
156# set the respective environment variables. 120# set the respective environment variables.
157.PHONY: $(GOPATH)/bin/promtool $(GOPATH)/bin/promu $(GOPATH)/bin/staticcheck 121.PHONY: $(FIRST_GOPATH)/bin/promtool
diff --git a/Makefile.common b/Makefile.common
new file mode 100644
index 0000000..353494c
--- /dev/null
+++ b/Makefile.common
@@ -0,0 +1,100 @@
1# Copyright 2018 The Prometheus Authors
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14
15# A common Makefile that includes rules to be reused in different prometheus projects.
16# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
17
18# Example usage :
19# Create the main Makefile in the root project directory.
20# include Makefile.common
21# customTarget:
22# @echo ">> Running customTarget"
23#
24
25# Ensure GOBIN is not set during build so that promu is installed to the correct path
26unexport GOBIN
27
28GO ?= go
29GOFMT ?= $(GO)fmt
30FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
31PROMU := $(FIRST_GOPATH)/bin/promu
32STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
33GOVENDOR := $(FIRST_GOPATH)/bin/govendor
34pkgs = ./...
35
36PREFIX ?= $(shell pwd)
37BIN_DIR ?= $(shell pwd)
38DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
39
40all: style staticcheck unused build test
41
42style:
43 @echo ">> checking code style"
44 ! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
45
46check_license:
47 @echo ">> checking license header"
48 @licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
49 awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
50 done); \
51 if [ -n "$${licRes}" ]; then \
52 echo "license header checking failed:"; echo "$${licRes}"; \
53 exit 1; \
54 fi
55
56test-short:
57 @echo ">> running short tests"
58 $(GO) test -short $(pkgs)
59
60test:
61 @echo ">> running all tests"
62 $(GO) test -race $(pkgs)
63
64format:
65 @echo ">> formatting code"
66 $(GO) fmt $(pkgs)
67
68vet:
69 @echo ">> vetting code"
70 $(GO) vet $(pkgs)
71
72staticcheck: $(STATICCHECK)
73 @echo ">> running staticcheck"
74 $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
75
76unused: $(GOVENDOR)
77 @echo ">> running check for unused packages"
78 @$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
79
80build: promu
81 @echo ">> building binaries"
82 $(PROMU) build --prefix $(PREFIX)
83
84tarball: promu
85 @echo ">> building release tarball"
86 $(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
87
88docker:
89 docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
90
91promu:
92 GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
93
94$(FIRST_GOPATH)/bin/staticcheck:
95 GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
96
97$(FIRST_GOPATH)/bin/govendor:
98 GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
99
100.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck govendor $(FIRST_GOPATH)/bin/govendor \ No newline at end of file