Gogs: PR-5262

Fix make build failure when enviroment of GOPATH have multiple items

[alimy@rover gogs]$ pwd
[alimy@rover gogs]$ echo $GOPATH
[alimy@rover gogs]$ make
go install "-v" -ldflags '-X "github.com/gogs/gogs/pkg/setting.BuildTime=2018-06-04 06:17:19 UTC" -X "github.com/gogs/gogs/pkg/setting.BuildGitHash=c08aab90ec696b7fcc56b8da0a468e74d266b89e"' -tags '""'
cp '/home/alimy/art/ago:/home/alimy/art/arg/bin/gogs' .
cp: cannot stat '/home/alimy/art/ago:/home/alimy/art/arg/bin/gogs': No such file or directory
Makefile:36: recipe for target 'build' failed
make: *** [build] Error 1

In this scene GOPATH have two item (/home/alimy/art/ago and /home/alimy/art/arg) and gogs source is not in first GOPATH items, when excecute go install ... will install to path that contain the source of gogs’s GOPATH items. when cp gogs file back will occur error like above. this patch fixed this problem.

[alimy@rover gogs]$ echo $GOPATH
[alimy@rover gogs]$ pwd
[alimy@rover gogs]$ echo ${PWD%%src*}

Also when have multiple item in GOPATH env you should do this:

export GOPATH=$HOME/art/ago:$HOME/art/arg
export PATH=$GOROOT/bin:${GOPATH//://bin:}/bin

Gogs’s Makefile:

LDFLAGS += -X "github.com/gogs/gogs/pkg/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "github.com/gogs/gogs/pkg/setting.BuildGitHash=$(shell git rev-parse HEAD)"

DATA_FILES := $(shell find conf | sed 's/ /\\ /g')
LESS_FILES := $(wildcard public/less/gogs.less public/less/_*.less)
GENERATED  := pkg/bindata/bindata.go public/css/gogs.css

OS := $(shell uname)

TAGS = ""

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
GOPATH = $(shell echo $${PWD%%src*})

.PHONY: build pack release bindata clean

.IGNORE: public/css/gogs.css

all: build

check: test

dist: release

web: build
	./gogs web

	$(GOVET) gogs.go
	$(GOVET) models pkg routes

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' .

	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: pkg/bindata/bindata.go

pkg/bindata/bindata.go: $(DATA_FILES)
	go-bindata -o=$@ -ignore="\\.DS_Store|README.md|TRANSLATORS|auth.d" -pkg=bindata conf/...

less: public/css/gogs.css

public/css/gogs.css: $(LESS_FILES)
	@type lessc >/dev/null 2>&1 && lessc $< >$@ || echo "lessc command not found, skipped."

	go clean -i ./...

clean-mac: clean
	find . -name ".DS_Store" -print0 | xargs -0 rm

	go test -cover -race ./...

	grep -rnw "FIXME" cmd routers models pkg

	grep -rnw "TODO" cmd routers models pkg

# Legacy code should be remove by the time of release
	grep -rnw "LEGACY" cmd routes models pkg

Note a PR-5322 for Gogs.

 收藏: 技术相关网站 Gogs: PR-5322 


©2015-2021 Alimy All rights reserved.