Skip to content

Commit 11f7fc5

Browse files
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 <[email protected]>
1 parent 8a0da9e commit 11f7fc5

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

Makefile

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ GO ?= go
77
SED_INPLACE := sed -i
88
SHASUM ?= shasum -a 256
99
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
10+
COMMA := ,
1011

1112
ifeq ($(HAS_GO), GO)
1213
GOPATH ?= $(shell $(GO) env GOPATH)
@@ -16,22 +17,14 @@ endif
1617

1718
ifeq ($(OS), Windows_NT)
1819
EXECUTABLE ?= gitea.exe
19-
FIND_PWD_REGEXP := find . -regextype posix-egrep
2020
else
2121
EXECUTABLE ?= gitea
2222
UNAME_S := $(shell uname -s)
23-
FIND_PWD_REGEXP := find . -regextype posix-egrep
24-
BUSYBOX := $(shell find --help 2>&1 | grep -o BusyBox)
2523
ifeq ($(UNAME_S),Darwin)
2624
SED_INPLACE := sed -i ''
27-
FIND_PWD_REGEXP := find -E .
2825
endif
2926
ifeq ($(UNAME_S),FreeBSD)
3027
SED_INPLACE := sed -i ''
31-
FIND_PWD_REGEXP := find -E .
32-
endif
33-
ifeq ($(BUSYBOX),BusyBox)
34-
FIND_PWD_REGEXP := find .
3528
endif
3629
endif
3730

@@ -71,9 +64,6 @@ LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(G
7164

7265
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/)))
7366

74-
GO_SOURCES ?= $(shell $(FIND_PWD_REGEXP) -regex '\./(node_modules|docs|public|options|contrib|data)' -prune -o -name "*.go" -type f -print)
75-
GO_SOURCES_OWN := $(filter-out ./vendor/% %/bindata.go, $(GO_SOURCES))
76-
7767
WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f)
7868
WEBPACK_CONFIGS := webpack.config.js .eslintrc .stylelintrc
7969
WEBPACK_DEST := public/js/index.js public/css/index.css
@@ -82,13 +72,24 @@ WEBPACK_DEST_DIRS := public/js public/css
8272
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
8373
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
8474

75+
TAGS ?=
76+
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
77+
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
78+
79+
GO_DIRS := cmd integrations models modules routers scripts services vendor
80+
GO_SOURCES := $(wildcard *.go)
81+
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)
82+
83+
ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
84+
GO_SOURCES += $(BINDATA_DEST)
85+
endif
86+
87+
GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
88+
8589
FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables
8690
FOMANTIC_DEST := public/fomantic/semantic.min.js public/fomantic/semantic.min.css
8791
FOMANTIC_DEST_DIR := public/fomantic
8892

89-
TAGS ?=
90-
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
91-
9293
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/[email protected]
9394
SWAGGER := GO111MODULE=on $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
9495
SWAGGER_SPEC := templates/swagger/v1_json.tmpl

0 commit comments

Comments
 (0)