This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.mk
532 lines (410 loc) · 15.2 KB
/
build.mk
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
-include local.mk
#
# Customizable variables. Set them in a local.mk file rather than
# modify this file. What follows are the default values.
#
# rst2html command.
RST2HTML?=rst2html
# jsdoc3 command
JSDOC3?=jsdoc
# wget command.
WGET?=wget
# Which saxon command to use. This must be a Saxon HE version that supports
# XSLT 3.
SAXON?=./utils/saxon
BEHAVE?=./selenium_test/btw-behave.py
# Which browser to use for selenium tests.
BROWSER?=
# Which service to use for selenium tests.
SERVICE?=browserstack
# Parameters to pass to behave
BEHAVE_PARAMS?=-D browser='$(BROWSER)' -D service=$(SERVICE)
# Whether to save the test results produced by behave.
#
# BEHAVE_SAVE?=
#
# *If not otherwise specified*, it is set to an empty string if the
# makefile is invoked in a "build system" like Buildbot or Jenkins. It
# is otherwise set to 1.
#
# The TEI hierarchy to use. This is the default location on
# Debian-type systems.
TEI?=/usr/share/xml/tei/stylesheet
# The schematron stylesheet. We rely on the TEI one since we already
# depend on TEI being present.
SCHEMATRON_TO_XSL?=/usr/share/xml/tei/odd/Utilities/iso_svrl_for_xslt2.xsl
PYTHON_PARAMS?=
PYTHON?=python
#
# End of customizable variables.
#
DJANGO_MANAGE:=$(PYTHON) $(PYTHON_PARAMS) ./manage.py
WGET:=$(WGET) --no-use-server-timestamps
BUILD_DIR:=build
WED_PATH:=node_modules/@wedxml/core
WED_BUILD:=build/wed-prod
WED_SASS_INC_PATH:=$(WED_BUILD)/lib/wed/sass-inc/
# Whether we are running in a builder like Jenkins or Buildbot.
# Normalized to the value 1 when true or empty string when false.
# JENKINS_HOME is set by Jenkins. Our buildbot setup must be
# configured to set BUILDBOT.
BUILD_ENV:=$(and $(or $(JENKINS_HOME),$(BUILDBOT)),1)
BEHAVE_SAVE?=$(if $(BUILD_ENV),,1)
# "direct" sources are those source that are directly built
# one-by-one. For instance, .js files that are copied, or .less files
# that are converted to .css. An example of source that is not
# "direct" is .ts files.
DIRECT_SOURCES:=$(shell find static-src -type f ! -name "*.ts")
BUILD_DEST:=$(BUILD_DIR)/static-build
BUILD_CONFIG:=$(BUILD_DIR)/config
LOCAL_SOURCES:=$(foreach f,$(DIRECT_SOURCES),$(patsubst %.scss,%.css,$(patsubst static-src/%,$(BUILD_DEST)/%,$f)))
# Local sources that need to be process by specialized recipes.
GENERATED_LOCAL_SOURCES:=$(filter %.css,$(LOCAL_SOURCES)) $(BUILD_DEST)/config/requirejs-config-dev.js
# Local sources that are merely copied.
COPIED_LOCAL_SOURCES:=$(filter-out $(GENERATED_LOCAL_SOURCES),$(LOCAL_SOURCES))
BUILD_SCRIPTS:=$(BUILD_DIR)/scripts/
BUILD_SERVICES:=$(BUILD_DIR)/services/
EXTERNAL:=$(BUILD_DEST)/lib/external
externalize=$(foreach f,$1,$(EXTERNAL)/$f)
# Function for automatically adding a map when the map is derived by
# adding .map to the name of the .js file.
and_map=$1 $1.map
# Function for automatically adding a map when the .js is replaced by .map.
map=$1 $(patsubst %.js,%.map,$1)
DATATABLES_PLUGIN_TARGETS:=$(call externalize, datatables/js/dataTables.bootstrap4.js datatables/css/dataTables.bootstrap4.css)
FINAL_SOURCES:=$(LOCAL_SOURCES) \
$(BUILD_DEST)/lib/requirejs/require.js\
$(BUILD_DEST)/lib/requirejs/text.js\
$(BUILD_DEST)/lib/requirejs/json.js\
$(call externalize, \
datatables\
jquery.growl/js/jquery.growl.js jquery.growl/css/jquery.growl.css\
bluebird.min.js\
bootstrap-datepicker\
moment.js\
velocity/velocity.min.js velocity/velocity.js\
velocity/velocity.ui.min.js velocity/velocity.ui.js\
last-resort.js\
bluejax.js bluejax.try.js\
lucene-query-parser.js\
bootstrap-treeview.min.js bootstrap-treeview.min.css\
$(call map,backbone-min.js) backbone.js\
$(call and_map,backbone.marionette.min.js) backbone.marionette.js\
backbone-forms/backbone-forms.js backbone-forms/bootstrap3.js backbone-forms/bootstrap3.css\
$(call and_map,underscore-min.js)\
backbone.paginator.js\
handlebars.js handlebars.min.js\
backbone-relational.js\
backbone.radio.js $(call and_map,backbone.radio.min.js)\
jquery.twbsPagination.js\
dragula.min.js dragula.min.css\
ResizeObserver.js\
js.cookie.js\
jquery.js\
bootstrap/js/bootstrap.js bootstrap/css/bootstrap.min.css\
popper.min.js\
lodash\
font-awesome/css/font-awesome.min.css\
font-awesome/fonts\
bootstrap-notify.js\
$(call and_map,salve.min.js)\
inversify\
$(call and_map,interact.min.js)\
bloodhound.min.js\
typeahead.jquery.min.js\
typeaheadjs.css\
log4javascript.js\
$(call and_map,ajv.min.js)\
merge-options.js\
is-plain-obj.js\
core-js.min.js)\
$(DATATABLES_PLUGIN_TARGETS)
DERIVED_SOURCES:=$(BUILD_DEST)/lib/btw/btw-storage.rng $(BUILD_DEST)/lib/btw/btw-storage-metadata.json $(BUILD_DEST)/lib/btw/btw-storage-doc
TEST_DATA_FILES:=$(foreach f,prepared_published_prasada.xml,build/test-data/$f)
.DELETE_ON_ERROR:
# We use this because make ignores patterns appearing as dependencies of a
# .PHONY target.
.PHONY: phony
phony:
TARGETS:= javascript typescript python-generation btw-schema-targets
.PHONY: all
all: _all
# We use --clear for two reasons: a) we want old crap to be removed
# and b) there are situations where the timestamps of files installed
# with NPM can trip us. Trying to fix it as part of the Makefile is
# onerous.
$(DJANGO_MANAGE) collectstatic --noinput --clear
include utils/schemas/include.mk
.PHONY: _all
_all: $(TARGETS) build-config build-scripts build-var
.PHONY: build-var
build-var:
mkdir -p var/run/btw
mkdir -p var/log/btw/wed
mkdir -p var/lib
.PHONY: python-generation
python-generation: build/python/semantic_fields/field.py
build/python/semantic_fields/field.py: semantic_fields/field.ebnf
-mkdir -p $(dir $@)
tatsu $< -o $@
.PHONY: javascript
javascript: $(WED_BUILD) $(FINAL_SOURCES) $(DERIVED_SOURCES)
.PHONY: typescript
typescript:
./node_modules/.bin/tsc -p static-src/lib/btw/tsconfig.json --outDir $(BUILD_DEST)/lib/btw/
$(BUILD_DIR)/wed-dev/entry.js: wed/entry.ts
./node_modules/.bin/tsc -p wed/tsconfig.json --outDir $(dir $@)
$(WED_BUILD): $(BUILD_DIR)/wed-dev/entry.js
./node_modules/.bin/wed-build wed/wed.config.js
rm -rf $(BUILD_DEST)/lib/wed*
-mkdir -p $(BUILD_DEST)/lib
cp -rp $(WED_BUILD)/lib/wed* $(BUILD_DEST)/lib
$(BUILD_DEST)/lib/btw/btw-storage.rng: utils/schemas/out/btw-storage-latest.rng
cp $< $@
$(BUILD_DEST)/lib/btw/btw-storage-metadata.json: utils/schemas/out/btw-storage-metadata-latest.json
cp $< $@
$(BUILD_DEST)/lib/btw/btw-storage-doc: utils/schemas/out/btw-storage-doc-latest
rm -rf $@
cp -rp $< $@
$(COPIED_LOCAL_SOURCES): $(BUILD_DEST)/%: static-src/%
-@[ -e $(dir $@) ] || mkdir -p $(dir $@)
cp $< $@
$(BUILD_DEST)/config/requirejs-config-dev.js: static-src/config/requirejs-config-dev.js
-@[ -e $(dir $@) ] || mkdir -p $(dir $@)
cp $< $@
btw-mode.css_CSS_DEPS=bibliography/static/stylesheets/bibsearch.scss $(WED_SASS_INC_PATH)/*.scss
btw-view.css_CSS_DEPS=static-src/lib/btw/btw-mode.scss node_modules/bootstrap/scss/_variables.scss
.SECONDEXPANSION:
$(filter %.css,$(LOCAL_SOURCES)): $(BUILD_DEST)/%.css: static-src/%.scss $$(wildcard $$($$(notdir $$@)_CSS_DEPS))
node_modules/.bin/node-sass --include-path=$(WED_SASS_INC_PATH) $< $@
APIDOC_EXCLUDE:=$(shell find $$PWD -name 'migrations' -type d)
.PHONY: python-doc
python-doc:
sphinx-apidoc -f -o doc/_apidoc . $(APIDOC_EXCLUDE)
(cd doc; make html)
.PHONY: doc
doc: python-doc build/doc README.html
build/doc: build $(filter %.js, $(SOURCES))
$(JSDOC3) -p -c jsdoc.conf.json -d build/doc -r static-src
README.html: README.rst
$(RST2HTML) $< $@
.PHONY: selenium-test
selenium-test: selenium_test
selenium_test/*.feature selenium_test: phony $(if $(BTW_SKIP_BUILD),,build-config $(TARGETS))
$(BEHAVE) $(BEHAVE_PARAMS) -D check_selenium_config=1 $@
$(if $(BTW_SKIP_BUILD),,$(MAKE) -f build.mk all)
ifneq ($(strip $(BEHAVE_SAVE)),)
(STAMP=$$(date -Iseconds); \
$(BEHAVE) $(BEHAVE_PARAMS) -f plain -o test_logs/$$STAMP.log -f pretty $@ ;\
ln -s -f $$STAMP.log test_logs/LATEST)
else
$(BEHAVE) $(BEHAVE_PARAMS) $@
endif # BEHAVE_SAVE
.PHONY: test
test: test-django test-karma
.PHONY: test-django
# The dependency on $(TARGETS) is needed because the tests depend on a
# complete application to run properly.
test-django: test-django-menu test-django-btwredis $(if $(BTW_SKIP_BUILD),,$(TARGETS))
$(DJANGO_MANAGE) test --ignore-files=test_btwredis.py --ignore-files=test_menus.py
.PHONY: test-django-menu
# The dependency on $(TARGETS) is needed because the tests depend on a
# complete application to run properly.
test-django-menu: $(if $(BTW_SKIP_BUILD),,$(TARGETS))
$(DJANGO_MANAGE) test ./core/tests/test_menus.py
.PHONY: test-django-btwredis
test-django-btwredis:
$(DJANGO_MANAGE) test ./btw_management/tests/test_btwredis.py
.PHONY: test-data
test-data: $(TEST_DATA_FILES)
build/test-data/prepared_published_prasada.xml: utils/schemas/prasada.xml
mkdir -p $(dir $@)
$(DJANGO_MANAGE) lexicography prepare-article $< $@ $(@:.xml=.json)
.PHONY: test-karma
test-karma: all test-data
./node_modules/.bin/karma start --single-run
.PHONY: keep-latest
keep-latest:
find test_logs -type f -not -name $$(realpath --relative-to=test_logs test_logs/LATEST) -delete
build-scripts:
mkdir -p $(BUILD_SCRIPTS) $(BUILD_SERVICES)
$(DJANGO_MANAGE) btw generate-scripts $(BUILD_SCRIPTS)
$(DJANGO_MANAGE) btw generate-systemd-services $(BUILD_SCRIPTS) $(BUILD_SERVICES)
build-config: $(BUILD_CONFIG)/nginx.conf | $(BUILD_CONFIG)
$(BUILD_CONFIG):
mkdir $@
$(BUILD_CONFIG)/nginx.conf: config/nginx.conf | $(BUILD_CONFIG)
sed -e's;@PWD@;$(PWD);'g $< > $@
$(EXTERNAL)/datatables: node_modules/datatables/media
-mkdir -p $(dir $@)
rm -rf $@
cp -rp node_modules/datatables/media $@
$(DATATABLES_PLUGIN_TARGETS): $(EXTERNAL)/datatables/%: node_modules/datatables.net-bs4/%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/core-js.min.js: node_modules/core-js/client/core.min.js
-mkdir -p $(dir $@)
cp $< $@
$(BUILD_DEST)/lib/requirejs/require.js: node_modules/requirejs/require.js
-mkdir -p $(dir $@)
cp $< $@
$(BUILD_DEST)/lib/requirejs/text.js: node_modules/requirejs-text/text.js
-mkdir -p $(dir $@)
cp $< $@
$(BUILD_DEST)/lib/requirejs/json.js: node_modules/requirejs-plugins/src/json.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/font-awesome/%: node_modules/font-awesome/%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/bootstrap-notify.js: node_modules/bootstrap-notify/bootstrap-notify.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/salve%: node_modules/salve/salve%
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/interact%: node_modules/interactjs/dist/interact%
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/merge-options.js: node_modules/merge-options/index.js
-mkdir -p $(dir $@)
echo "define(function (require, exports, module) {" > $@
cat $< >> $@
echo "});" >> $@
$(EXTERNAL)/is-plain-obj.js: node_modules/is-plain-obj/index.js
-mkdir -p $(dir $@)
echo "define(function (require, exports, module) {" > $@
cat $< >> $@
echo "});" >> $@
$(EXTERNAL)/bloodhound.min.js: node_modules/corejs-typeahead/dist/bloodhound.min.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/typeahead.jquery.min.js: node_modules/corejs-typeahead/dist/typeahead.jquery.min.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/typeaheadjs.css: node_modules/typeahead.js-bootstrap4-css/typeaheadjs.css
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/log4javascript.js: node_modules/log4javascript/log4javascript.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/ajv.%: node_modules/ajv/dist/ajv.%
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/inversify: node_modules/inversify/amd
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/js.cookie.js: node_modules/js-cookie/src/js.cookie.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/bluebird%: node_modules/bluebird/js/browser/bluebird%
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/bluejax.js: node_modules/bluejax/index.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/bluejax.try.js: node_modules/bluejax.try/index.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/last-resort.js: node_modules/last-resort/last-resort.js
-mkdir -p $(dir $@)
cp $< $@
$(EXTERNAL)/bootstrap-datepicker: node_modules/bootstrap-datepicker/dist
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/moment.js: node_modules/moment/moment.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/lucene-query-parser.js: node_modules/lucene-query-parser/lib/lucene-query-parser.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/velocity/%: node_modules/velocity-animate/%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/jquery.growl/css/jquery.growl.css: node_modules/jquery.growl/stylesheets/jquery.growl.css
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/jquery.growl/js/jquery.growl.js: node_modules/jquery.growl/javascripts/jquery.growl.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/jquery.js: node_modules/jquery/dist/jquery.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/bootstrap/js/bootstrap.js: node_modules/bootstrap/dist/js/bootstrap.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/popper.min.js: node_modules/popper.js/dist/umd/popper.min.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/bootstrap/css/bootstrap.min.css: node_modules/bootstrap/dist/css/bootstrap.min.css
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/bootstrap-treeview.%: node_modules/patternfly-bootstrap-treeview/dist/bootstrap-treeview.%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/backbone%: node_modules/backbone/backbone%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/lodash: node_modules/lodash
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/backbone.marionette.%: node_modules/backbone.marionette/lib/backbone.marionette.%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/backbone.paginator.%: node_modules/backbone.paginator/lib/backbone.paginator.%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/backbone-relational%: node_modules/backbone-relational/backbone-relational%
-mkdir -p $(dir $@)
cp -rp $< $@
# backbone.radio may be installed in different locations.
BACKBONE_RADIO:=$(or $(wildcard node_modules/backbone.radio),$(wildcard node_modules/backbone.marionette/node_modules/backbone.radio))
$(EXTERNAL)/backbone.radio%: $(BACKBONE_RADIO)/build/backbone.radio%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/backbone-forms/backbone-forms.js: node_modules/backbone-forms/distribution.amd/backbone-forms.js
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/backbone-forms/bootstrap3.%: node_modules/backbone-forms/distribution.amd/templates/bootstrap3.%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/underscore%: node_modules/underscore/underscore%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/handlebars%: node_modules/handlebars/dist/handlebars%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/jquery.twbsPagination%: node_modules/twbs-pagination/jquery.twbsPagination%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/dragula%: node_modules/dragula/dist/dragula%
-mkdir -p $(dir $@)
cp -rp $< $@
$(EXTERNAL)/ResizeObserver%: node_modules/resize-observer-polyfill/dist/ResizeObserver%
-mkdir -p $(dir $@)
cp -rp $< $@
.PHONY: eslint
eslint:
./node_modules/.bin/eslint *.js '{karma_tests,bibliography,lexicography,semantic_fields,wed,core,static-src}/**/*.js'
.PHONY: tslint
tslint:
./node_modules/.bin/tslint -p static-src/lib/btw/tsconfig.json
.PHONY: lint
lint: tslint eslint
.PHONY: venv
venv:
[ -e .btw-venv ] || python3 -m venv .btw-venv
.PHONY: dev-venv
dev-venv: venv
.btw-venv/bin/pip install -r frozen-requirements.txt
.PHONY: shrinkwrap
shrinkwrap:
npm prune
npm shrinkwrap
.PHONY: freeze
freeze:
tasks/freeze
.PHONY: clean
clean::
-rm -rf build
-rm -rf sitestatic