forked from mozilla-b2g/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
339 lines (286 loc) · 13.7 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
###############################################################################
# Global configurations #
# #
# GAIA_DOMAIN : change that if you plan to use a different domain to update #
# your applications or want to use a local domain #
# #
# ADB : if you use a device and plan to send update it with your work #
# you need to have adb in your path or you can edit this line to#
# specify its location. #
# #
# DEBUG : debug mode enables mode output on the console and disable the #
# the offline cache. This is mostly for desktop debugging. #
# #
# REPORTER : Mocha reporter to use for test output. #
# #
###############################################################################
GAIA_DOMAIN?=gaiamobile.org
ADB?=adb
DEBUG?=0
REPORTER=Spec
###############################################################################
# The above rules generate the profile/ folder and all its content. #
# The profile folder content depends on different rules: #
# 1. manifests #
# A directory structure representing the applications installed using the #
# Apps API. In Gaia all applications use this method. #
# See https://developer.mozilla.org/en/Apps/Apps_JavaScript_API #
# #
# 2. offline #
# An Application Cache database containing Gaia apps, so the phone can be #
# used offline and application can be updated easily. For details about it#
# see: https://developer.mozilla.org/en/Using_Application_Cache #
# #
# 3. preferences #
# A preference file used by the platform to configure permissions #
# #
###############################################################################
# In debug mode the offline cache is not used (even if it is generated) and
# Gaia is loaded by a built-in web server via port GAIA_PORT.
#
# XXX For now the name of the domain should be mapped to localhost manually
# by editing /etc/hosts on linux/mac. This steps would not be required
# anymore once https://bugzilla.mozilla.org/show_bug.cgi?id=722197 will land.
ifeq ($(DEBUG),1)
GAIA_PORT?=:8080
else
GAIA_PORT?=
endif
# what OS are we on?
SYS=$(shell uname -s)
ARCH=$(shell uname -m)
ifeq ($(SYS),Darwin)
MD5SUM = md5 -r
SED_INPLACE_NO_SUFFIX = sed -i ''
DOWNLOAD_CMD = curl -s -O
else
MD5SUM = md5sum -b
SED_INPLACE_NO_SUFFIX = sed -i
DOWNLOAD_CMD = wget
endif
# Test agent setup
TEST_AGENT_DIR=tools/test-agent/
ifeq ($(strip $(NODEJS)),)
NODEJS := `which node`
endif
ifeq ($(strip $(NPM)),)
NPM := `which npm`
endif
#Marionette testing variables
#make sure we're python 2.7.x
ifeq ($(strip $(PYTHON_27)),)
PYTHON_27 := `which python`
endif
PYTHON_FULL := $(wordlist 2,4,$(subst ., ,$(shell $(PYTHON_27) --version 2>&1)))
PYTHON_MAJOR := $(word 1,$(PYTHON_FULL))
PYTHON_MINOR := $(word 2,$(PYTHON_FULL))
MARIONETTE_HOST ?= localhost
MARIONETTE_PORT ?= 2828
TEST_DIRS ?= $(CURDIR)/tests
# Generate profile/
profile: stamp-commit-hash update-offline-manifests preferences manifests offline extensions
@echo "\nProfile Ready: please run [b2g|firefox] -profile $(CURDIR)/profile"
LANG=POSIX # Avoiding sort order differences between OSes
# Generate profile/webapps/
manifests:
@echo "Generated webapps"
@mkdir -p profile/webapps
@echo { > profile/webapps/webapps.json
@cd apps; \
for d in `find * -maxdepth 0 -type d` ;\
do \
if [ -f $$d/manifest.json ]; \
then \
mkdir -p ../profile/webapps/$$d; \
cp $$d/manifest.json ../profile/webapps/$$d ;\
(\
echo \"$$d\": { ;\
echo \"origin\": \"http://$$d.$(GAIA_DOMAIN)$(GAIA_PORT)\", ;\
echo \"installOrigin\": \"http://$$d.$(GAIA_DOMAIN)$(GAIA_PORT)\", ;\
echo \"receipt\": null, ;\
echo \"installTime\": 132333986000, ;\
echo \"manifestURL\": \"http://$$d.$(GAIA_DOMAIN)$(GAIA_PORT)/manifest.json\" ;\
echo },) >> ../profile/webapps/webapps.json;\
fi \
done
@$(SED_INPLACE_NO_SUFFIX) -e '$$s|,||' profile/webapps/webapps.json
@echo } >> profile/webapps/webapps.json
@cat profile/webapps/webapps.json
@echo "Done"
# Generate profile/OfflineCache/
offline: install-xulrunner
ifneq ($(DEBUG),1)
@echo "Building offline cache"
@rm -rf profile/OfflineCache
@mkdir -p profile/OfflineCache
@cd ..
$(XULRUNNER) $(XPCSHELL) -e 'const GAIA_DIR = "$(CURDIR)"; const PROFILE_DIR = "$(CURDIR)/profile"; const GAIA_DOMAIN = "$(GAIA_DOMAIN)$(GAIA_PORT)"' build/offline-cache.js
@echo "Done"
endif
# The install-xulrunner target arranges to get xulrunner downloaded and sets up
# some commands for invoking it. But it is platform dependent
ifeq ($(SYS),Darwin)
# We're on a mac
XULRUNNER_DOWNLOAD=ftp://ftp.mozilla.org/pub/xulrunner/nightly/2012/05/2012-05-08-03-05-17-mozilla-central/xulrunner-15.0a1.en-US.mac-x86_64.sdk.tar.bz2
XULRUNNER=./xulrunner-sdk/bin/run-mozilla.sh
XPCSHELL=./xulrunner-sdk/bin/xpcshell
install-xulrunner:
test -d xulrunner-sdk || ($(DOWNLOAD_CMD) $(XULRUNNER_DOWNLOAD) && tar xjf xulrunner*.tar.bz2 && rm xulrunner*.tar.bz2)
else
# Not a mac: assume linux
# Linux only!
# downloads and installs locally xulrunner to run the xpchsell
# script that creates the offline cache
ifeq ($(ARCH),x86_64)
XULRUNNER_DOWNLOAD=http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/11.0/runtimes/xulrunner-11.0.en-US.linux-x86_64.tar.bz2
else
XULRUNNER_DOWNLOAD=http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/11.0/runtimes/xulrunner-11.0.en-US.linux-i686.tar.bz2
endif
XULRUNNER=./xulrunner/run-mozilla.sh
XPCSHELL=./xulrunner/xpcshell
install-xulrunner :
test -d xulrunner || ($(DOWNLOAD_CMD) $(XULRUNNER_DOWNLOAD) && tar xjf xulrunner*.tar.bz2 && rm xulrunner*.tar.bz2)
endif
settingsdb :
@echo "B2G pre-populate settings DB."
$(XULRUNNER) $(XPCSHELL) -e 'const PROFILE_DIR = "$(CURDIR)/profile"' build/settings.js
# Generate profile/prefs.js
preferences: install-xulrunner
@echo "Generating prefs.js..."
@mkdir -p profile
$(XULRUNNER) $(XPCSHELL) -e 'const GAIA_DIR = "$(CURDIR)"; const PROFILE_DIR = "$(CURDIR)/profile"; const GAIA_DOMAIN = "$(GAIA_DOMAIN)$(GAIA_PORT)"; const DEBUG = $(DEBUG)' build/preferences.js
@echo "Done"
# Generate profile/extensions
EXT_DIR=profile/extensions
extensions:
@echo "Generating extensions..."
@mkdir -p profile
@rm -rf $(EXT_DIR)
ifeq ($(DEBUG),1)
cp -r tools/extensions $(EXT_DIR)
# httpd
@$(SED_INPLACE_NO_SUFFIX) -e 's|@GAIA_DIR@|$(CURDIR)|g' $(EXT_DIR)/[email protected]
@$(SED_INPLACE_NO_SUFFIX) -e 's|@GAIA_DOMAIN@|$(GAIA_DOMAIN)|g' $(EXT_DIR)/httpd/content/httpd.js
@$(SED_INPLACE_NO_SUFFIX) -e 's|@GAIA_DIR@|$(CURDIR)|g' $(EXT_DIR)/httpd/content/loader.js
@$(SED_INPLACE_NO_SUFFIX) -e 's|@GAIA_DOMAIN@|$(GAIA_DOMAIN)|g' $(EXT_DIR)/httpd/content/loader.js
@$(SED_INPLACE_NO_SUFFIX) -e 's|@GAIA_PORT@|$(subst :,,$(GAIA_PORT))|g' $(EXT_DIR)/httpd/content/loader.js
endif
@echo "Done"
###############################################################################
# Tests #
###############################################################################
MOZ_TESTS = "$(MOZ_OBJDIR)/_tests/testing/mochitest"
INJECTED_GAIA = "$(MOZ_TESTS)/browser/gaia"
TEST_PATH=gaia/tests/${TEST_FILE}
.PHONY: tests
tests: manifests offline
echo "Checking if the mozilla build has tests enabled..."
test -d $(MOZ_TESTS) || (echo "Please ensure you don't have |ac_add_options --disable-tests| in your mozconfig." && exit 1)
echo "Checking the injected Gaia..."
test -L $(INJECTED_GAIA) || ln -s $(CURDIR) $(INJECTED_GAIA)
TEST_PATH=$(TEST_PATH) make -C $(MOZ_OBJDIR) mochitest-browser-chrome EXTRA_TEST_ARGS="--browser-arg=\"\" --extra-profile-file=$(CURDIR)/profile/webapps --extra-profile-file=$(CURDIR)/profile/OfflineCache --extra-profile-file=$(CURDIR)/profile/user.js"
.PHONY: common-install
common-install:
@test -x $(NODEJS) || (echo "Please Install NodeJS -- (use aptitude on linux or homebrew on osx)" && exit 1 )
@test -x $(NPM) || (echo "Please install NPM (node package manager) -- http://npmjs.org/" && exit 1 )
cd $(TEST_AGENT_DIR) && npm install .
.PHONY: update-common
update-common: common-install
mkdir -p common/vendor/test-agent/
mkdir -p common/vendor/marionette-client/
mkdir -p common/vendor/chai/
rm -f common/vendor/test-agent/test-agent*.js
rm -f common/vendor/marionette-client/*.js
rm -f common/vendor/chai/*.js
cp $(TEST_AGENT_DIR)/node_modules/test-agent/test-agent.js common/vendor/test-agent/
cp $(TEST_AGENT_DIR)/node_modules/test-agent/test-agent.css common/vendor/test-agent/
cp $(TEST_AGENT_DIR)/node_modules/marionette-client/marionette.js common/vendor/marionette-client/
cp $(TEST_AGENT_DIR)/node_modules/chai/chai.js common/vendor/chai/
# Temp make file method until we can switch
# over everything in test
.PHONY: test-agent-test
test-agent-test:
@$(TEST_AGENT_DIR)/node_modules/test-agent/bin/js-test-agent test --reporter $(REPORTER)
.PHONY: test-agent-server
test-agent-server: common-install
$(TEST_AGENT_DIR)/node_modules/test-agent/bin/js-test-agent server -c ./$(TEST_AGENT_DIR)/test-agent-server.js --http-path . --growl
.PHONY: marionette
marionette:
#need the profile
test -d $(GAIA)/profile || $(MAKE) profile
ifneq ($(PYTHON_MAJOR), 2)
@echo "Python 2.7.x is needed for the marionette client. You can set the PYTHON_27 variable to your python2.7 path." && exit 1
endif
ifneq ($(PYTHON_MINOR), 7)
@echo "Python 2.7.x is needed for the marionette client. You can set the PYTHON_27 variable to your python2.7 path." && exit 1
endif
ifeq ($(strip $(MC_DIR)),)
@echo "Please have the MC_DIR environment variable point to the top of your mozilla-central tree." && exit 1
endif
#if B2G_BIN is defined, we will run the b2g binary, otherwise, we assume an instance is running
ifneq ($(strip $(B2G_BIN)),)
cd $(MC_DIR)/testing/marionette/client/marionette && \
sh venv_test.sh $(PYTHON_27) --address=$(MARIONETTE_HOST):$(MARIONETTE_PORT) --b2gbin=$(B2G_BIN) $(TEST_DIRS)
else
cd $(MC_DIR)/testing/marionette/client/marionette && \
sh venv_test.sh $(PYTHON_27) --address=$(MARIONETTE_HOST):$(MARIONETTE_PORT) $(TEST_DIRS)
endif
###############################################################################
# Utils #
###############################################################################
# Generate a text file containing the current changeset of Gaia
# XXX I wonder if this should be a replace-in-file hack. This would let us
# let us remove the update-offline-manifests target dependancy of the
# default target.
stamp-commit-hash:
git log -1 --format="%H%n%at" HEAD > apps/settings/gaia-commit.txt
# Erase all the indexedDB databases on the phone, so apps have to rebuild them.
delete-databases:
$(ADB) shell rm -r /data/b2g/mozilla/*.default/indexedDB/*
# Take a screenshot of the device and put it in screenshot.png
screenshot:
mkdir -p screenshotdata
$(ADB) pull /dev/graphics/fb0 screenshotdata/fb0
dd bs=1920 count=800 if=screenshotdata/fb0 of=screenshotdata/fb0b
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 480x800 -i screenshotdata/fb0b -f image2 -vcodec png screenshot.png
rm -rf screenshotdata
# Forward port to use the RIL daemon from the device
forward:
$(ADB) shell touch /data/local/rilproxyd
$(ADB) shell killall rilproxy
$(ADB) forward tcp:6200 localreserved:rilproxyd
# update the manifest.appcache files to match what's actually there
update-offline-manifests:
@cd apps; \
for d in `find * -maxdepth 0 -type d` ;\
do \
if [ -f $$d/manifest.json ] ;\
then \
echo \\t$$d ;\
cd $$d ;\
echo "CACHE MANIFEST" > manifest.appcache ;\
cat `find * -type f | sort -nfs` | $(MD5SUM) | cut -f 1 -d ' ' | sed 's/^/\#\ Version\ /' >> manifest.appcache ;\
find * -type f | grep -v tools | sort >> manifest.appcache ;\
$(SED_INPLACE_NO_SUFFIX) -e 's|manifest.appcache||g' manifest.appcache ;\
echo "http://$(GAIA_DOMAIN)$(GAIA_PORT)/webapi.js" >> manifest.appcache ;\
echo "NETWORK:" >> manifest.appcache ;\
echo "http://*" >> manifest.appcache ;\
echo "https://*" >> manifest.appcache ;\
cd .. ;\
fi \
done
# If your gaia/ directory is a sub-directory of the B2G directory, then
# you should use the install-gaia target of the B2G Makefile. But if you're
# working on just gaia itself, and you already have B2G firmware on your
# phone, and you have adb in your path, then you can use the install-gaia
# target to update the gaia files and reboot b2g
PROFILE_PATH = /data/b2g/mozilla/`$(ADB) shell ls -1 /data/b2g/mozilla/ | grep default | tr -d [:cntrl:]`
install-gaia: profile
$(ADB) start-server
$(ADB) shell rm -r /cache/*
python build/install-gaia.py "$(ADB)"
# Until bug 746121 lands, push user.js in the profile
$(ADB) push profile/user.js ${PROFILE_PATH}/user.js
@echo "Installed gaia into profile/."
$(ADB) shell kill $(shell $(ADB) shell toolbox ps | grep "b2g" | awk '{ print $$2; }')
@echo 'Rebooting b2g now'