Skip to content

Commit 8080e23

Browse files
zeripathdelvh
andauthored
Move go-licenses to generate and separate generate into a frontend and backend component (#21061)
The `go-licenses` make task introduced in #21034 is being run on make vendor and occasionally causes an empty go-licenses file if the vendors need to change. This should be moved to the generate task as it is a generated file. Now because of this change we also need to split generation into two separate steps: 1. `generate-backend` 2. `generate-frontend` In the future it would probably be useful to make `generate-swagger` part of `generate-frontend` but it's not tolerated with our .drone.yml Ref #21034 Signed-off-by: Andrew Thornton <[email protected]> Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 0232601 commit 8080e23

File tree

12 files changed

+51
-8
lines changed

12 files changed

+51
-8
lines changed

Makefile

+21-6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack pub
111111
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
112112
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
113113

114+
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
115+
114116
SVG_DEST_DIR := public/img/svg
115117

116118
AIR_TMP_DIR := .air
@@ -130,9 +132,12 @@ GO_DIRS := cmd tests models modules routers build services tools
130132

131133
GO_SOURCES := $(wildcard *.go)
132134
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)
135+
GO_SOURCES += $(GENERATED_GO_DEST)
136+
GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
133137

134138
ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
135139
GO_SOURCES += $(BINDATA_DEST)
140+
GENERATED_GO_DEST += $(BINDATA_DEST)
136141
endif
137142

138143
# Force installation of playwright dependencies by setting this flag
@@ -259,7 +264,7 @@ clean:
259264
fmt:
260265
@MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
261266
$(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
262-
@# strip whitespace after '{{' and before `}}` unless there is only whitespace before it
267+
@# strip whitespace after '{{' and before `}}` unless there is only whitespace before it
263268
@$(SED_INPLACE) -e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' $(TEMPLATES)
264269

265270
.PHONY: vet
@@ -278,7 +283,9 @@ TAGS_PREREQ := $(TAGS_EVIDENCE)
278283
endif
279284

280285
.PHONY: generate-swagger
281-
generate-swagger:
286+
generate-swagger: $(SWAGGER_SPEC)
287+
288+
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
282289
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
283290
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
284291
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
@@ -398,7 +405,6 @@ unit-test-coverage:
398405
tidy:
399406
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
400407
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
401-
@$(MAKE) --no-print-directory assets/go-licenses.json
402408

403409
.PHONY: vendor
404410
vendor: tidy
@@ -702,16 +708,25 @@ install: $(wildcard *.go)
702708
build: frontend backend
703709

704710
.PHONY: frontend
705-
frontend: $(WEBPACK_DEST)
711+
frontend: generate-frontend $(WEBPACK_DEST)
706712

707713
.PHONY: backend
708-
backend: go-check generate $(EXECUTABLE)
714+
backend: go-check generate-backend $(EXECUTABLE)
709715

716+
# We generate the backend before the frontend in case we in future we want to generate things in the frontend from generated files in backend
710717
.PHONY: generate
711-
generate: $(TAGS_PREREQ)
718+
generate: generate-backend generate-frontend
719+
720+
.PHONY: generate-backend
721+
generate-backend: $(TAGS_PREREQ) generate-go
722+
723+
generate-go: $(TAGS_PREREQ)
712724
@echo "Running go generate..."
713725
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
714726

727+
.PHONY: generate-frontend
728+
generate-frontend: $(TAGS_PREREQ) go-licenses
729+
715730
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
716731
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
717732

modules/charset/ambiguous/generate.go

+11
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
110110
verbosef("Bad source:\n%s", buf.String())
111111
return fmt.Errorf("unable to format source: %w", err)
112112
}
113+
114+
old, err := os.ReadFile(filename)
115+
if err != nil && !os.IsNotExist(err) {
116+
return fmt.Errorf("failed to read old file %s because %w", filename, err)
117+
} else if err == nil {
118+
if bytes.Equal(bs, old) {
119+
// files are the same don't rewrite it.
120+
return nil
121+
}
122+
}
123+
113124
file, err := os.Create(filename)
114125
if err != nil {
115126
return fmt.Errorf("failed to create file %s because %w", filename, err)

modules/charset/invisible/generate.go

+11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
6363
verbosef("Bad source:\n%s", buf.String())
6464
return fmt.Errorf("unable to format source: %w", err)
6565
}
66+
67+
old, err := os.ReadFile(filename)
68+
if err != nil && !os.IsNotExist(err) {
69+
return fmt.Errorf("failed to read old file %s because %w", filename, err)
70+
} else if err == nil {
71+
if bytes.Equal(bs, old) {
72+
// files are the same don't rewrite it.
73+
return nil
74+
}
75+
}
76+
6677
file, err := os.Create(filename)
6778
if err != nil {
6879
return fmt.Errorf("failed to create file %s because %w", filename, err)

services/migrations/dump.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"code.gitea.io/gitea/modules/structs"
2727

2828
"github.com/google/uuid"
29-
3029
"gopkg.in/yaml.v2"
3130
)
3231

templates/repo/sub_menu.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</div>
4040
<a class="ui segment language-stats">
4141
{{range .LanguageStats}}
42-
<div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-placement="top" data-content={{ .Language }}>&nbsp;</div>
42+
<div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-placement="top" data-content={{.Language}}>&nbsp;</div>
4343
{{end}}
4444
</a>
4545
{{end}}

tests/integration/compare_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"code.gitea.io/gitea/tests"
13+
1314
"github.com/stretchr/testify/assert"
1415
)
1516

tests/integration/cors_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"code.gitea.io/gitea/tests"
12+
1213
"github.com/stretchr/testify/assert"
1314
)
1415

tests/integration/nonascii_branches_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/tests"
14+
1415
"github.com/stretchr/testify/assert"
1516
)
1617

tests/integration/pull_compare_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"code.gitea.io/gitea/tests"
12+
1213
"github.com/stretchr/testify/assert"
1314
)
1415

tests/integration/pull_create_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414

1515
"code.gitea.io/gitea/tests"
16+
1617
"github.com/stretchr/testify/assert"
1718
)
1819

tests/integration/repo_commits_search_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/tests"
14+
1415
"github.com/stretchr/testify/assert"
1516
)
1617

tests/integration/view_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"code.gitea.io/gitea/tests"
12+
1213
"github.com/stretchr/testify/assert"
1314
)
1415

0 commit comments

Comments
 (0)