Browse Source

Merge pull request #57 from 9seconds/remove-go-generate

Remove generating of version.go
tags/0.15.1^2
Sergey Arkhipov 7 years ago
parent
commit
e7958aaf33
No account linked to committer's email address
5 changed files with 16 additions and 29 deletions
  1. 11
    12
      Makefile
  2. 1
    1
      go.mod
  3. 2
    2
      go.sum
  4. 2
    2
      main.go
  5. 0
    12
      scripts/generate_version.sh

+ 11
- 12
Makefile View File

@@ -3,26 +3,28 @@ IMAGE_NAME   := mtg
3 3
 APP_NAME     := $(IMAGE_NAME)
4 4
 
5 5
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
6
-APP_DEPS     := version.go
7 6
 
8
-GOLANGCI_LINT_VERSION := v1.10.2
7
+GOLANGCI_LINT_VERSION := v1.11.2
9 8
 
10
-COMMON_BUILD_FLAGS := -ldflags="-s -w"
9
+VERSION_GO         := $(shell go version)
10
+VERSION_DATE       := $(shell date -Ru)
11
+VERSION_TAG        := $(shell git describe --tags --always)
12
+COMMON_BUILD_FLAGS := -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
11 13
 
12 14
 MOD_ON  := env GO111MODULE=on
13 15
 MOD_OFF := env GO111MODULE=auto
14 16
 
15 17
 # -----------------------------------------------------------------------------
16 18
 
17
-$(APP_NAME): $(APP_DEPS)
19
+$(APP_NAME):
18 20
 	@$(MOD_ON) go build $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"
19 21
 
20
-static-$(APP_NAME): $(APP_DEPS)
22
+static-$(APP_NAME):
21 23
 	@$(MOD_ON) env CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"
22 24
 
23 25
 $(APP_NAME)-%: GOOS=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f1 -d-)
24 26
 $(APP_NAME)-%: GOARCH=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f2 -d-)
25
-$(APP_NAME)-%: $(APP_DEPS) ccbuilds
27
+$(APP_NAME)-%: ccbuilds
26 28
 	@$(MOD_ON) env "GOOS=$(GOOS)" "GOARCH=$(GOARCH)" \
27 29
 		go build \
28 30
 		$(COMMON_BUILD_FLAGS) \
@@ -31,9 +33,6 @@ $(APP_NAME)-%: $(APP_DEPS) ccbuilds
31 33
 ccbuilds:
32 34
 	@rm -rf ./ccbuilds && mkdir -p ./ccbuilds
33 35
 
34
-version.go:
35
-	@$(MOD_ON) go generate main.go
36
-
37 36
 vendor: go.mod go.sum
38 37
 	@$(MOD_ON) go mod vendor
39 38
 
@@ -53,15 +52,15 @@ crosscompile-dir:
53 52
 	@rm -rf "$(CC_DIR)" && mkdir -p "$(CC_DIR)"
54 53
 
55 54
 .PHONY: test
56
-test: vendor $(APP_DEPS)
55
+test: vendor
57 56
 	@$(MOD_ON) go test -v ./...
58 57
 
59 58
 .PHONY: lint
60
-lint: vendor $(APP_DEPS)
59
+lint: vendor
61 60
 	@$(MOD_OFF) golangci-lint run
62 61
 
63 62
 .PHONY: critic
64
-critic: vendor $(APP_DEPS)
63
+critic: vendor
65 64
 	@$(MOD_OFF) gocritic check-project "$(ROOT_DIR)"
66 65
 
67 66
 .PHONY: clean

+ 1
- 1
go.mod View File

@@ -25,7 +25,7 @@ require (
25 25
 	go.uber.org/atomic v1.3.2 // indirect
26 26
 	go.uber.org/multierr v1.1.0 // indirect
27 27
 	go.uber.org/zap v1.9.1
28
-	golang.org/x/net v0.0.0-20181029044818-c44066c5c816 // indirect
28
+	golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc // indirect
29 29
 	golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
30 30
 	gopkg.in/alecthomas/kingpin.v2 v2.2.6
31 31
 	gopkg.in/alexcesaro/statsd.v2 v2.0.0

+ 2
- 2
go.sum View File

@@ -49,8 +49,8 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
49 49
 go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
50 50
 go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
51 51
 go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
52
-golang.org/x/net v0.0.0-20181029044818-c44066c5c816 h1:mVFkLpejdFLXVUv9E42f3XJVfMdqd0IVLVIVLjZWn5o=
53
-golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
52
+golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc h1:ZMCWScCvS2fUVFw8LOpxyUUW5qiviqr4Dg5NdjLeiLU=
53
+golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
54 54
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
55 55
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
56 56
 gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=

+ 2
- 2
main.go View File

@@ -1,7 +1,5 @@
1 1
 package main
2 2
 
3
-//go:generate scripts/generate_version.sh
4
-
5 3
 import (
6 4
 	"encoding/json"
7 5
 	"fmt"
@@ -22,6 +20,8 @@ import (
22 20
 	"github.com/9seconds/mtg/stats"
23 21
 )
24 22
 
23
+var version = "dev" // this has to be set by build ld flags
24
+
25 25
 var (
26 26
 	app = kingpin.New("mtg", "Simple MTPROTO proxy.")
27 27
 

+ 0
- 12
scripts/generate_version.sh View File

@@ -1,12 +0,0 @@
1
-#!/bin/sh
2
-set -eu
3
-
4
-PROJECT_DIR="$(git rev-parse --show-toplevel)"
5
-OUTPUT_FILE="${PROJECT_DIR}/version.go"
6
-
7
-cat > "$OUTPUT_FILE" <<EOF
8
-package main
9
-// autogenerated by $(basename "$0") on $(date -Ru)
10
-
11
-const version = "$(git describe --long --always) ($(go version)) [$(date -Ru)]"
12
-EOF

Loading…
Cancel
Save