Skip to content

Commit 8831f0d

Browse files
committed
Merge branch 'master' into sparsehistogram
2 parents 24db95a + 147c58e commit 8831f0d

6 files changed

Lines changed: 134 additions & 83 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
target/
2+
tmp/

Makefile

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,71 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
KEY_ID ?= _DEFINE_ME_
14+
all:
15+
$(MAKE) go
16+
$(MAKE) build
1517

16-
all: go
18+
GO_FILE := go/metrics.pb.go
19+
PROTO_FILE := io/prometheus/client/metrics.proto
1720

18-
SUFFIXES:
21+
# Need to be on a previous version that doesn't cause the updated WKT go_package values to be added.
22+
PROTOC_VERSION := 3.13.0
23+
# This has been around for a while.
24+
PROTOC_GEN_GO_VERSION := v1.3.5
1925

20-
go: go/metrics.pb.go
26+
# There are no protobuf releases for Darwin ARM so for
27+
# now we always use the x86_64 release through Rosetta.
28+
UNAME_OS := $(shell uname -s)
29+
UNAME_ARCH := $(shell uname -m)
30+
ifeq ($(UNAME_OS),Darwin)
31+
PROTOC_OS := osx
32+
PROTOC_ARCH := x86_64
33+
endif
34+
ifeq ($(UNAME_OS),Linux)
35+
PROTOC_OS = linux
36+
PROTOC_ARCH := $(UNAME_ARCH)
37+
endif
38+
PROTOC := tmp/versions/protoc/$(PROTOC_VERSION)
39+
PROTOC_BIN := tmp/bin/protoc
40+
PROTOC_INCLUDE := tmp/include/google
41+
$(PROTOC):
42+
@if ! command -v curl >/dev/null 2>/dev/null; then echo "error: curl must be installed" >&2; exit 1; fi
43+
@if ! command -v unzip >/dev/null 2>/dev/null; then echo "error: unzip must be installed" >&2; exit 1; fi
44+
@rm -f $(PROTOC_BIN)
45+
@rm -rf $(PROTOC_INCLUDE)
46+
@mkdir -p $(dir $(PROTOC_BIN)) $(dir $(PROTOC_INCLUDE))
47+
$(eval PROTOC_TMP := $(shell mktemp -d))
48+
cd $(PROTOC_TMP); curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip -o protoc.zip
49+
cd $(PROTOC_TMP); unzip protoc.zip && mv bin/protoc $(PWD)/$(PROTOC_BIN) && mv include/google $(PWD)/$(PROTOC_INCLUDE)
50+
@rm -rf $(PROTOC_TMP)
51+
@rm -rf $(dir $(PROTOC))
52+
@mkdir -p $(dir $(PROTOC))
53+
@touch $(PROTOC)
2154

22-
go/metrics.pb.go: metrics.proto
23-
protoc $< --go_out=import_path=github.com/prometheus/client_model/,paths=source_relative:go/
55+
PROTOC_GEN_GO := tmp/versions/protoc-gen-go/$(PROTOC_GEN_GO_VERSION)
56+
PROTOC_GEN_GO_BIN := tmp/bin/protoc-gen-go
57+
$(PROTOC_GEN_GO):
58+
@rm -f $(PROTOC_GEN_GO_BIN)
59+
@mkdir -p $(dir $(PROTOC_GEN_GO_BIN))
60+
$(eval PROTOC_GEN_GO_TMP := $(shell mktemp -d))
61+
cd $(PROTOC_GEN_GO_TMP); GOBIN=$(PWD)/$(dir $(PROTOC_GEN_GO_BIN)) go get github.com/golang/protobuf/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
62+
@rm -rf $(PROTOC_GEN_GO_TMP)
63+
@rm -rf $(dir $(PROTOC_GEN_GO))
64+
@mkdir -p $(dir $(PROTOC_GEN_GO))
65+
@touch $(PROTOC_GEN_GO)
66+
67+
go: $(GO_FILE)
68+
69+
$(GO_FILE): $(PROTO_FILE) $(PROTOC_GEN_GO) $(PROTOC)
70+
@rm -rf $(dir $(GO_FILE)) tmp/go
71+
@mkdir -p $(dir $(GO_FILE)) tmp/go
72+
PATH=$(PWD)/tmp/bin:$$PATH protoc -I tmp/include -I . --go_out=paths=source_relative:tmp/go $(PROTO_FILE)
73+
@mv tmp/go/$(patsubst %.proto,%.pb.go,$(PROTO_FILE)) $(GO_FILE)
74+
75+
build: $(GO_FILE)
76+
go build ./go
2477

2578
clean:
26-
-rm -rf go/*
79+
-rm -rf go tmp
2780

28-
.PHONY: all clean go
81+
.PHONY: all clean go build

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module github.com/prometheus/client_model
22

33
go 1.9
44

5-
require (
6-
github.com/golang/protobuf v1.2.0
7-
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
8-
)
5+
require github.com/golang/protobuf v1.3.5

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
2-
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3-
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
4-
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
1+
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
2+
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=

go/metrics.pb.go

Lines changed: 69 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)