Skip to content

Refactoring of the makefile #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
.DS_Store
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skip this? (though it should be /log if anything ^.^)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


# 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
*.log
log/
custom/
data/
.vendor/
.idea/
*.iml
public/img/avatar/
*.exe
*.exe~
/gogs
profile/
*.pem
output*
gogs.sublime-project
gogs.sublime-workspace
/release

/bin
/dist
/custom
/data
/log
/public/img/avatar
16 changes: 10 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ go:
- 1.6
- 1.7

env:
TAGS: cert sqlite pam miniwinsvc

before_install:
- sudo apt-get update -qq
- sudo apt-get install -y libpam-dev

script:
- go build -v -tags 'cert sqlite pam miniwinsvc'
- |
for pkg in $(go list ./... | grep -v /vendor/)
do
go test -v -race -cover -coverprofile $GOPATH/src/$pkg/coverage.out $pkg || exit 1
done
- make clean
- make vet

# - make lint

- make test
- make build

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
160 changes: 109 additions & 51 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,74 +1,132 @@
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildGitHash=$(shell git rev-parse HEAD)"
DIST := dist
BIN := bin

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

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

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

.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
.PHONY: clean
clean:
go clean -i ./...
rm -rf $(BIN) $(DIST)

.PHONY: deps
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:
for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;

build: $(GENERATED)
go install $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' .
.PHONY: install
install: $(BIN)/$(EXECUTABLE)
cp $< $(GOPATH)/bin/

build-dev: $(GENERATED) govet
go install $(BUILD_FLAGS) -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' .
.PHONY: build
build: $(BIN)/$(EXECUTABLE)

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

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"
.PHONY: release
release: release-build release-copy release-check

release: build pack
.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)

bindata: modules/bindata/bindata.go
.PHONY: release-copy
release-copy:
mkdir -p $(DIST)/release
$(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)

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

less: public/css/index.css
.PHONY: latest
latest: release-build latest-copy latest-check

public/css/index.css: $(LESS_FILES)
lessc $< $@
.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)));)

clean:
go clean -i ./...
.PHONY: latest-check
latest-check:
cd $(DIST)/latest; $(foreach file,$(wildcard $(DIST)/latest/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)

clean-mac: clean
find . -name ".DS_Store" -print0 | xargs -0 rm
.PHONY: publish
publish: release latest

test:
go test -cover -race ./...
.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

fixme:
grep -rnw "FIXME" routers models modules
.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 $< $@

todo:
grep -rnw "TODO" routers models modules
.PHONY: generate
generate: bindata javascripts stylesheets
1 change: 1 addition & 0 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

var (
// CmdAdmin represents the available admin sub-command.
CmdAdmin = cli.Command{
Name: "admin",
Usage: "Preform admin operations on command line",
Expand Down
3 changes: 2 additions & 1 deletion cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"github.com/urfave/cli"
)

// CmdCert represents the available cert sub-command.
var CmdCert = cli.Command{
Name: "cert",
Usage: "Generate self-signed certificate",
Description: `Generate a self-signed X.509 certificate for a TLS server.
Description: `Generate a self-signed X.509 certificate for a TLS server.
Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
Action: runCert,
Flags: []cli.Flag{
Expand Down
2 changes: 2 additions & 0 deletions cmd/cert_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package cmd

import (
Expand All @@ -13,6 +14,7 @@ import (
"github.com/urfave/cli"
)

// CmdCert represents the available cert sub-command.
var CmdCert = cli.Command{
Name: "cert",
Usage: "Generate self-signed certificate",
Expand Down
1 change: 1 addition & 0 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/go-gitea/gitea/modules/setting"
)

// CmdDump represents the available dump sub-command.
var CmdDump = cli.Command{
Name: "dump",
Usage: "Dump Gogs files and database",
Expand Down
7 changes: 4 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
)

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{
Name: "serv",
Usage: "This command should only be called by SSH shell",
Expand Down Expand Up @@ -179,7 +180,7 @@ func runServ(c *cli.Context) error {
repo, err := models.GetRepositoryByName(repoUser.ID, reponame)
if err != nil {
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)
}
Expand Down Expand Up @@ -241,7 +242,7 @@ func runServ(c *cli.Context) error {
if err != nil {
fail("Internal error", "Fail to check access: %v", err)
} else if mode < requestedMode {
clientMessage := _ACCESS_DENIED_MESSAGE
clientMessage := accessDenied
if mode >= models.ACCESS_MODE_READ {
clientMessage = "You do not have sufficient authorization for this action"
}
Expand Down
1 change: 1 addition & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-gitea/gitea/modules/setting"
)

// CmdUpdate represents the available update sub-command.
var CmdUpdate = cli.Command{
Name: "update",
Usage: "This command should only be called by Git hook",
Expand Down
6 changes: 4 additions & 2 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/go-gitea/gitea/routers/user"
)

// CmdWeb represents the available web sub-command.
var CmdWeb = cli.Command{
Name: "web",
Usage: "Start Gogs web server",
Expand All @@ -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 {
ImportPath string
Version func() string
Expand Down Expand Up @@ -99,7 +101,7 @@ func checkVersion() {
for _, c := range checkers {
if !version.Compare(c.Version(), c.Expected, ">=") {
log.Fatal(4, `Dependency outdated!
Package '%s' current version (%s) is below requirement (%s),
Package '%s' current version (%s) is below requirement (%s),
please use following command to update this package and recompile Gogs:
go get -u %[1]s`, c.ImportPath, c.Version(), c.Expected)
}
Expand Down Expand Up @@ -653,7 +655,7 @@ func runWeb(ctx *cli.Context) error {
os.Remove(listenAddr)

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 {
break // Handle error after switch
}
Expand Down
Loading