forked from RequestPolicyContinued/requestpolicy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
565 lines (424 loc) · 16.8 KB
/
Makefile
File metadata and controls
565 lines (424 loc) · 16.8 KB
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
# NOTE: in this file tab indentation is used.
# Otherwise .RECIPEPREFIX would have to be set.
# ==============================================================================
# create variables
# ==============================================================================
# _________________
# general variables
#
SHELL := /bin/bash
extension_name := requestpolicy
amo__extension_id := rpcontinued@requestpolicy.org
off_amo__extension_id := rpcontinued@non-amo.requestpolicy.org
# ____________________________________
# generating XPIs -- general variables
#
# The zip application to be used.
ZIP := zip
source_dirname := src
build_dirname := build
dist_dirname := dist
source_path := $(source_dirname)/
dist_path := $(dist_dirname)/
# _____________________________________________
# RequestPolicy XPI -- collect the files' paths
#
# files which are simply copied
src__copy_files := \
$(source_dirname)/chrome.manifest \
$(source_dirname)/install.rdf \
$(source_dirname)/README \
$(source_dirname)/LICENSE \
$(wildcard $(source_dirname)/content/settings/*.css) \
$(wildcard $(source_dirname)/content/settings/*.html) \
$(wildcard $(source_dirname)/content/*.html) \
$(wildcard $(source_dirname)/content/ui/*.xul) \
$(wildcard $(source_dirname)/locale/*/*.dtd) \
$(wildcard $(source_dirname)/locale/*/*.properties) \
$(wildcard $(source_dirname)/skin/*.css) \
$(wildcard $(source_dirname)/skin/*.png) \
$(wildcard $(source_dirname)/skin/*.svg) \
$(shell find $(source_dirname) -type f -iname "jquery*.js")
# JavaScript files which will be (pre)processed.
# The `copy_files` will be filtered out.
src__jspp_files := \
$(filter-out $(src__copy_files), \
$(shell find $(source_dirname) -type f -regex ".*\.jsm?") \
)
# all source files
src__all_files := $(src__copy_files) $(src__jspp_files)
# Create generic variables without path prefixs.
rp_all_files := $(patsubst $(source_path)%,%,$(src__all_files))
rp_jspp_files := $(patsubst $(source_path)%,%,$(src__jspp_files))
rp_copy_files := $(patsubst $(source_path)%,%,$(src__copy_files))
rp_deleted_files :=
rp_empty_dirs :=
# _____________________________________
# vars for generating the "off-AMO" XPI
#
off_amo__build_path := $(build_dirname)/off-amo/
off_amo__xpi_file := $(dist_path)$(extension_name).xpi
off_amo__all_files := $(addprefix $(off_amo__build_path),$(rp_all_files))
off_amo__jspp_files := $(addprefix $(off_amo__build_path),$(rp_jspp_files))
off_amo__copy_files := $(addprefix $(off_amo__build_path),$(rp_copy_files))
# detect deleted files and empty directories
off_amo__deleted_files :=
off_amo__empty_dirs :=
ifneq "$(wildcard $(off_amo__build_path))" ""
# files that have been deleted but still exist in the build directory.
off_amo__deleted_files := $(shell find $(off_amo__build_path) -type f | \
grep -v "META-INF" | \
grep -F -v $(addprefix -e ,$(off_amo__all_files)))
# empty directories. -mindepth 1 to exclude the build directory itself.
off_amo__empty_dirs := $(shell find $(off_amo__build_path) -mindepth 1 -type d -empty)
endif
rp_deleted_files += $(off_amo__deleted_files)
rp_empty_dirs += $(off_amo__empty_dirs)
# __________________________________________
# vars for generating a signed "off-AMO" XPI
#
signed_xpi_file := $(dist_path)$(extension_name)-signed.xpi
# _________________________________
# vars for generating the "AMO" XPI
#
amo__build_path := $(build_dirname)/amo/
amo__xpi_file := $(dist_path)$(extension_name)-amo.xpi
amo__all_files := $(addprefix $(amo__build_path),$(rp_all_files))
amo__jspp_files := $(addprefix $(amo__build_path),$(rp_jspp_files))
amo__copy_files := $(addprefix $(amo__build_path),$(rp_copy_files))
# detect deleted files and empty directories
amo__deleted_files :=
amo__empty_dirs :=
ifneq "$(wildcard $(amo__build_path))" ""
# files that have been deleted but still exist in the build directory.
amo__deleted_files := \
$(shell find $(amo__build_path) -type f | \
grep -v "META-INF" | \
grep -F -v $(addprefix -e ,$(amo__all_files)))
# empty directories. -mindepth 1 to exclude the build directory itself.
amo__empty_dirs := $(shell find $(amo__build_path) -mindepth 1 -type d -empty)
endif
rp_deleted_files += $(amo__deleted_files)
rp_empty_dirs += $(amo__empty_dirs)
# ________________________________________
# vars for generating the unit-testing XPI
#
unit_testing__build_path := $(build_dirname)/unit-testing/
unit_testing__xpi_file := $(dist_path)$(extension_name)-unit-testing.xpi
unit_testing__all_files := $(addprefix $(unit_testing__build_path),$(rp_all_files))
unit_testing__jspp_files := $(addprefix $(unit_testing__build_path),$(rp_jspp_files))
unit_testing__copy_files := $(addprefix $(unit_testing__build_path),$(rp_copy_files))
# detect deleted files and empty directories
unit_testing__deleted_files :=
unit_testing__empty_dirs :=
ifneq "$(wildcard $(unit_testing__build_path))" ""
# files that have been deleted but still exist in the build directory.
unit_testing__deleted_files := \
$(shell find $(unit_testing__build_path) -type f | \
grep -v "META-INF" | \
grep -F -v $(addprefix -e ,$(unit_testing__all_files)))
# empty directories. -mindepth 1 to exclude the build directory itself.
unit_testing__empty_dirs := $(shell find $(unit_testing__build_path) -mindepth 1 -type d -empty)
endif
rp_deleted_files += $(unit_testing__deleted_files)
rp_empty_dirs += $(unit_testing__empty_dirs)
# ______________________________________
# vars for generating the Dev Helper XPI
#
dev_helper__source_dirname := tests/helper-addons/dev-helper
dev_helper__source_path := $(dev_helper__source_dirname)/
dev_helper__src__all_files := $(shell find $(dev_helper__source_dirname) -type f -regex ".*\.jsm?") \
$(dev_helper__source_dirname)/chrome.manifest \
$(dev_helper__source_dirname)/install.rdf
dev_helper__xpi_file := $(dist_path)rpc-dev-helper.xpi
# _________________________________
# vars for generating the Dummy XPI
#
dummy_ext__source_dirname := tests/helper-addons/dummy-ext
dummy_ext__source_path := $(dummy_ext__source_dirname)/
dummy_ext__src__all_files := $(shell find $(dummy_ext__source_dirname) -type f -regex ".*\.jsm?") \
$(dummy_ext__source_dirname)/install.rdf
dummy_ext__xpi_file := $(dist_path)dummy-ext.xpi
# ______________________________
# vars for mozrunner and mozmill
#
# the default XPI to use for mozrunner and mozmill
moz_xpi := $(unit_testing__xpi_file)
# select the default app. Can be overridden e.g. via `make run app='seamonkey'`
app := firefox
# default app branch
ifeq ($(app),firefox)
app_branch := nightly
else
app_branch := release
endif
binary_filename := $(app)
app_binary := .mozilla/software/$(app)/$(app_branch)/$(binary_filename)
# __________________
# vars for mozrunner
#
mozrunner_prefs_ini := tests/mozrunner-prefs.ini
# ==============================================================================
# define targets
# ==============================================================================
.PHONY: all build dist sign
# set "all" to be the default target
.DEFAULT_GOAL := all
# building means to prepare all files in the build directory
build: $(off_amo__build_path)
# build and create XPI file
all: $(off_amo__xpi_file)
@echo "Build finished successfully."
dist xpi: $(off_amo__xpi_file)
# create the dist directory
$(dist_path):
@mkdir -p $(dist_path)
signed-xpi: $(signed_xpi_file)
# ________________________
# create the "off-AMO" XPI
#
# Note: Here the build path is added as a prerequisite, *not* the
# phony "build" target. This avoids re-packaging in case
# nothing has changed.
# Also $(off_amo__all_files) is needed as prerequisite, so that the
# xpi gets updated.
$(off_amo__xpi_file): $(off_amo__build_path) $(off_amo__all_files) | $(dist_path)
@rm -f $(off_amo__xpi_file)
@echo "Creating XPI file."
@cd $(off_amo__build_path) && \
$(ZIP) $(abspath $(off_amo__xpi_file)) $(rp_all_files)
@echo "Creating XPI file: Done!"
# _______________________________
# create the signed "off-AMO" XPI
#
$(signed_xpi_file): $(off_amo__build_path) $(off_amo__all_files) $(off_amo__build_path)/META-INF/ | $(dist_path)
@rm -f $(signed_xpi_file)
@cd $(off_amo__build_path) && \
$(ZIP) $(abspath $(signed_xpi_file)) \
META-INF/zigbert.rsa && \
$(ZIP) -r -D $(abspath $(signed_xpi_file)) \
$(rp_all_files) META-INF \
-x META-INF/zigbert.rsa
# ____________________
# create the "AMO" XPI
#
amo-xpi $(amo__xpi_file): $(amo__build_path) $(amo__all_files) | $(dist_path)
@rm -f $(amo__xpi_file)
@echo "Creating AMO XPI."
@cd $(amo__build_path) && \
$(ZIP) $(abspath $(amo__xpi_file)) $(rp_all_files)
@echo "Creating AMO XPI: Done!"
# ___________________________
# create the unit-testing XPI
#
unit-testing-xpi $(unit_testing__xpi_file): $(unit_testing__build_path) $(unit_testing__all_files) | $(dist_path)
@rm -f $(unit_testing__xpi_file)
@echo "Creating unit-testing XPI."
@cd $(unit_testing__build_path) && \
$(ZIP) $(abspath $(unit_testing__xpi_file)) $(rp_all_files)
@echo "Creating unit-testing XPI: Done!"
# _________________________
# create the Dev Helper XPI
#
# 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 other XPIs.
dev-helper-xpi $(dev_helper__xpi_file): $(dev_helper__src__all_files) FORCE | $(dist_path)
@rm -f $(dev_helper__xpi_file)
@echo "Creating 'RPC Dev Helper' XPI."
@cd $(dev_helper__source_dirname) && \
$(ZIP) $(abspath $(dev_helper__xpi_file)) $(patsubst $(dev_helper__source_path)%,%,$(dev_helper__src__all_files))
@echo "Creating 'RPC Dev Helper' XPI: Done!"
# ____________________
# create the Dummy XPI
#
# 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 other XPIs.
dummy-xpi $(dummy_ext__xpi_file): $(dummy_ext__src__all_files) FORCE | $(dist_path)
@rm -f $(dummy_ext__xpi_file)
@echo "Creating 'Dummy' XPI."
@cd $(dummy_ext__source_dirname) && \
$(ZIP) $(abspath $(dummy_ext__xpi_file)) $(patsubst $(dummy_ext__source_path)%,%,$(dummy_ext__src__all_files))
@echo "Creating 'Dummy' XPI: Done!"
# _________________________________________
# create the XPI from any tag or any commit
#
# Default tree-ish.
specific_xpi__treeish := v1.0.beta9.3
specific_xpi__file := $(dist_path)$(extension_name)-$(specific_xpi__treeish).xpi
specific_xpi__build_path := $(build_dirname)/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_path)
mkdir -p $(specific_xpi__build_path)
@# 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_path); tar x)
@# run `make` in the build directory
(cd $(specific_xpi__build_path); make)
@# move the created XPI from the build directory to the actual
@# dist directory
mv $(specific_xpi__build_path)/dist/*.xpi $(specific_xpi__file)
# ______________________________________
# create the files for the "off-AMO" XPI
#
# Process all source files, but also eventually delete
# empty directories and deleted files from the build directory.
$(off_amo__build_path): $(off_amo__all_files) $(off_amo__deleted_files) $(off_amo__empty_dirs)
# enable Secondary Expansion (so that $@ can be used in prerequisites via $$@)
.SECONDEXPANSION:
$(off_amo__jspp_files): $$(patsubst $$(off_amo__build_path)%,$$(source_path)%,$$@)
@mkdir -p $(@D)
preprocess $< > $@
$(off_amo__copy_files): $$(patsubst $$(off_amo__build_path)%,$$(source_path)%,$$@)
@mkdir -p $(@D)
@# Use `--dereference` to copy the files instead of the symlinks.
cp --dereference $< $@
# _____________________________________________
# create the files for the signed "off-AMO" XPI
#
$(off_amo__build_path)/META-INF/: $(off_amo__build_path) $(off_amo__all_files)
mkdir -p $(off_amo__build_path)/META-INF
signtool -d .signing \
-k "Open Source Developer, Martin Kimmerle's Unizeto Technologies S.A. ID" \
$(off_amo__build_path)
# __________________________________
# create the files for the "AMO" XPI
#
$(amo__build_path): $(amo__all_files) $(amo__deleted_files) $(amo__empty_dirs)
$(amo__jspp_files): $$(patsubst $$(amo__build_path)%,$$(source_path)%,$$@)
@mkdir -p $(@D)
preprocess $< -AMO=true > $@
$(amo__copy_files): $$(patsubst $$(amo__build_path)%,$$(source_path)%,$$@)
@mkdir -p $(@D)
cp --dereference $< $@
@if [[ "$(notdir $@)" == "install.rdf" ]]; then \
echo 'using `sed` on install.rdf !' ; \
sed -i s/$(off_amo__extension_id)/$(amo__extension_id)/ $@ ; \
fi
# _________________________________________
# create the files for the unit-testing XPI
#
$(unit_testing__build_path): $(unit_testing__all_files) $(unit_testing__deleted_files) $(unit_testing__empty_dirs)
$(unit_testing__jspp_files): $$(patsubst $$(unit_testing__build_path)%,$$(source_path)%,$$@)
@mkdir -p $(@D)
preprocess $< -UNIT_TESTING=true > $@
$(unit_testing__copy_files): $$(patsubst $$(unit_testing__build_path)%,$$(source_path)%,$$@)
@mkdir -p $(@D)
cp --dereference $< $@
.PHONY: unit-testing-files
unit-testing-files: $(unit_testing__all_files)
# __________________
# "cleaning" targets
#
# This cleans all temporary files and directories created by 'make'.
.PHONY: clean
clean:
@rm -rf $(dist_dirname)/*.xpi $(build_dirname)/*
@echo "Cleanup is done."
# remove empty directories
$(rp_empty_dirs): FORCE
rmdir $@
# delete deleted files that still exist in the build directory.
# this target should be forced
$(rp_deleted_files): FORCE
@# delete:
rm $@
@# delete parent dirs if empty:
@rmdir --parents --ignore-fail-on-non-empty $(@D)
# ____________________________
# virtual python environments
# for running and unit-testing
#
.PHONY: venv venv-mozmill
venv: .venv/bin/activate
.venv/bin/activate: requirements.txt
test -d .venv || virtualenv --prompt='(RP)' .venv
@# With the `touch` command, this target is only executed
@# when "requirements.txt" changes
( \
source .venv/bin/activate ; \
pip install -r requirements.txt ; \
touch --no-create .venv/bin/activate ; \
)
# mozmill needs a separate venv
# ( because it uses '==' package dependencies instead of '>='
# see https://github.com/mozilla/mozmill/blob/2.0.10/mozmill/setup.py#L11 )
venv-mozmill: .venv-mozmill/bin/activate
.venv-mozmill/bin/activate:
test -d .venv-mozmill || virtualenv --prompt='(RP/mozmill)' .venv-mozmill
( \
source .venv-mozmill/bin/activate ; \
pip install mozmill ; \
)
# ___________
# run firefox
#
# arguments for mozrunner
mozrunner_args := -a $(moz_xpi) -a $(dev_helper__xpi_file)
mozrunner_args += -b $(app_binary)
mozrunner_args += --preferences=$(mozrunner_prefs_ini):dev
mozrunner_args += $(moz_args)
.PHONY: run
run: venv $(moz_xpi) $(dev_helper__xpi_file)
( \
source .venv/bin/activate ; \
mozrunner $(mozrunner_args) ; \
)
# ____________
# unit testing
#
# Note: currently you have to do some setup before this will work.
# see https://github.com/RequestPolicyContinued/requestpolicy/wiki/Setting-up-a-development-environment#unit-tests-for-requestpolicy
mozmill_tests_dir := .mozilla/mozmill-tests
mozmill_rpc_test_dir := $(mozmill_tests_dir)/firefox/tests/addons/rpcontinued@requestpolicy.org
# Default mozmill manifest to use for testing
mm_manifest := manifest.ini
.PHONY: check test mozmill marionette mozmill-dirs
check test: mozmill marionette
mozmill: venv-mozmill $(moz_xpi) $(dev_helper__xpi_file) mozmill-dirs
( \
source .venv-mozmill/bin/activate ; \
mozmill -a $(moz_xpi) -a $(dev_helper__xpi_file) -b $(app_binary) \
-m $(mozmill_rpc_test_dir)/$(mm_manifest) $(moz_args) ; \
)
mozmill-dirs: $(mozmill_tests_dir) \
$(mozmill_rpc_test_dir) \
$(mozmill_rpc_test_dir)/mozmill-tests \
$(mozmill_rpc_test_dir)/data
$(mozmill_rpc_test_dir): $(mozmill_tests_dir)
@test -L $@ \
|| ln -ns ../../../../../tests/mozmill $@
$(mozmill_rpc_test_dir)/mozmill-tests: $(mozmill_rpc_test_dir)
@test -L tests/mozmill/mozmill-tests \
|| ln -ns ../../$(mozmill_tests_dir) tests/mozmill/mozmill-tests
$(mozmill_rpc_test_dir)/data: $(mozmill_rpc_test_dir)
@test -L tests/mozmill/data \
|| ln -ns ../../ tests/mozmill/data
marionette_tests := tests/marionette/rp_puppeteer/tests/manifest.ini
marionette_tests += tests/marionette/tests/manifest.ini
.PHONY: marionette
marionette: venv \
unit-testing-xpi \
dev-helper-xpi \
dummy-xpi \
specific-xpi \
amo-xpi
@# Due to Mozilla Bug 1173502, the profile needs to be created and
@# removed directly.
( \
source .venv/bin/activate ; \
export PYTHONPATH=tests/marionette/ ; \
profile_dir=`mozprofile -a $(unit_testing__xpi_file) -a $(dev_helper__xpi_file) --preferences=$(mozrunner_prefs_ini):marionette` ; \
firefox-ui-tests --binary=$(app_binary) --profile=$$profile_dir $(marionette_tests) ; \
rm -rf $$profile_dir ; \
)
# ________________
# "helper" targets
#
.PHONY: FORCE
FORCE: