Merge pull request #69 from go-gitea/makefile

Refactoring of the makefile
This commit is contained in:
Thomas Boerger 2016-11-05 00:06:41 +01:00 committed by GitHub
commit b58b634e0e
18 changed files with 1118 additions and 1337 deletions

52
.gitignore vendored
View File

@ -1,19 +1,37 @@
.DS_Store # Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
coverage.out
gitea
*.db *.db
*.log *.log
log/
custom/ /bin
data/ /dist
.vendor/ /custom
.idea/ /data
*.iml /log
public/img/avatar/ /public/img/avatar
*.exe
*.exe~
/gogs
profile/
*.pem
output*
gogs.sublime-project
gogs.sublime-workspace
/release

View File

@ -4,17 +4,21 @@ go:
- 1.6 - 1.6
- 1.7 - 1.7
env:
TAGS: cert sqlite pam miniwinsvc
before_install: before_install:
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -y libpam-dev - sudo apt-get install -y libpam-dev
script: script:
- go build -v -tags 'cert sqlite pam miniwinsvc' - make clean
- | - make vet
for pkg in $(go list ./... | grep -v /vendor/)
do # - make lint
go test -v -race -cover -coverprofile $GOPATH/src/$pkg/coverage.out $pkg || exit 1
done - make test
- make build
after_success: after_success:
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)

174
Makefile
View File

