-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
216 lines (180 loc) · 7.4 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
include vendor/vendorpull/targets.mk
.PHONY: lint clean distclean html docker
.DEFAULT_GOAL = docker
METADATA_DESCRIPTION = A space-efficiency benchmark of JSON-compatible serialization specifications
export METADATA_DESCRIPTION
METADATA_ORGANIZATION = sourcemeta
export METADATA_ORGANIZATION
METADATA_ORGANIZATION_URL = https://www.sourcemeta.com
export METADATA_ORGANIZATION_URL
METADATA_NAME = json-size-benchmark
export METADATA_NAME
METADATA_AUTHOR = Juan Cruz Viotti
export METADATA_AUTHOR
METADATA_AUTHOR_URL = https://www.jviotti.com
export METADATA_AUTHOR_URL
METADATA_EMAIL = [email protected]
export METADATA_EMAIL
METADATA_URL = https://benchmark.sourcemeta.com
export METADATA_URL
METADATA_GITHUB_URL = https://github.com/sourcemeta/json-size-benchmark
export METADATA_GITHUB_URL
#################################################
# GLOBALS
#################################################
# Make Python not write .pyc files for every executed Python script
PYTHONDONTWRITEBYTECODE = 1
export PYTHONDONTWRITEBYTECODE
#################################################
# PROGRAMS
#################################################
NODE ?= node
NPM ?= npm
PYTHON ?= python3
INSTALL ?= install
RMRF ?= rm -rf
MKDIR ?= mkdir
CUT ?= cut
PRINTF ?= printf
DOCKER ?= docker
PYTHON ?= python3
ESLINT ?= eslint
WEBPACK ?= webpack
JAVA ?= java
JQ ?= jq
GZIP ?= gzip
LZ4 ?= lz4
LZMA ?= lzma
CAPNP ?= capnp
THRIFT ?= thrift
FLATC ?= flatc
PROTOC ?= protoc
JSONBINPACK ?= jsonbinpack
#################################################
# VARIABLES
#################################################
CLASSPATH ?= /usr/share/java
OUTPUT ?= output
ALL_FORMATS = $(notdir $(wildcard formats/*))
FORMATS ?= $(ALL_FORMATS)
ALL_DOCUMENTS = $(notdir $(wildcard benchmark/*))
DOCUMENTS ?= $(ALL_DOCUMENTS)
ALL_COMPRESSORS = $(notdir $(wildcard compression/*))
COMPRESSORS ?= $(ALL_COMPRESSORS)
#################################################
# PHONY TARGETS
#################################################
lint: .eslintrc.json
$(ESLINT) --config $< scripts/**/*.js web/**/*.js
$(PYTHON) -m flake8 --max-line-length 150 scripts/*.py formats/**/*.py benchmark/*/*/*.py
clean:
exec $(RMRF) $(OUTPUT)
distclean: clean
exec $(RMRF) node_modules
html: $(OUTPUT)/index.html $(OUTPUT)/CNAME
docker: Dockerfile clean | $(OUTPUT)
$(DOCKER) build --progress plain --tag $(METADATA_ORGANIZATION)/$(METADATA_NAME) \
$(dir $(realpath $<))
$(DOCKER) run --volume $(shell pwd)/$(OUTPUT):/usr/src/app/output \
$(METADATA_ORGANIZATION)/$(METADATA_NAME)
#################################################
# PRELUDE
#################################################
# Create output directory structure
$(OUTPUT):
mkdir $@
define MAKE_DIRECTORY
$1/$2: | $1; exec $(MKDIR) $$@
endef
$(eval $(call MAKE_DIRECTORY,$(OUTPUT),documents))
$(eval $(call MAKE_DIRECTORY,$(OUTPUT),compressors))
$(foreach compressor,$(ALL_COMPRESSORS),$(eval $(call MAKE_DIRECTORY,$(OUTPUT)/compressors,$(compressor))))
$(foreach document,$(ALL_DOCUMENTS),$(eval $(call MAKE_DIRECTORY,$(OUTPUT)/documents,$(document))))
$(foreach document,$(ALL_DOCUMENTS),$(foreach format,$(ALL_FORMATS),$(eval $(call MAKE_DIRECTORY,$(OUTPUT)/documents/$(document),$(format)))))
# We programatically define these basic rule for every format as they are the
# base ones that requires two wildcards, which GNU Make doesn't support.
define COPY_TO_OUTPUT
$(OUTPUT)/documents/%/$1/$2: $3 | $(OUTPUT)/documents/%/$1
exec $(INSTALL) -m 0664 $$< $$@
endef
$(foreach format,$(ALL_FORMATS),$(eval $(call COPY_TO_OUTPUT,$(format),document.json,benchmark/%/document.json)))
$(foreach format,$(ALL_FORMATS),$(eval $(call COPY_TO_OUTPUT,$(format),NAME,formats/$(format)/NAME)))
#################################################
# BENCHMARK
#################################################
include compression/gz/targets.mk
include compression/lz4/targets.mk
include compression/lzma/targets.mk
include formats/protobuf/targets.mk
include formats/capnproto/targets.mk
include formats/capnproto-packed/targets.mk
include formats/flatbuffers/targets.mk
include formats/flexbuffers/targets.mk
include formats/messagepack/targets.mk
include formats/thrift/targets.mk
include formats/json/targets.mk
include formats/ubjson/targets.mk
include formats/cbor/targets.mk
include formats/bson/targets.mk
include formats/avro/targets.mk
include formats/smile/targets.mk
include formats/jsonbinpack/targets.mk
include formats/jsonbinpack-schemaless/targets.mk
$(OUTPUT)/documents/%/pre.patch.json: benchmark/%/pre.patch.json | $(OUTPUT)/documents/%
$(INSTALL) -m 0664 $< $@
$(OUTPUT)/documents/%/post.patch.json: benchmark/%/post.patch.json | $(OUTPUT)/documents/%
$(INSTALL) -m 0664 $< $@
# Provide default transformation JSON Patch documents
$(OUTPUT)/documents/%/pre.patch.json: | $(OUTPUT)/documents/%
exec echo "[]" > $@
$(OUTPUT)/documents/%/post.patch.json: | $(OUTPUT)/documents/%
exec echo "[]" > $@
$(OUTPUT)/documents/%/input.json: scripts/jsonpatch-apply.py \
$(OUTPUT)/documents/%/document.json $(OUTPUT)/documents/%/pre.patch.json \
| $(OUTPUT)/documents/%
exec $(PYTHON) $< $(word 2,$^) $(word 3,$^) > $@
$(OUTPUT)/documents/%/decode.json: scripts/jsonpatch-apply.py \
$(OUTPUT)/documents/%/output.json $(OUTPUT)/documents/%/post.patch.json \
| $(OUTPUT)/documents/%
exec $(PYTHON) $< $(word 2,$^) $(word 3,$^) > $@
$(OUTPUT)/documents/%/result.json: scripts/json-equals.py \
$(OUTPUT)/documents/%/decode.json $(OUTPUT)/documents/%/document.json \
| $(OUTPUT)/documents/%
$(PYTHON) $< $(word 2,$^) $(word 3,$^)
$(INSTALL) -m 0664 $(word 2,$^) $@
$(OUTPUT)/documents/%/TAXONOMY: vendor/json-taxonomy/js/cli.js benchmark/%/document.json | $(OUTPUT)/documents/%
exec $(NODE) $< $(word 2,$^) > $@
# This target ensures that the result is validated against the original input
$(OUTPUT)/documents/%/size.json: scripts/size.js \
$(OUTPUT)/documents/%/output.bin $(OUTPUT)/documents/%/NAME $(OUTPUT)/documents/%/VERSION \
$(foreach compressor,$(ALL_COMPRESSORS),$(addsuffix .$(compressor),$(OUTPUT)/documents/%/output.bin)) \
$(OUTPUT)/documents/%/result.json \
| $(OUTPUT)/documents/%
exec $(NODE) $< $(word 2,$^) "$(shell cat $(word 3,$^))" "$(shell cat $(word 4,$^))" $(COMPRESSORS) > $@
$(OUTPUT)/documents/%/data.json: scripts/data.js benchmark/%/NAME \
benchmark/%/SOURCE $(OUTPUT)/documents/%/TAXONOMY \
$(addsuffix /NAME,$(addprefix compression/,$(COMPRESSORS))) \
$(addsuffix /VERSION,$(addprefix output/compressors/,$(COMPRESSORS))) \
$(addsuffix /size.json,$(addprefix output/documents/%/,$(FORMATS))) \
| $(OUTPUT)/documents/%
exec $(NODE) $< "$(shell cat $(word 2,$^))" $(notdir $(realpath $(dir $(word 2,$^)))) \
"$(shell cat $(word 3,$^))" "$(shell cat $(word 4,$^))" \
$(addsuffix /size.json,$(addprefix $(dir $@),$(FORMATS))) > $@
$(OUTPUT)/documents/aggregate.json: scripts/concat.js \
$(addsuffix /data.json,$(addprefix output/documents/,$(DOCUMENTS))) \
| $(OUTPUT)/documents
exec $(NODE) $^ > $@
#################################################
# WEB
#################################################
$(OUTPUT)/app.min.js: web/app.js | $(OUTPUT)
exec $(WEBPACK) --mode=production $< -o $@
$(OUTPUT)/style.min.css: vendor/simplecss/simple.min.css | $(OUTPUT)
exec $(INSTALL) -m 0644 $< $@
$(OUTPUT)/index.html: scripts/template.js \
web/index.tpl.html $(OUTPUT)/documents/aggregate.json \
$(OUTPUT)/app.min.js $(OUTPUT)/style.min.css \
| $(OUTPUT)
exec $(NODE) $< $(word 2,$^) $(word 3,$^) > $@
$(OUTPUT)/CNAME: web/CNAME | $(OUTPUT)
exec $(INSTALL) -m 0644 $< $@