@@ -45,21 +45,32 @@ GOOS ?= $(shell uname | tr A-Z a-z)
45
45
GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
46
46
47
47
GO_VERSION ?= 1.5.3
48
- GOURL ?= https://golang.org/dl
49
- GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH).tar.gz
50
- GOPATH := $(CURDIR)/.build/gopath
51
48
52
49
# Check for the correct version of go in the path. If we find it, use it.
53
50
# Otherwise, prepare to build go locally.
54
51
ifeq ($(shell command -v "go" >/dev/null && go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/'), $(GO_VERSION))
55
52
GOCC ?= $(shell command -v "go")
56
53
GOFMT ?= $(shell command -v "gofmt")
57
- GO ?= GOPATH=$(GOPATH) $(GOCC)
54
+ GO ?= $(GOCC)
58
55
else
56
+ GOURL ?= https://golang.org/dl
57
+ GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH).tar.gz
59
58
GOROOT ?= $(CURDIR)/.build/go$(GO_VERSION)
60
59
GOCC ?= $(GOROOT)/bin/go
61
60
GOFMT ?= $(GOROOT)/bin/gofmt
62
- GO ?= GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC)
61
+ GO ?= GOROOT=$(GOROOT) $(GOCC)
62
+ endif
63
+
64
+ # Use vendored dependencies if available. Otherwise try to download them.
65
+ ifneq (,$(wildcard vendor))
66
+ DEPENDENCIES := $(shell find vendor/ -type f -iname '*.go')
67
+ GO := GO15VENDOREXPERIMENT=1 $(GO)
68
+ else
69
+ GOPATH := $(CURDIR)/.build/gopath
70
+ ROOTPKG ?= github.com/prometheus/$(TARGET)
71
+ SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
72
+ DEPENDENCIES := dependencies-stamp
73
+ GO := GOPATH=$(GOPATH) $(GO)
63
74
endif
64
75
65
76
# Never honor GOBIN, should it be set at all.
@@ -68,32 +79,10 @@ unexport GOBIN
68
79
SUFFIX ?= $(GOOS)-$(GOARCH)
69
80
BINARY ?= $(TARGET)
70
81
ARCHIVE ?= $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
71
- ROOTPKG ?= github.com/prometheus/$(TARGET)
72
- SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
73
82
74
83
default: $(BINARY)
75
84
76
- $(GOCC):
77
- @echo Go version $(GO_VERSION) required but not found in PATH.
78
- @echo About to download and install go$(GO_VERSION) to $(GOROOT)
79
- @echo Abort now if you want to manually install it system-wide instead.
80
- @echo
81
- @sleep 5
82
- mkdir -p .build
83
- # The archive contains a single directory called 'go/'.
84
- curl -L $(GOURL)/$(GOPKG) | tar -C .build -xzf -
85
- rm -rf $(GOROOT)
86
- mv .build/go $(GOROOT)
87
-
88
- $(SELFLINK):
89
- mkdir -p $(dir $@)
90
- ln -s $(CURDIR) $@
91
-
92
- dependencies-stamp: $(GOCC) $(SRC) | $(SELFLINK)
93
- $(GO) get -d
94
- touch $@
95
-
96
- $(BINARY): $(GOCC) $(SRC) dependencies-stamp Makefile Makefile.COMMON
85
+ $(BINARY): $(GOCC) $(SRC) $(DEPENDENCIES) Makefile Makefile.COMMON
97
86
$(GO) build $(GOFLAGS) -o $@
98
87
99
88
.PHONY: archive
@@ -108,13 +97,36 @@ tag:
108
97
git push --tags
109
98
110
99
.PHONY: test
111
- test: $(GOCC) dependencies-stamp
112
- $(GO) test ./...
100
+ test: $(GOCC) $(DEPENDENCIES)
101
+ $(GO) test $$($(GO) list ./... | grep -v /vendor/)
113
102
114
103
.PHONY: format
115
104
format: $(GOCC)
116
- find . -iname '*.go' | egrep -v "^\./\.build|./generated|\./Godeps |\.(l|y)\.go" | xargs -n1 $(GOFMT) -w -s=true
105
+ find . -iname '*.go' | egrep -v "^\./\.build|./generated|\./vendor |\.(l|y)\.go" | xargs -n1 $(GOFMT) -w -s=true
117
106
118
107
.PHONY: clean
119
108
clean:
120
109
rm -rf $(BINARY) $(ARCHIVE) .build *-stamp
110
+
111
+
112
+
113
+ $(GOCC):
114
+ @echo Go version $(GO_VERSION) required but not found in PATH.
115
+ @echo About to download and install go$(GO_VERSION) to $(GOROOT)
116
+ @echo Abort now if you want to manually install it system-wide instead.
117
+ @echo
118
+ @sleep 5
119
+ mkdir -p .build
120
+ # The archive contains a single directory called 'go/'.
121
+ curl -L $(GOURL)/$(GOPKG) | tar -C .build -xzf -
122
+ rm -rf $(GOROOT)
123
+ mv .build/go $(GOROOT)
124
+
125
+ $(SELFLINK):
126
+ mkdir -p $(dir $@)
127
+ ln -s $(CURDIR) $@
128
+
129
+ # Download dependencies if project doesn't vendor them.
130
+ dependencies-stamp: $(GOCC) $(SRC) | $(SELFLINK)
131
+ $(GO) get -d
132
+ touch $@
0 commit comments