Skip to content

Commit b58b634

Browse files
authored
Merge pull request #69 from go-gitea/makefile
Refactoring of the makefile
2 parents ba4d255 + c524078 commit b58b634

File tree

18 files changed

+1111
-1330
lines changed

18 files changed

+1111
-1330
lines changed

.gitignore

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
1-
.DS_Store
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof
25+
26+
coverage.out
27+
gitea
28+
229
*.db
330
*.log
4-
log/
5-
custom/
6-
data/
7-
.vendor/
8-
.idea/
9-
*.iml
10-
public/img/avatar/
11-
*.exe
12-
*.exe~
13-
/gogs
14-
profile/
15-
*.pem
16-
output*
17-
gogs.sublime-project
18-
gogs.sublime-workspace
19-
/release
31+
32+
/bin
33+
/dist
34+
/custom
35+
/data
36+
/log
37+
/public/img/avatar

.travis.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ go:
44
- 1.6
55
- 1.7
66

7+
env:
8+
TAGS: cert sqlite pam miniwinsvc
9+
710
before_install:
811
- sudo apt-get update -qq
912
- sudo apt-get install -y libpam-dev
1013

1114
script:
12-
- go build -v -tags 'cert sqlite pam miniwinsvc'
13-
- |
14-
for pkg in $(go list ./... | grep -v /vendor/)
15-
do
16-
go test -v -race -cover -coverprofile $GOPATH/src/$pkg/coverage.out $pkg || exit 1
17-
done
15+
- make clean
16+
- make vet
17+
18+
# - make lint
19+
20+
- make test
21+
- make build
1822

1923
after_success:
2024
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 109 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,132 @@
1-
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
2-
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildGitHash=$(shell git rev-parse HEAD)"
1+
DIST := dist
2+
BIN := bin
33

4-
DATA_FILES := $(shell find conf | sed 's/ /\\ /g')
5-
LESS_FILES := $(wildcard public/less/gogs.less public/less/_*.less)
6-
GENERATED := modules/bindata/bindata.go public/css/index.css
4+
EXECUTABLE := gitea
5+
IMPORT := github.com/go-gitea/gitea
76

8-
TAGS = ""
9-
BUILD_FLAGS = "-v"
7+
SHA := $(shell git rev-parse --short HEAD)
8+
DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
109

11-
RELEASE_ROOT = "release"
12-
RELEASE_GOGS = "release/gogs"
13-
NOW = $(shell date -u '+%Y%m%d%I%M%S')
14-
GOVET = go tool vet -composites=false -methods=false -structtags=false
10+
BINDATA := $(shell find conf | sed 's/ /\\ /g')
11+
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
12+
JAVASCRIPTS :=
1513

16-
.PHONY: build pack release bindata clean
14+
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildTime=$(DATE)"
15+
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildGitHash=$(SHA)"
1716

