forked from bufbuild/protobuf-es
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
188 lines (153 loc) · 7.51 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# See https://tech.davis-hansson.com/p/make/
SHELL := bash
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
TMP = .tmp
BIN = .tmp/bin
BUILD = .tmp/build
GEN = .tmp/gen
TS_VERSIONS = 4.1.2 4.2.4 4.3.5 4.4.4 4.5.2 4.6.4 4.7.4 4.8.4 4.9.5 5.0.4
node_modules: package-lock.json
npm ci
$(BUILD)/upstream-protobuf: node_modules packages/upstream-protobuf/version.txt $(shell find packages/upstream-protobuf -name '*.mjs' -not -path "*/node_modules/*")
@mkdir -p $(@D)
npm run -w packages/upstream-protobuf build
@touch $(@)
$(BUILD)/protobuf: node_modules tsconfig.base.json packages/protobuf/tsconfig.json $(shell find packages/protobuf/src -name '*.ts')
npm run -w packages/protobuf clean
npm run -w packages/protobuf build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protobuf-test: $(BUILD)/protobuf $(GEN)/protobuf-test node_modules tsconfig.base.json packages/protobuf-test/tsconfig.json $(shell find packages/protobuf-test/src -name '*.ts')
npm run -w packages/protobuf-test clean
npm run -w packages/protobuf-test build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protoplugin: $(BUILD)/protobuf node_modules tsconfig.base.json packages/protoplugin/tsconfig.json $(shell find packages/protoplugin/src -name '*.ts')
npm run -w packages/protoplugin clean
npm run -w packages/protoplugin build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protoplugin-test: $(BUILD)/protoplugin $(GEN)/protoplugin-test node_modules tsconfig.base.json packages/protoplugin-test/tsconfig.json $(shell find packages/protoplugin-test/src -name '*.ts')
npm run -w packages/protoplugin-test clean
npm run -w packages/protoplugin-test build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protoplugin-example: $(BUILD)/protoc-gen-es packages/protoplugin-example/buf.gen.yaml node_modules tsconfig.base.json packages/protoplugin-example/tsconfig.json $(shell find packages/protoplugin-example/src -name '*.ts')
npm run -w packages/protoplugin-example generate
npm run -w packages/protoplugin-example build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protoc-gen-es: $(BUILD)/protoplugin node_modules tsconfig.base.json packages/protoc-gen-es/tsconfig.json $(shell find packages/protoc-gen-es/src -name '*.ts')
npm run -w packages/protoc-gen-es clean
npm run -w packages/protoc-gen-es build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protobuf-conformance: $(GEN)/protobuf-conformance node_modules tsconfig.base.json packages/protobuf-conformance $(shell find packages/protobuf-conformance/src -name '*.ts')
npm run -w packages/protobuf-conformance clean
npm run -w packages/protobuf-conformance build
@mkdir -p $(@D)
@touch $(@)
$(BUILD)/protobuf-example: $(BUILD)/protobuf node_modules tsconfig.base.json packages/protobuf-example/tsconfig.json $(shell find packages/protobuf-example/src -name '*.ts')
npm run -w packages/protobuf-example build
@mkdir -p $(@D)
@touch $(@)
$(GEN)/protobuf-test: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es $(shell find packages/protobuf-test/extra -name '*.proto')
npm run -w packages/protobuf-test generate
@mkdir -p $(@D)
@touch $(@)
$(GEN)/protoplugin-test: $(BUILD)/protoc-gen-es $(shell find packages/protoplugin-test/proto -name '*.proto')
@rm -rf packages/protoplugin-test/src/gen/* packages/protoplugin-test/descriptorset.bin
@npm run -w packages/protoplugin-test buf:build
@npm run -w packages/protoplugin-test generate
$(GEN)/protobuf-conformance: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es
npm run -w packages/protobuf-conformance generate
@mkdir -p $(@D)
@touch $(@)
$(GEN)/protobuf-example: $(BUILD)/protoc-gen-es packages/protobuf-example/buf.gen.yaml $(shell find packages/protobuf-example -name '*.proto')
npm run -w packages/protobuf-example generate
@mkdir -p $(@D)
@touch $(@)
$(GEN)/protobuf-bench: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es packages/protobuf-bench Makefile
npm run -w packages/protobuf-bench generate
@mkdir -p $(@D)
@touch $(@)
.PHONY: help
help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'
.PHONY: all
all: build test format lint bench bootstrapwkt ## build, test, format, lint, bench, and bootstrapwkt (default)
.PHONY: ci
ci: build test-protobuf test-protoplugin test-conformance format lint bench bootstrapwkt #
$(MAKE) checkdiff
.PHONY: clean
clean: ## Delete build artifacts and installed dependencies
@# -X only removes untracked files, -d recurses into directories, -f actually removes files/dirs
git clean -Xdf
.PHONY: build
build: $(BUILD)/protobuf $(BUILD)/protobuf-test $(BUILD)/protoplugin $(BUILD)/protoplugin-test $(BUILD)/protobuf-conformance $(BUILD)/protoc-gen-es $(BUILD)/protobuf-example $(BUILD)/protoplugin-example ## Build
.PHONY: test
test: test-protobuf test-protoplugin test-conformance test-ts-compat ## Run all tests
.PHONY: test-protobuf
test-protobuf: $(BUILD)/protobuf-test packages/protobuf-test/jest.config.js
npm run -w packages/protobuf-test test
.PHONY: test-protoplugin
test-protoplugin: $(BUILD)/protoplugin-test packages/protoplugin-test/jest.config.js
npm run -w packages/protoplugin-test test
.PHONY: test-protoplugin-example
test-protoplugin-example: $(BUILD)/protoplugin-example
npm run -w packages/protoplugin-example test
.PHONY: test-conformance
test-conformance: $(BUILD)/upstream-protobuf $(BUILD)/protobuf-conformance
npm run -w packages/protobuf-conformance test
.PHONY: test-ts-compat
test-ts-compat: $(GEN)/protobuf-test $(BUILD)/protobuf node_modules
node packages/typescript-compat/typescript-compat.mjs
.PHONY: lint
lint: node_modules $(BUILD)/protobuf $(BUILD)/protobuf-test $(BUILD)/protobuf-conformance $(BUILD)/protoplugin $(GEN)/protobuf-bench $(GEN)/protobuf-example ## Lint all files
npx eslint --max-warnings 0 .
@# Check type exports on npm packages to verify they're correct
npm run -w packages/protobuf attw
npm run -w packages/protoplugin attw
.PHONY: format
format: node_modules ## Format all files, adding license headers
npx prettier --write '**/*.{json,js,jsx,ts,tsx,css,mjs,cjs}' --log-level error
npx license-header --ignore packages/protobuf/src/google/varint.ts
.PHONY: bench
bench: node_modules $(GEN)/protobuf-bench $(BUILD)/protobuf ## Benchmark code size
npm run -w packages/protobuf-bench report
.PHONY: perf
perf: $(BUILD)/protobuf-test
npm run -w packages/protobuf-test perf
.PHONY: bootstrapwkt
bootstrapwkt: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es node_modules ## Generate the well-known types in @bufbuild/protobuf
npm run -w packages/protobuf bootstrap
@# If the generated code differs, use it, and run tests again
npm run -w packages/protobuf bootstrap-diff || $(MAKE) build test format lint
.PHONY: setversion
setversion: ## Set a new version in for the project, i.e. make setversion SET_VERSION=1.2.3
node scripts/set-workspace-version.js $(SET_VERSION)
rm package-lock.json
npm i
$(MAKE) all
# Recommended procedure:
# 1. Set a new version with the target `setversion`
# 2. Commit and push all changes
# 3. Login with `npm login`
# 4. Run this target, publishing to npmjs.com
# 5. Tag the release
.PHONY: release
release: all ## Release @bufbuild/protobuf
@[ -z "$(shell git status --short)" ] || (echo "Uncommitted changes found." && exit 1);
npm publish \
--workspace packages/protobuf \
--workspace packages/protoplugin \
--workspace packages/protoc-gen-es
.PHONY: checkdiff
checkdiff:
@# Used in CI to verify that `make` doesn't produce a diff
test -z "$$(git status --porcelain | tee /dev/stderr)"