From 11f7fc5621629624034916b118b4b4ef368f8418 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 9 Mar 2020 01:11:39 +0100 Subject: [PATCH] Use whitelist to find go files, run find only once (#10594) - Use a whitelist-based approach to find *.go files so we can use standard find syntax. Also included is a change that files no longer pass a leading './' which should help performance further. - Instead of running `find` multiple times in make because of the lazy evaluation, run it only once and add the bindata files when the bindata tag is present This is another huge speedup on my machine of around 2000%. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> --- Makefile | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 9b3b44dca..a4d1ac51c 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ GO ?= go SED_INPLACE := sed -i SHASUM ?= shasum -a 256 HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" ) +COMMA := , ifeq ($(HAS_GO), GO) GOPATH ?= $(shell $(GO) env GOPATH) @@ -16,22 +17,14 @@ endif ifeq ($(OS), Windows_NT) EXECUTABLE ?= gitea.exe - FIND_PWD_REGEXP := find . -regextype posix-egrep else EXECUTABLE ?= gitea UNAME_S := $(shell uname -s) - FIND_PWD_REGEXP := find . -regextype posix-egrep - BUSYBOX := $(shell find --help 2>&1 | grep -o BusyBox) ifeq ($(UNAME_S),Darwin) SED_INPLACE := sed -i '' - FIND_PWD_REGEXP := find -E . endif ifeq ($(UNAME_S),FreeBSD) SED_INPLACE := sed -i '' - FIND_PWD_REGEXP := find -E . - endif - ifeq ($(BUSYBOX),BusyBox) - FIND_PWD_REGEXP := find . endif endif @@ -71,9 +64,6 @@ LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(G PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/))) -GO_SOURCES ?= $(shell $(FIND_PWD_REGEXP) -regex '\./(node_modules|docs|public|options|contrib|data)' -prune -o -name "*.go" -type f -print) -GO_SOURCES_OWN := $(filter-out ./vendor/% %/bindata.go, $(GO_SOURCES)) - WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f) WEBPACK_CONFIGS := webpack.config.js .eslintrc .stylelintrc WEBPACK_DEST := public/js/index.js public/css/index.css @@ -82,13 +72,24 @@ WEBPACK_DEST_DIRS := public/js public/css BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST)) +TAGS ?= +TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS)) +TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags + +GO_DIRS := cmd integrations models modules routers scripts services vendor +GO_SOURCES := $(wildcard *.go) +GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go) + +ifeq ($(filter $(TAGS_SPLIT),bindata),bindata) + GO_SOURCES += $(BINDATA_DEST) +endif + +GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES)) + FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables FOMANTIC_DEST := public/fomantic/semantic.min.js public/fomantic/semantic.min.css FOMANTIC_DEST_DIR := public/fomantic -TAGS ?= -TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags - #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1 SWAGGER := GO111MODULE=on $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger SWAGGER_SPEC := templates/swagger/v1_json.tmpl