18-
.IGNORE: public/css/index.css
17+
TARGETS ?= linux/*,darwin/*,windows/*
18+
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
1919

20-
all: build
20+
TAGS ?=
2121

22-
check: test
22+
ifneq ($(TRAVIS_TAG),)
23+
VERSION ?= $(TRAVIS_TAG)
24+
else
25+
ifneq ($(TRAVIS_BRANCH),)
26+
VERSION ?= $(TRAVIS_BRANCH)
27+
else
28+
VERSION ?= master
29+
endif
30+
endif
2331

24-
dist: release
32+
.PHONY: all
33+
all: clean test build
2534

26-
govet:
27-
$(GOVET) main.go
28-
$(GOVET) models modules routers
35+
.PHONY: clean
36+
clean:
37+
go clean -i ./...
38+
rm -rf $(BIN) $(DIST)
39+
40+
.PHONY: deps
41+
deps:
42+
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
43+
go get -u github.com/jteeuwen/go-bindata/...; \
44+
fi
45+
46+
.PHONY: fmt
47+
fmt:
48+
go fmt $(PACKAGES)
49+
50+
.PHONY: vet
51+
vet:
52+
go vet $(PACKAGES)
53+
54+
.PHONY: lint
55+
lint:
56+
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
57+
go get -u github.com/golang/lint/golint; \
58+
fi
59+
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
60+
61+
.PHONY: test
62+
test:
63+
for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
2964

30-
build: $(GENERATED)
31-
go install $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
32-
cp '$(GOPATH)/bin/gogs' .
65+
.PHONY: install
66+
install: $(BIN)/$(EXECUTABLE)
67+
cp $< $(GOPATH)/bin/
3368

34-
build-dev: $(GENERATED) govet
35-
go install $(BUILD_FLAGS) -tags '$(TAGS)'
36-
cp '$(GOPATH)/bin/gogs' .
69+
.PHONY: build
70+
build: $(BIN)/$(EXECUTABLE)
3771

38-
build-dev-race: $(GENERATED) govet
39-
go install $(BUILD_FLAGS) -race -tags '$(TAGS)'
40-
cp '$(GOPATH)/bin/gogs' .
72+
$(BIN)/$(EXECUTABLE): $(wildcard *.go)
73+
go build -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
4174

42-
pack:
43-
rm -rf $(RELEASE_GOGS)
44-
mkdir -p $(RELEASE_GOGS)
45-
cp -r gogs LICENSE README.md README_ZH.md templates public scripts $(RELEASE_GOGS)
46-
rm -rf $(RELEASE_GOGS)/public/config.codekit $(RELEASE_GOGS)/public/less
47-
cd $(RELEASE_ROOT) && zip -r gogs.$(NOW).zip "gogs"
75+
.PHONY: release
76+
release: release-build release-copy release-check
4877

49-
release: build pack
78+
.PHONY: release-build
79+
release-build:
80+
@which xgo > /dev/null; if [ $$? -ne 0 ]; then \
81+
go get -u github.com/karalabe/xgo; \
82+
fi
83+
xgo -dest $(BIN) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -targets '$(TARGETS)' -out $(EXECUTABLE)-$(VERSION) $(IMPORT)
5084

51-
bindata: modules/bindata/bindata.go
85+
.PHONY: release-copy
86+
release-copy:
87+
mkdir -p $(DIST)/release
88+
$(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
5289

53-
modules/bindata/bindata.go: $(DATA_FILES)
54-
go-bindata -o=$@ -ignore="\\.DS_Store|README.md|TRANSLATORS" -pkg=bindata conf/...
90+
.PHONY: release-check
91+
release-check:
92+
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
5593

56-
less: public/css/index.css
94+
.PHONY: latest
95+
latest: release-build latest-copy latest-check
5796

58-
public/css/index.css: $(LESS_FILES)
59-
lessc $< $@
97+
.PHONY: latest-copy
98+
latest-copy:
99+
mkdir -p $(DIST)/latest
100+
$(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/latest/$(subst $(EXECUTABLE)-$(VERSION),$(EXECUTABLE)-latest,$(notdir $(file)));)
60101

61-
clean:
62-
go clean -i ./...
102+
.PHONY: latest-check
103+
latest-check:
104+
cd $(DIST)/latest; $(foreach file,$(wildcard $(DIST)/latest/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
63105

64-
clean-mac: clean
65-
find . -name ".DS_Store" -print0 | xargs -0 rm
106+
.PHONY: publish
107+
publish: release latest
66108

67-
test:
68-
go test -cover -race ./...
109+
.PHONY: bindata
110+
bindata: modules/bindata/bindata.go
111+
112+
.IGNORE: modules/bindata/bindata.go
113+
modules/bindata/bindata.go: $(BINDATA)
114+
go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
115+
go fmt $@
116+
117+
.PHONY: javascripts
118+
javascripts: public/js/index.js
69119

70-
fixme:
71-
grep -rnw "FIXME" routers models modules
120+
.IGNORE: public/js/index.js
121+
public/js/index.js: $(JAVASCRIPTS)
122+
cat $< >| $@
123+
124+
.PHONY: stylesheets
125+
stylesheets: public/css/index.css
126+
127+
.IGNORE: public/css/index.css
128+
public/css/index.css: $(STYLESHEETS)
129+
lessc $< $@
72130

73-
todo:
74-
grep -rnw "TODO" routers models modules
131+
.PHONY: generate
132+
generate: bindata javascripts stylesheets

cmd/admin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
var (
17+
// CmdAdmin represents the available admin sub-command.
1718
CmdAdmin = cli.Command{
1819
Name: "admin",
1920
Usage: "Preform admin operations on command line",

cmd/cert.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ import (
2525
"github.com/urfave/cli"
2626
)
2727

28+
// CmdCert represents the available cert sub-command.
2829
var CmdCert = cli.Command{
2930
Name: "cert",
3031
Usage: "Generate self-signed certificate",
31-
Description: `Generate a self-signed X.509 certificate for a TLS server.
32+
Description: `Generate a self-signed X.509 certificate for a TLS server.
3233
Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
3334
Action: runCert,
3435
Flags: []cli.Flag{

cmd/cert_stub.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Copyright 2014 The Gogs Authors. All rights reserved.
55
// Use of this source code is governed by a MIT-style
66
// license that can be found in the LICENSE file.
7+
78
package cmd
89

910
import (
@@ -13,6 +14,7 @@ import (
1314
"github.com/urfave/cli"
1415
)
1516

17+
// CmdCert represents the available cert sub-command.
1618
var CmdCert = cli.Command{
1719
Name: "cert",
1820
Usage: "Generate self-signed certificate",

cmd/dump.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/go-gitea/gitea/modules/setting"
2121
)
2222

23+
// CmdDump represents the available dump sub-command.
2324
var CmdDump = cli.Command{
2425
Name: "dump",
2526
Usage: "Dump Gogs files and database",

cmd/serve.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import (
2626
)
2727

2828
const (
29-
_ACCESS_DENIED_MESSAGE = "Repository does not exist or you do not have access"
29+
accessDenied = "Repository does not exist or you do not have access"
3030
)
3131

32+
// CmdServ represents the available serv sub-command.
3233
var CmdServ = cli.Command{
3334
Name: "serv",
3435
Usage: "This command should only be called by SSH shell",
@@ -179,7 +180,7 @@ func runServ(c *cli.Context) error {
179180
repo, err := models.GetRepositoryByName(repoUser.ID, reponame)
180181
if err != nil {
181182
if models.IsErrRepoNotExist(err) {
182-
fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", repoUser.Name, reponame)
183+
fail(accessDenied, "Repository does not exist: %s/%s", repoUser.Name, reponame)
183184
}
184185
fail("Internal error", "Failed to get repository: %v", err)
185186
}
@@ -241,7 +242,7 @@ func runServ(c *cli.Context) error {
241242
if err != nil {
242243
fail("Internal error", "Fail to check access: %v", err)
243244
} else if mode < requestedMode {
244-
clientMessage := _ACCESS_DENIED_MESSAGE
245+
clientMessage := accessDenied
245246
if mode >= models.ACCESS_MODE_READ {
246247
clientMessage = "You do not have sufficient authorization for this action"
247248
}

cmd/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/go-gitea/gitea/modules/setting"
1515
)
1616

17+
// CmdUpdate represents the available update sub-command.
1718
var CmdUpdate = cli.Command{
1819
Name: "update",
1920
Usage: "This command should only be called by Git hook",

cmd/web.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
"github.com/go-gitea/gitea/routers/user"
4949
)
5050

51+
// CmdWeb represents the available web sub-command.
5152
var CmdWeb = cli.Command{
5253
Name: "web",
5354
Usage: "Start Gogs web server",
@@ -60,6 +61,7 @@ and it takes care of all the other things for you`,
6061
},
6162
}
6263

64+
// VerChecker is a listing of required dependency versions.
6365
type VerChecker struct {
6466
ImportPath string
6567
Version func() string
@@ -99,7 +101,7 @@ func checkVersion() {
99101
for _, c := range checkers {
100102
if !version.Compare(c.Version(), c.Expected, ">=") {
101103
log.Fatal(4, `Dependency outdated!
102-
Package '%s' current version (%s) is below requirement (%s),
104+
Package '%s' current version (%s) is below requirement (%s),
103105
please use following command to update this package and recompile Gogs:
104106
go get -u %[1]s`, c.ImportPath, c.Version(), c.Expected)
105107
}
@@ -653,7 +655,7 @@ func runWeb(ctx *cli.Context) error {
653655
os.Remove(listenAddr)
654656

655657
var listener *net.UnixListener
656-
listener, err = net.ListenUnix("unix", &net.UnixAddr{listenAddr, "unix"})
658+
listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: listenAddr, Net: "unix"})
657659
if err != nil {
658660
break // Handle error after switch
659661
}

0 commit comments

Comments
 (0)