Skip to content

Commit a201977

Browse files
cez81lunny
authored andcommitted
Fix for #828: Embed build tags (#1051)
* Fix for #828 Add build tags to ldflags and print in version output Signed-off-by: Jonas Östanbäck <[email protected]> * Reworked formatBuiltWith function Signed-off-by: Jonas Östanbäck <[email protected]> * Add tags to version information in admin panel Signed-off-by: Jonas Östanbäck <[email protected]> * Added new variable for use on admin page. Signed-off-by: Jonas Östanbäck <[email protected]> * Fixed incorrect indentation
1 parent 8947b71 commit a201977

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ BINDATA := modules/{options,public,templates}/bindata.go
1111
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
1212
JAVASCRIPTS :=
1313

14-
LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')"
14+
LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
1515

1616
TARGETS ?= linux/*,darwin/*,windows/*
1717
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)

main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package main // import "code.gitea.io/gitea"
88

99
import (
1010
"os"
11+
"strings"
1112

1213
"code.gitea.io/gitea/cmd"
1314
"code.gitea.io/gitea/modules/log"
@@ -18,15 +19,19 @@ import (
1819
// Version holds the current Gitea version
1920
var Version = "1.1.0+dev"
2021

22+
// Tags holds the build tags used
23+
var Tags = ""
24+
2125
func init() {
2226
setting.AppVer = Version
27+
setting.AppBuiltWith = formatBuiltWith(Tags)
2328
}
2429

2530
func main() {
2631
app := cli.NewApp()
2732
app.Name = "Gitea"
2833
app.Usage = "A painless self-hosted Git service"
29-
app.Version = Version
34+
app.Version = Version + formatBuiltWith(Tags)
3035
app.Commands = []cli.Command{
3136
cmd.CmdWeb,
3237
cmd.CmdServ,
@@ -41,3 +46,11 @@ func main() {
4146
log.Fatal(4, "Failed to run app with %s: %v", os.Args, err)
4247
}
4348
}
49+
50+
func formatBuiltWith(Tags string) string {
51+
if len(Tags) == 0 {
52+
return ""
53+
}
54+
55+
return " built with: " + strings.Replace(Tags, " ", ", ", -1)
56+
}

modules/setting/setting.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const (
5959
var (
6060
// AppVer settings
6161
AppVer string
62+
AppBuiltWith string
6263
AppName string
6364
AppURL string
6465
AppSubURL string
@@ -939,7 +940,7 @@ var logLevels = map[string]string{
939940
}
940941

941942
func newLogService() {
942-
log.Info("Gitea v%s", AppVer)
943+
log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
943944

944945
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
945946
LogConfigs = make([]string, len(LogModes))

modules/templates/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func NewFuncMap() []template.FuncMap {
4848
"AppVer": func() string {
4949
return setting.AppVer
5050
},
51+
"AppBuiltWith": func() string {
52+
return setting.AppBuiltWith
53+
},
5154
"AppDomain": func() string {
5255
return setting.Domain
5356
},

templates/admin/config.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<dt>{{.i18n.Tr "admin.config.app_name"}}</dt>
1414
<dd>{{AppName}}</dd>
1515
<dt>{{.i18n.Tr "admin.config.app_ver"}}</dt>
16-
<dd>{{AppVer}}</dd>
16+
<dd>{{AppVer}}{{AppBuiltWith}}</dd>
1717
<dt>{{.i18n.Tr "admin.config.app_url"}}</dt>
1818
<dd>{{.AppUrl}}</dd>
1919
<dt>{{.i18n.Tr "admin.config.domain"}}</dt>

0 commit comments

Comments
 (0)