-
Notifications
You must be signed in to change notification settings - Fork 35
/
Makefile
603 lines (485 loc) · 20 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
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# NOTE: in this file tab indentation is used.
# Otherwise .RECIPEPREFIX would have to be set.
# http://clarkgrubb.com/makefile-style-guide
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
#===============================================================================
# GNU make HACKS
#===============================================================================
_SPACE :=
_SPACE +=
ifndef MAKECMDGOALS
MAKECMDGOALS :=
endif
_make_invocation_cmd := $(wordlist 2,100000,$(shell ps -o cmd fp $$PPID))
_make_invocation_program := $(firstword $(_make_invocation_cmd))
#===============================================================================
# general variables and targets
#===============================================================================
#-------------------------------------------------------------------------------
# extension metadata
#-------------------------------------------------------------------------------
extension_name := requestpolicy
#-------------------------------------------------------------------------------
# running, UI testing
#-------------------------------------------------------------------------------
# select the default app. Can be overridden e.g. via `make run app='seamonkey'`
app := firefox
app_branch := default-rp-dev
binary_filename := $(app)
app_binary = dev_env/browsers/$(app)/$(app_branch)/$(binary_filename)
mozrunner_prefs_ini := tests/mozrunner-prefs.ini
#-------------------------------------------------------------------------------
# directories
#-------------------------------------------------------------------------------
source_dir := src
build_dir_root := build
dist_dir := dist
logs_dir := logs
dev_env_dir := dev_env
python_env_dir := $(dev_env_dir)/python
browsers_dir := $(dev_env_dir)/browsers
stamps_dir := $(dev_env_dir)/.stamps
varstamps_dir := $(stamps_dir)/vars
node_modules_dir := ./node_modules
# create the dist directory
$(dist_dir) $(logs_dir):
@mkdir -p $@
#-------------------------------------------------------------------------------
# programs and scripts
#-------------------------------------------------------------------------------
# system
GIT := /usr/bin/git
NPM := npm
ZIP := zip
PYTHON := $(python_env_dir)/bin/python
# nodejs
ADDONS_LINTER := $(abspath $(node_modules_dir))/.bin/addons-linter
COFFEELINT := $(abspath $(node_modules_dir))/.bin/coffeelint
ESLINT := $(abspath $(node_modules_dir))/.bin/eslint --ext .js,.jsm
GULP := $(abspath $(node_modules_dir))/.bin/gulp
MOCHA := $(abspath $(node_modules_dir))/.bin/mocha
TSC := $(abspath $(node_modules_dir))/.bin/tsc
TSLINT := $(abspath $(node_modules_dir))/.bin/tslint
# python
PY_PYCODESTYLE := $(abspath $(python_env_dir))/bin/pycodestyle
PY_MOZPROFILE := $(abspath $(python_env_dir))/bin/mozprofile
PY_MOZRUNNER := $(abspath $(python_env_dir))/bin/mozrunner
#-------------------------------------------------------------------------------
# helper targets
#-------------------------------------------------------------------------------
# Can force a target to be executed every time.
.PHONY: FORCE
FORCE:
# $1: variable name
_VAR_STAMP_ = $(shell \
mkdir -p $(varstamps_dir); \
./scripts/update_stamp.sh "$(varstamps_dir)/$1" "$($1)"; \
echo "$(varstamps_dir)/$1" \
)
#-------------------------------------------------------------------------------
# helpers
#-------------------------------------------------------------------------------
# in a pipe
_remove_leading_empty_lines := sed '/./,$$!d'
# $1: command(s) to be wrapped
_remove_all_files_and_dirs_in = find '$1/' '!' -path '$1/' -delete
#-------------------------------------------------------------------------------
# error and warning messages
#-------------------------------------------------------------------------------
_warning_offline = [$1] WARNING: in offline mode, make targets may fail \
due to missing software packages.
#===============================================================================
# Building RequestPolicy
#===============================================================================
#-------------------------------------------------------------------------------
# Meta-Targets
#-------------------------------------------------------------------------------
define make_xpi
$(GULP) xpi:$(1)
endef
define make_files
$(GULP) build:$(1)
endef
.PHONY: all \
xpi nightly-xpi beta-xpi ui-testing-xpi amo-beta-xpi amo-nightly-xpi \
nightly-files
all: xpi
xpi: nightly-xpi
nightly-xpi: node-packages
$(call make_xpi,nightly)
dev-xpi: node-packages
$(call make_xpi,dev)
beta-xpi: node-packages
$(call make_xpi,beta)
ui-testing-xpi: node-packages
$(call make_xpi,ui-testing)
amo-beta-xpi: node-packages
$(call make_xpi,amo-beta)
amo-nightly-xpi: node-packages
$(call make_xpi,amo-nightly)
nightly-files: node-packages
$(call make_files,nightly)
xpi_file__nightly := $(dist_dir)/$(extension_name)-legacy-nightly.xpi
xpi_file__dev := $(dist_dir)/$(extension_name)-legacy-dev.xpi
xpi_file__beta := $(dist_dir)/$(extension_name)-legacy-beta.xpi
xpi_file__amo_beta := $(dist_dir)/$(extension_name)-legacy-amo-beta.xpi
xpi_file__amo_nightly := $(dist_dir)/$(extension_name)-legacy-amo-nightly.xpi
xpi_file__ui_testing := $(dist_dir)/$(extension_name)-legacy-ui-testing.xpi
#===============================================================================
# Create a XPI from any git-tag or git-commit
#===============================================================================
# Default tree-ish.
specific_xpi__treeish := v1.0.beta9.3__preprocess.py
specific_xpi__file := $(dist_dir)/$(extension_name)-$(specific_xpi__treeish).xpi
specific_xpi__build_dir := $(build_dir_root)/specific-xpi
# create the XPI only if it doesn't exist yet
.PHONY: specific-xpi
specific-xpi: $(specific_xpi__file)
$(specific_xpi__file):
@# remove the build directory (if it exists) and recreate it
rm -rf $(specific_xpi__build_dir)
mkdir -p $(specific_xpi__build_dir)
@# copy the content of the tree-ish to the build dir
@# see https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export/9416271#9416271
git archive $(specific_xpi__treeish) | (cd $(specific_xpi__build_dir); tar x)
@# run `make` in the build directory
(cd $(specific_xpi__build_dir); make)
@# move the created XPI from the build directory to the actual
@# dist directory
mv $(specific_xpi__build_dir)/dist/*.xpi $(specific_xpi__file)
#===============================================================================
# Other XPIs (simple XPIs)
#===============================================================================
#-------------------------------------------------------------------------------
# Meta-Targets
#-------------------------------------------------------------------------------
define make_other_xpi
@$(MAKE) --no-print-directory _other_xpi OTHER_BUILD=$(1)
endef
.PHONY: _other_xpi \
dev-helper-xpi ui-testing-helper-xpi dummy-xpi webext-apply-css-xpi
dev-helper-xpi:
$(call make_other_xpi,dev_helper)
ui-testing-helper-xpi:
$(call make_other_xpi,ui_testing_helper)
dummy-xpi:
$(call make_other_xpi,dummy)
webext-apply-css-xpi:
$(call make_other_xpi,we_apply_css)
#-------------------------------------------------------------------------------
# [VARIABLES] configuration of different builds
#-------------------------------------------------------------------------------
alias__dev_helper := RPC Dev Helper
alias__ui_testing_helper := RPC UI Testing Helper
alias__dummy := Dummy
alias__we_apply_css := Dummy WebExtension
source_path__dev_helper := tests/helper-addons/dev-helper/
source_path__ui_testing_helper := tests/helper-addons/ui-testing-helper/
source_path__dummy := tests/helper-addons/dummy-ext/
source_path__we_apply_css := tests/helper-addons/external/webext-apply-css/
xpi_file__dev_helper := $(dist_dir)/rpc-dev-helper.xpi
xpi_file__ui_testing_helper := $(dist_dir)/rpc-ui-testing-helper.xpi
xpi_file__dummy := $(dist_dir)/dummy-ext.xpi
xpi_file__we_apply_css := $(dist_dir)/webext-apply-css.xpi
#-------------------------------------------------------------------------------
# intermediate targets
#-------------------------------------------------------------------------------
ifdef OTHER_BUILD
other_build__alias := $(alias__$(OTHER_BUILD))
other_build__source_path := $(source_path__$(OTHER_BUILD))
other_build__xpi_file := $(xpi_file__$(OTHER_BUILD))
endif
#-------------------------------------------------------------------------------
# [VARIABLES] collect source files
#-------------------------------------------------------------------------------
ifdef OTHER_BUILD
other_build__src__all_files := $(shell find $(other_build__source_path) -type f)
endif
#-------------------------------------------------------------------------------
# TARGETS
#-------------------------------------------------------------------------------
ifdef OTHER_BUILD
_other_xpi: $(other_build__xpi_file)
# For now use FORCE, i.e. create the XPI every time. If the
# 'FORCE' should be removed, deleted files have to be detected,
# just like for the RequestPolicy XPIs.
$(other_build__xpi_file): $(other_build__src__all_files) FORCE | $(dist_dir)
@rm -f $(other_build__xpi_file)
@echo "Creating \"$(other_build__alias)\" XPI."
@cd $(other_build__source_path) && \
$(ZIP) $(abspath $(other_build__xpi_file)) $(patsubst $(other_build__source_path)%,%,$(other_build__src__all_files))
@echo "Creating \"$(other_build__alias)\" XPI: Done!"
endif
#===============================================================================
# Development environment
#===============================================================================
.PHONY: development-environment
development-environment: python-venv node-packages firefox-all
#-------------------------------------------------------------------------------
# timestamps for remakes every x hours/days
#-------------------------------------------------------------------------------
fn_timestamp_file = $(stamps_dir)/.timestamp_$(subst $(_SPACE),_,$1)_ago
force_every = $(shell \
mkdir -p $(dir $(call fn_timestamp_file,$1)); \
touch -d '$1 ago' $(call fn_timestamp_file,$1); \
echo $(call fn_timestamp_file,$1) \
)
#-------------------------------------------------------------------------------
# python
#-------------------------------------------------------------------------------
# timestamp/target files
# NOTE: The timestamp files must reside inside the venv dir,
# so that when the venv dir is removed, the timestamp files
# will be removed as well.
T_PYTHON_PACKAGES := $(python_env_dir)/.timestamp_requirements
T_PYTHON_VIRTUALENV := $(python_env_dir)/.timestamp_virtualenv
# increment the value when changing the target
__python_venv__ := v1
.PHONY: python-venv python-packages
python-venv python-packages: $(T_PYTHON_PACKAGES)
$(T_PYTHON_PACKAGES): $(dev_env_dir)/python-requirements.txt \
$(call force_every,7 days) \
$(T_PYTHON_VIRTUALENV)
ifndef OFFLINE
$(PYTHON) -m pip install --upgrade -r $<
touch $@
endif
ifdef OFFLINE
@echo '$(call _warning_offline,python)'
endif
$(T_PYTHON_VIRTUALENV): \
$(call _VAR_STAMP_,__python_venv__) \
$(call _VAR_STAMP_,CURDIR) \
$(call _VAR_STAMP_,python_env_dir)
rm -rf $(python_env_dir)
mkdir -p $(python_env_dir)
virtualenv --no-site-packages --prompt='(RP)' $(python_env_dir)
@echo $(CURDIR)/tests/python \
> $(python_env_dir)/lib/python2.7/site-packages/requestpolicy.pth
touch $@
#-------------------------------------------------------------------------------
# node.js
#-------------------------------------------------------------------------------
# timestamp/target files
T_NODE_PACKAGES := $(node_modules_dir)/.timestamp_packages
.PHONY: node-packages
node-packages: $(T_NODE_PACKAGES)
$(T_NODE_PACKAGES): package.json package-lock.json \
$(call force_every,7 days)
ifndef OFFLINE
$(NPM) install
touch $@
endif
ifdef OFFLINE
@echo '$(call _warning_offline,npm)'
endif
#===============================================================================
# Running a Browser + RequestPolicy
#===============================================================================
# arguments for mozrunner
run_additional_xpis :=
_run_xpis := $(xpi_file__dev) $(xpi_file__dev_helper) $(run_additional_xpis)
run_additional_prefs := default
_run_prefs := common run $(run_additional_prefs)
run_additional_args :=
_run_mozrunner_args := \
$(addprefix --addon=,$(_run_xpis)) \
--binary=$(app_binary) \
$(addprefix --preferences=$(mozrunner_prefs_ini):,$(_run_prefs)) \
$(run_additional_args)
.PHONY: run
run: python-venv dev-xpi dev-helper-xpi
$(PY_MOZRUNNER) $(_run_mozrunner_args)
_dev_profile_dir := .temp/dev_profile
dev_profile_additional_args :=
_dev_profile_mozprofile_args := \
--profile=$(_dev_profile_dir) \
$(addprefix --addon=,$(_run_xpis)) \
$(addprefix --preferences=$(mozrunner_prefs_ini):,$(_run_prefs)) \
$(dev_profile_additional_args)
.PHONY: temp-dev-profile
temp-dev-profile: python-venv dev-xpi dev-helper-xpi
@rm -rf $(_dev_profile_dir)
@mkdir -p $(_dev_profile_dir)
$(PY_MOZPROFILE) $(_dev_profile_mozprofile_args)
#===============================================================================
# Testing
#===============================================================================
_ui_subtests := ui-tests-quick ui-tests-non-quick
_quick_tests := static-analysis non-ui-tests ui-tests-quick
_non_quick_tests := test-makefile ui-tests-non-quick
.PHONY: test-quick test
test-quick: $(_quick_tests)
test-quick-non-ui: $(filter-out ui-tests-quick,$(_quick_tests))
test-non-quick: $(_non_quick_tests)
test: $(filter-out $(_ui_subtests),$(_quick_tests) $(_non_quick_tests)) ui-tests
#-------------------------------------------------------------------------------
# Testing: non-UI tests
#-------------------------------------------------------------------------------
.PHONY: non-ui-tests
non-ui-tests: mocha-tests
_non_ui_subtests := unit-tests integration-tests
.PHONY: $(_non_ui_subtests)
unit-tests: mocha-unit-tests
integration-tests: mocha-integration-tests
_mocha_test_targets = mocha-tests mocha-unit-tests mocha-integration-tests
.PHONY: $(_mocha_test_targets)
mocha-tests: ALIASES := unit legacy-integration
mocha-unit-tests: ALIASES := unit
mocha-integration-tests: ALIASES := legacy-integration
$(_mocha_test_targets): node-packages
NODE_PATH=$${NODE_PATH+$$NODE_PATH:}src/content/:src/conditional/legacy/content/:src/conditional/legacy/webextension/ \
$(MOCHA) \
--exit \
--recursive \
--require coffeescript/register \
--require source-map-support/register \
--require ts-node/register \
tests/mocha/lib/helper.* \
$(patsubst %,tests/mocha/%/*,$(ALIASES)) \
$(patsubst %,tests/mocha/%/**/*,$(ALIASES))
#-------------------------------------------------------------------------------
# UI tests
#-------------------------------------------------------------------------------
# Note: currently you have to do some setup before this will work.
# see https://github.com/RequestPolicyContinued/requestpolicy/wiki/Setting-up-a-development-environment#marionette-ui-tests
.PHONY: ui-tests ui-tests-quick ui-tests-non-quick
ui-tests: marionette
ui-tests-quick: marionette-quick
ui-tests-non-quick: marionette-non-quick
_marionette_targets := marionette marionette-quick marionette-non-quick
.PHONY: $(_marionette_targets)
marionette: _args :=
marionette-quick: _args := --quick
marionette-non-quick: _args := --non-quick
$(_marionette_targets): _marionette_dependencies
./scripts/run_marionette_tests.py --no-make-dependencies $(_args)
.PHONY: _marionette_dependencies
_marionette_dependencies: \
python-venv $(logs_dir) \
ui-testing-xpi \
amo-nightly-xpi specific-xpi \
dev-helper-xpi ui-testing-helper-xpi \
dummy-xpi webext-apply-css-xpi
#===============================================================================
# static analysis
#===============================================================================
.PHONY: static-analysis
static-analysis: lint check-locales
#-------------------------------------------------------------------------------
# linting
#-------------------------------------------------------------------------------
.PHONY: lint
lint: lint-anytype lint-coffee lint-js lint-python lint-ts lint-xpi
.PHONY: lint-coffee lint-js lint-python lint-ts lint-xpi
lint-anytype: bad-words-linter
lint-coffee: coffeelint
lint-js: eslint
lint-python: pycodestyle
lint-ts: ts tslint
lint-xpi: addons-linter
.PHONY: addons-linter coffeelint eslint pycodestyle ts tslint
addons-linter: nightly-xpi node-packages
@echo $@
@$(ADDONS_LINTER) $(xpi_file__nightly)
coffeelint: node-packages
@echo $@
@$(COFFEELINT) $(shell find tests/mocha/ -name '*.coffee')
eslint: node-packages
@echo $@
@$(ESLINT) src/
@$(ESLINT) tests/mocha/
@$(ESLINT) tests/xpcshell/
@$(ESLINT) tests/helper-addons/
@$(ESLINT) gulpfile.js
pycodestyle: python-packages
@echo $@
@$(PY_PYCODESTYLE) scripts/
@$(PY_PYCODESTYLE) tests/marionette/
ts: node-packages
@echo $@
@$(TSC) --noEmit
@$(TSC) --noEmit -p src/conditional/legacy/webextension/tsconfig.json
@#$(TSC) --noEmit -p tests/mocha
@#$(TSC) --noEmit -p tests/xpcshell # failing
tslint: node-packages
@echo $@
@$(TSLINT) --project tsconfig.json \
--exclude '**/third-party/**/*' \
--exclude '**/*.d.ts' \
--exclude 'src/conditional/legacy/webextension/**/*' \
'src/**/*.ts' \
| $(_remove_leading_empty_lines)
@$(TSLINT) --project src/conditional/legacy/webextension/tsconfig.json \
--exclude '**/third-party/**/*' \
'src/conditional/legacy/webextension/**/*.ts' \
| $(_remove_leading_empty_lines)
bad-words-linter:
@echo $@
@./scripts/lint-bad-words src/
#-------------------------------------------------------------------------------
# localization checks
#-------------------------------------------------------------------------------
.PHONY: check-locales
check-locales: check-we-locales check-legacy-locales
.PHONY: check-we-locales
check-we-locales: python-packages
@echo $@
@./tests/l10n/check-we-locales.py
include tests/l10n/Makefile
#-------------------------------------------------------------------------------
# Makefile tests
#-------------------------------------------------------------------------------
.PHONY: test-makefile
test-makefile:
./scripts/run_makefile_tests
#===============================================================================
# clean targets
#===============================================================================
_clean_targets := clean mostlyclean distclean clean-dev-environment
# ---
# check if ".NOTPARALLEL" is necessary (in case a clean target is part of the goals),
# and perhaps warn the user (in case other, non-clean targets are part of the goals).
# ---
_clean_makecmdgoals := $(filter $(_clean_targets),$(MAKECMDGOALS))
_nonclean_makecmdgoals = $(filter-out $(_clean_targets),$(MAKECMDGOALS))
# NOTE: do not put spaces in the following variable:
_jobs_in_cmdline = \
$(findstring $(space)-j,$(_make_invocation_cmd))\
$(findstring $(space)--jobs,$(_make_invocation_cmd))
define _jobs_warning
WARNING:
executing NON-parallel! To execute in parallel AND execute clean targets, run
"$(_make_invocation_program) $(_clean_makecmdgoals) && $(filter-out $(_clean_targets),$(_make_invocation_cmd))"
endef
ifneq '' '$(_clean_makecmdgoals)'
.NOTPARALLEL:
ifneq '' '$(_nonclean_makecmdgoals)'
ifneq '' '$(_jobs_in_cmdline)'
$(info $(_jobs_warning))
endif
endif
endif
# ---
# actual targets
# ---
.PHONY: $(_clean_targets)
clean:
@rm -rf $(dist_dir)/*.xpi
@-$(call _remove_all_files_and_dirs_in,$(build_dir_root))
mostlyclean: clean
@-$(call _remove_all_files_and_dirs_in,$(logs_dir))
clean-dev-environment:
@-$(call _remove_all_files_and_dirs_in,$(python_env_dir))
@-$(call _remove_all_files_and_dirs_in,$(node_modules_dir))
@-$(call _remove_all_files_and_dirs_in,$(stamps_dir))
@rm -rf $(browsers_dir)/firefox
@# Do not remove the seamonkey "downloads" dir. Seamonkey tarballs
@# are put there manually.
@rm -rf $(browsers_dir)/seamonkey/extracted
distclean: mostlyclean clean-dev-environment