@ -1,74 +1,132 @@
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')" DIST := dist
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildGitHash=$(shell git rev-parse HEAD)" BIN := bin
DATA_FILES := $(shell find conf | sed 's/ /\\ /g') EXECUTABLE := gitea
LESS_FILES := $(wildcard public/less/gogs.less public/less/_*.less) IMPORT := github.com/go-gitea/gitea
GENERATED := modules/bindata/bindata.go public/css/index.css
TAGS = "" SHA := $(shell git rev-parse --short HEAD)
BUILD_FLAGS = "-v" DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
RELEASE_ROOT = "release" BINDATA := $(shell find conf | sed 's/ /\\ /g')
RELEASE_GOGS = "release/gogs" STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
NOW = $(shell date -u '+%Y%m%d%I%M%S') JAVASCRIPTS :=
GOVET = go tool vet -composites=false -methods=false -structtags=false
.PHONY: build pack release bindata clean LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildTime=$(DATE)"
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildGitHash=$(SHA)"
.IGNORE: public/css/index.css TARGETS ?= linux/*,darwin/*,windows/*
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
all: build TAGS ?=
check: test ifneq ($(TRAVIS_TAG),)
VERSION ?= $(TRAVIS_TAG)
else
ifneq ($(TRAVIS_BRANCH),)
VERSION ?= $(TRAVIS_BRANCH)
else
VERSION ?= master
endif
endif
dist: release .PHONY: all
all: clean test build
govet:
$(GOVET) main.go
$(GOVET) models modules routers
build: $(GENERATED)
go install $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' .
build-dev: $(GENERATED) govet
go install $(BUILD_FLAGS) -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' .
build-dev-race: $(GENERATED) govet
go install $(BUILD_FLAGS) -race -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' .
pack:
rm -rf $(RELEASE_GOGS)
mkdir -p $(RELEASE_GOGS)
cp -r gogs LICENSE README.md README_ZH.md templates public scripts $(RELEASE_GOGS)
rm -rf $(RELEASE_GOGS)/public/config.codekit $(RELEASE_GOGS)/public/less
cd $(RELEASE_ROOT) && zip -r gogs.$(NOW).zip "gogs"
release: build pack
bindata: modules/bindata/bindata.go
modules/bindata/bindata.go: $(DATA_FILES)
go-bindata -o=$@ -ignore="\\.DS_Store|README.md|TRANSLATORS" -pkg=bindata conf/...
less: public/css/index.css
public/css/index.css: $(LESS_FILES)
lessc $< $@
.PHONY: clean
clean: clean:
go clean -i ./... go clean -i ./...
rm -rf $(BIN) $(DIST)
clean-mac: clean .PHONY: deps
find . -name ".DS_Store" -print0 | xargs -0 rm deps:
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/jteeuwen/go-bindata/...; \
fi
.PHONY: fmt
fmt:
go fmt $(PACKAGES)
.PHONY: vet
vet:
go vet $(PACKAGES)
.PHONY: lint
lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/golang/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
.PHONY: test
test: test:
go test -cover -race ./... for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
fixme: .PHONY: install
grep -rnw "FIXME" routers models modules install: $(BIN)/$(EXECUTABLE)
cp $< $(GOPATH)/bin/
todo: .PHONY: build
grep -rnw "TODO" routers models modules build: $(BIN)/$(EXECUTABLE)
$(BIN)/$(EXECUTABLE): $(wildcard *.go)
go build -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
.PHONY: release
release: release-build release-copy release-check
.PHONY: release-build
release-build:
@which xgo > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/karalabe/xgo; \
fi
xgo -dest $(BIN) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -targets '$(TARGETS)' -out $(EXECUTABLE)-$(VERSION) $(IMPORT)
.PHONY: release-copy
release-copy:
mkdir -p $(DIST)/release
$(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
.PHONY: release-check
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
.PHONY: latest
latest: release-build latest-copy latest-check
.PHONY: latest-copy
latest-copy:
mkdir -p $(DIST)/latest
$(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/latest/$(subst $(EXECUTABLE)-$(VERSION),$(EXECUTABLE)-latest,$(notdir $(file)));)
.PHONY: latest-check
latest-check:
cd $(DIST)/latest; $(foreach file,$(wildcard $(DIST)/latest/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
.PHONY: publish
publish: release latest
.PHONY: bindata
bindata: modules/bindata/bindata.go
.IGNORE: modules/bindata/bindata.go
modules/bindata/bindata.go: $(BINDATA)
go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
go fmt $@
.PHONY: javascripts
javascripts: public/js/index.js
.IGNORE: public/js/index.js
public/js/index.js: $(JAVASCRIPTS)
cat $< >| $@
.PHONY: stylesheets
stylesheets: public/css/index.css
.IGNORE: public/css/index.css
public/css/index.css: $(STYLESHEETS)
lessc $< $@
.PHONY: generate
generate: bindata javascripts stylesheets

View File

@ -14,6 +14,7 @@ import (
) )
var ( var (
// CmdAdmin represents the available admin sub-command.
CmdAdmin = cli.Command{ CmdAdmin = cli.Command{
Name: "admin", Name: "admin",
Usage: "Preform admin operations on command line", Usage: "Preform admin operations on command line",

View File

@ -25,6 +25,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// CmdCert represents the available cert sub-command.
var CmdCert = cli.Command{ var CmdCert = cli.Command{
Name: "cert", Name: "cert",
Usage: "Generate self-signed certificate", Usage: "Generate self-signed certificate",

View File

@ -4,6 +4,7 @@
// Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package cmd package cmd
import ( import (
@ -13,6 +14,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// CmdCert represents the available cert sub-command.
var CmdCert = cli.Command{ var CmdCert = cli.Command{
Name: "cert", Name: "cert",
Usage: "Generate self-signed certificate", Usage: "Generate self-signed certificate",

View File

@ -20,6 +20,7 @@ import (
"github.com/go-gitea/gitea/modules/setting" "github.com/go-gitea/gitea/modules/setting"
) )
// CmdDump represents the available dump sub-command.
var CmdDump = cli.Command{ var CmdDump = cli.Command{
Name: "dump", Name: "dump",
Usage: "Dump Gogs files and database", Usage: "Dump Gogs files and database",

View File

@ -26,9 +26,10 @@ import (
) )
const ( const (
_ACCESS_DENIED_MESSAGE = "Repository does not exist or you do not have access" accessDenied = "Repository does not exist or you do not have access"
) )
// CmdServ represents the available serv sub-command.
var CmdServ = cli.Command{ var CmdServ = cli.Command{
Name: "serv", Name: "serv",
Usage: "This command should only be called by SSH shell", Usage: "This command should only be called by SSH shell",
@ -179,7 +180,7 @@ func runServ(c *cli.Context) error {
repo, err := models.GetRepositoryByName(repoUser.ID, reponame) repo, err := models.GetRepositoryByName(repoUser.ID, reponame)
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", repoUser.Name, reponame) fail(accessDenied, "Repository does not exist: %s/%s", repoUser.Name, reponame)
} }
fail("Internal error", "Failed to get repository: %v", err) fail("Internal error", "Failed to get repository: %v", err)
} }
@ -241,7 +242,7 @@ func runServ(c *cli.Context) error {
if err != nil { if err != nil {
fail("Internal error", "Fail to check access: %v", err) fail("Internal error", "Fail to check access: %v", err)
} else if mode < requestedMode { } else if mode < requestedMode {
clientMessage := _ACCESS_DENIED_MESSAGE clientMessage := accessDenied
if mode >= models.ACCESS_MODE_READ { if mode >= models.ACCESS_MODE_READ {
clientMessage = "You do not have sufficient authorization for this action" clientMessage = "You do not have sufficient authorization for this action"
} }

View File

@ -14,6 +14,7 @@ import (
"github.com/go-gitea/gitea/modules/setting" "github.com/go-gitea/gitea/modules/setting"
) )
// CmdUpdate represents the available update sub-command.
var CmdUpdate = cli.Command{ var CmdUpdate = cli.Command{
Name: "update", Name: "update",
Usage: "This command should only be called by Git hook", Usage: "This command should only be called by Git hook",

View File

@ -48,6 +48,7 @@ import (
"github.com/go-gitea/gitea/routers/user" "github.com/go-gitea/gitea/routers/user"
) )
// CmdWeb represents the available web sub-command.
var CmdWeb = cli.Command{ var CmdWeb = cli.Command{
Name: "web", Name: "web",
Usage: "Start Gogs web server", Usage: "Start Gogs web server",
@ -60,6 +61,7 @@ and it takes care of all the other things for you`,
}, },
} }
// VerChecker is a listing of required dependency versions.
type VerChecker struct { type VerChecker struct {
ImportPath string ImportPath string
Version func() string Version func() string
@ -653,7 +655,7 @@ func runWeb(ctx *cli.Context) error {
os.Remove(listenAddr) os.Remove(listenAddr)
var listener *net.UnixListener var listener *net.UnixListener
listener, err = net.ListenUnix("unix", &net.UnixAddr{listenAddr, "unix"}) listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: listenAddr, Net: "unix"})
if err != nil { if err != nil {
break // Handle error after switch break // Handle error after switch
} }

View File

@ -16,18 +16,19 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
const APP_VER = "0.9.99.0915" // Version holds the current Gitea version
const Version = "0.9.99.0915"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
setting.AppVer = APP_VER setting.AppVer = Version
} }
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "Gogs" app.Name = "Gogs"
app.Usage = "Go Git Service: a painless self-hosted Git service" app.Usage = "Go Git Service: a painless self-hosted Git service"
app.Version = APP_VER app.Version = Version
app.Commands = []cli.Command{ app.Commands = []cli.Command{
cmd.CmdWeb, cmd.CmdWeb,
cmd.CmdServ, cmd.CmdServ,

View File

@ -367,10 +367,10 @@ type HookTask struct {
func (t *HookTask) BeforeUpdate() { func (t *HookTask) BeforeUpdate() {
if t.RequestInfo != nil { if t.RequestInfo != nil {
t.RequestContent = t.MarshalJSON(t.RequestInfo) t.RequestContent = t.SimpleMarshalJSON(t.RequestInfo)
} }
if t.ResponseInfo != nil { if t.ResponseInfo != nil {
t.ResponseContent = t.MarshalJSON(t.ResponseInfo) t.ResponseContent = t.SimpleMarshalJSON(t.ResponseInfo)
} }
} }
@ -402,7 +402,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
} }
} }
func (t *HookTask) MarshalJSON(v interface{}) string { func (t *HookTask) SimpleMarshalJSON(v interface{}) string {
p, err := json.Marshal(v) p, err := json.Marshal(v)
if err != nil { if err != nil {
log.Error(3, "Marshal [%d]: %v", t.ID, err) log.Error(3, "Marshal [%d]: %v", t.ID, err)

View File

@ -289,7 +289,7 @@ func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) bindin
type EditRepoFileForm struct { type EditRepoFileForm struct {
TreePath string `binding:"Required;MaxSize(500)"` TreePath string `binding:"Required;MaxSize(500)"`
Content string `binding:"Required"` Content string `binding:"Required"`
CommitSummary string `binding:"MaxSize(100)` CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"` CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"` NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
@ -317,8 +317,8 @@ func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors
// //
type UploadRepoFileForm struct { type UploadRepoFileForm struct {
TreePath string `binding:MaxSize(500)"` TreePath string `binding:"MaxSize(500)"`
CommitSummary string `binding:"MaxSize(100)` CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"` CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"` NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
@ -345,7 +345,7 @@ func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Error
// \/ \/ \/ \/ // \/ \/ \/ \/
type DeleteRepoFileForm struct { type DeleteRepoFileForm struct {
CommitSummary string `binding:"MaxSize(100)` CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"` CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"` NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,6 @@ import (
"path" "path"
"strings" "strings"
"github.com/gogits/git-module"
"github.com/go-gitea/gitea/models" "github.com/go-gitea/gitea/models"
"github.com/go-gitea/gitea/modules/auth" "github.com/go-gitea/gitea/modules/auth"
"github.com/go-gitea/gitea/modules/base" "github.com/go-gitea/gitea/modules/base"
@ -19,6 +18,7 @@ import (
"github.com/go-gitea/gitea/modules/log" "github.com/go-gitea/gitea/modules/log"
"github.com/go-gitea/gitea/modules/setting" "github.com/go-gitea/gitea/modules/setting"
"github.com/go-gitea/gitea/modules/template" "github.com/go-gitea/gitea/modules/template"
"github.com/gogits/git-module"
) )
const ( const (

View File

@ -1,32 +0,0 @@
#!/usr/bin/env bash
outPath=./output
rm -rf $outPath
mkdir $outPath
go build ../main.go -o gitea
PLATFORM=`uname | cut -d _ -f 1`
if [ $PLATFORM = "MINGW32" ] || [ $PLATFORM = "MINGW64" ] || [ $PLATFORM = "CYGWIN" ]; then
GOGS_EXE=gogs.exe
else
GOGS_EXE=gogs
fi
chmod +x $GOGS_EXE
mv $GOGS_EXE $outPath/
cp -r ../conf/ $outPath/conf/
cp -r ../custom/ $outPath/custom/
cp -r dockerfiles/ $outPath/dockerfiles/
cp -r ../public/ $outPath/public/
cp -r ../templates/ $outPath/templates/
cp ../cert.pem $outPath/
cp ../CONTRIBUTING.md $outPath/
cp gogs_supervisord.sh $outPath/
cp ../key.pem $outPath/
cp ../LICENSE $outPath/
cp ../README.md $outPath/
cp ../README_ZH.md $outPath/
cp start.bat $outPath/
cp start.sh $outPath/
cp ../wercker.yml $outPath/
cp mysql.sql $outPath/

View File

@ -1,28 +0,0 @@
#!/usr/bin/env bash
outPlattform=freebsd
outArch=amd64
outPath=./output_$outPlattform_$outArch
rm -rf $outPath
mkdir $outPath
CGO_ENABLED=0 GOOS=$outPlattform GOARCH=$outArch go build ../main.go -o gitea
chmod +x gogs
mv gogs $outPath/
cp -r ../conf/ $outPath/conf/
cp -r ../custom/ $outPath/custom/
cp -r dockerfiles/ $outPath/dockerfiles/
cp -r ../public/ $outPath/public/
cp -r ../templates/ $outPath/templates/
cp ../cert.pem $outPath/
cp ../CONTRIBUTING.md $outPath/
cp gogs_supervisord.sh $outPath/
cp ../key.pem $outPath/
cp ../LICENSE $outPath/
cp ../README.md $outPath/
cp ../README_ZH.md $outPath/
cp start.bat $outPath/
cp start.sh $outPath/
cp ../wercker.yml $outPath/
cp mysql.sql $outPath/

View File

@ -1,28 +0,0 @@
#!/usr/bin/env bash
outPlattform=linux
outArch=amd64
outPath=./output_$outPlattform_$outArch
rm -rf $outPath
mkdir $outPath
CGO_ENABLED=0 GOOS=$outPlattform GOARCH=$outArch go build ../main.go -o gitea
chmod +x gogs
mv gogs $outPath/
cp -r ../conf/ $outPath/conf/
cp -r ../custom/ $outPath/custom/
cp -r dockerfiles/ $outPath/dockerfiles/
cp -r ../public/ $outPath/public/
cp -r ../templates/ $outPath/templates/
cp ../cert.pem $outPath/
cp ../CONTRIBUTING.md $outPath/
cp gogs_supervisord.sh $outPath/
cp ../key.pem $outPath/
cp ../LICENSE $outPath/
cp ../README.md $outPath/
cp ../README_ZH.md $outPath/
cp start.bat $outPath/
cp start.sh $outPath/
cp ../wercker.yml $outPath/
cp mysql.sql $outPath/