blob: b2f8cfa8841eec28f0cafd5457b22481157e0ae1 [file] [log] [blame]
Nicolas Lacasse973110f2015-10-07 09:37:42 -07001DART_LIB_FILES_ALL := $(shell find lib -name *.dart)
2DART_TEST_FILES_ALL := $(shell find test -name *.dart)
3DART_TEST_FILES := $(shell find test -name *.dart ! -name *.part.dart)
4
5# This section is used to setup the environment for running with mojo_shell.
Alex Fandrianto3d881692015-08-27 19:28:30 -07006CROUPIER_DIR := $(shell pwd)
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -07007DISCOVERY_DIR := $(JIRI_ROOT)/release/mojo/discovery
Alex Fandrianto3d881692015-08-27 19:28:30 -07008SHELL := /bin/bash -euo pipefail
9
Nicolas Lacassef5916c72015-10-05 17:03:25 -070010# Flags for Syncbase service running as Mojo service.
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070011SYNCBASE_FLAGS := --v=0
Alex Fandriantob3ff3762015-10-13 13:31:12 -070012
13ifdef ANDROID
14 # Parse the adb devices output to obtain the correct device id.
15 # sed takes out the ANDROID_PLUS_ONE'th row of the output
16 # awk takes just the first bit of the line (before whitespace).
17 ANDROID_PLUS_ONE := $(shell echo $(ANDROID) \+ 1 | bc)
18 DEVICE_ID := $(shell adb devices | sed -n $(ANDROID_PLUS_ONE)p | awk '{ print $$1; }')
19endif
Nicolas Lacassef5916c72015-10-05 17:03:25 -070020
Alex Fandrianto3d881692015-08-27 19:28:30 -070021ifdef ANDROID
22 MOJO_ANDROID_FLAGS := --android
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070023 SYNCBASE_MOJO_BIN_DIR := packages/syncbase/mojo_services/android
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070024 DISCOVERY_MOJO_BIN_DIR := $(DISCOVERY_DIR)/gen/mojo/android
Nicolas Lacassef5916c72015-10-05 17:03:25 -070025
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -070026 # Location of mounttable on syncslides-alpha network.
27 MOUNTTABLE := /192.168.86.254:8101
28 # Name to mount under.
Alex Fandriantob3ff3762015-10-13 13:31:12 -070029 NAME := croupier
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -070030
Nicolas Lacassef5916c72015-10-05 17:03:25 -070031 APP_HOME_DIR = /data/data/org.chromium.mojo.shell/app_home
32 ANDROID_CREDS_DIR := /sdcard/v23creds
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -070033
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070034 SYNCBASE_FLAGS += --logtostderr=true \
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -070035 --root-dir=$(APP_HOME_DIR)/syncbase_data \
36 --v23.credentials=$(ANDROID_CREDS_DIR) \
37 --v23.namespace.root=$(MOUNTTABLE)
Alex Fandriantob3ff3762015-10-13 13:31:12 -070038
Alex Fandriantob3ff3762015-10-13 13:31:12 -070039ifeq ($(ANDROID), 1)
40 # If ANDROID is set to 1 exactly, then treat it like the first device.
41 # TODO(alexfandrianto): If we can do a better job of this, we won't have to
42 # special-case the first device.
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070043 SYNCBASE_FLAGS += --name=$(NAME)
Alex Fandriantob3ff3762015-10-13 13:31:12 -070044endif
45
Alex Fandrianto1be468c2015-11-15 15:55:25 -080046# If this is not the first mojo shell, then you must reuse the devservers
47# to avoid a "port in use" error.
48ifneq ($(shell fuser 31841/tcp),)
49 REUSE_FLAG := --reuse-servers
50endif
51
Alex Fandrianto3d881692015-08-27 19:28:30 -070052else
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070053 SYNCBASE_MOJO_BIN_DIR := packages/syncbase/mojo_services/linux_amd64
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070054 DISCOVERY_MOJO_BIN_DIR := $(DISCOVERY_DIR)/gen/mojo/linux_amd64
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070055 SYNCBASE_FLAGS += --root-dir=$(PWD)/tmp/syncbase_data --v23.credentials=$(PWD)/creds
Alex Fandrianto3d881692015-08-27 19:28:30 -070056endif
57
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070058# We should consider combining these URLs and hosting our *.mojo files.
59# https://github.com/vanadium/issues/issues/834
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070060export SYNCBASE_SERVER_URL := https://mojo.v.io/syncbase_server.mojo
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070061export DISCOVERY_SERVER_URL := https://mojo2.v.io/discovery.mojo
62MOJO_SHELL_FLAGS := --enable-multiprocess \
63 --map-origin="https://mojo2.v.io=$(DISCOVERY_MOJO_BIN_DIR)" --args-for="$(DISCOVERY_SERVER_URL) host$(ANDROID) mdns" \
64 --map-origin="https://mojo.v.io=$(SYNCBASE_MOJO_BIN_DIR)" --args-for="$(SYNCBASE_SERVER_URL) $(SYNCBASE_FLAGS)"
Nicolas Lacasse973110f2015-10-07 09:37:42 -070065
66ifdef ANDROID
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070067 MOJO_SHELL_FLAGS += --target-device $(DEVICE_ID)
Nicolas Lacasse973110f2015-10-07 09:37:42 -070068endif
69
70# Runs a sky app.
71# $1 is location of flx file.
72define RUN_SKY_APP
73 pub run sky_tools -v --very-verbose run_mojo \
74 --app $1 \
75 $(MOJO_ANDROID_FLAGS) \
Alex Fandriantob6e1a292015-11-02 13:36:02 -080076 --mojo-path $(MOJO_DIR)/src/mojo/devtools/common/mojo_run \
Nicolas Lacasse973110f2015-10-07 09:37:42 -070077 --checked \
78 --mojo-debug \
Alex Fandriantob3ff3762015-10-13 13:31:12 -070079 -- $(MOJO_SHELL_FLAGS) \
Alex Fandrianto1be468c2015-11-15 15:55:25 -080080 $(REUSE_FLAG) \
81 --no-config-file
Nicolas Lacasse973110f2015-10-07 09:37:42 -070082endef
83
Alex Fandrianto3d881692015-08-27 19:28:30 -070084.DELETE_ON_ERROR:
85
Alex Fandrianto598a93c2015-08-25 10:47:25 -070086# Get the packages used by the dart project, according to pubspec.yaml
Alex Fandriantoe74249f2015-08-25 18:34:30 -070087# Can also use `pub get`, but Sublime occasionally reverts me to an ealier version.
88# Only `pub upgrade` can escape such a thing.
Alex Fandrianto3d881692015-08-27 19:28:30 -070089packages: pubspec.yaml
Alex Fandrianto598a93c2015-08-25 10:47:25 -070090 pub upgrade
Alex Fandrianto7efccfd2015-08-12 18:48:03 -070091
Nicolas Lacasse973110f2015-10-07 09:37:42 -070092# Builds mounttabled and principal.
93bin: | env-check
94 jiri go build -a -o $@/mounttabled v.io/x/ref/services/mounttable/mounttabled
95 jiri go build -a -o $@/principal v.io/x/ref/cmd/principal
96 touch $@
97
98.PHONY: creds
99creds: | bin
100 ./bin/principal seekblessings --v23.credentials creds
101 touch $@
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700102
Alex Fandrianto3d881692015-08-27 19:28:30 -0700103.PHONY: dartfmt
104dartfmt:
Alex Fandriantoc95dd192015-10-05 14:21:16 -0700105 dartfmt -w $(DART_LIB_FILES_ALL) $(DART_TEST_FILES_ALL)
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700106
Alex Fandrianto3d881692015-08-27 19:28:30 -0700107.PHONY: lint
Nicolas Lacasse48f74202015-09-10 11:33:36 -0700108lint: packages
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700109 dartanalyzer lib/main.dart | grep -v "\[warning\] The imported libraries"
110 dartanalyzer $(DART_TEST_FILES) | grep -v "\[warning\] The imported libraries"
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700111
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700112.PHONY: build
113build: croupier.flx
114
Nicolas Lacasse973110f2015-10-07 09:37:42 -0700115croupier.flx: packages $(DART_LIB_FILES_ALL)
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700116 pub run sky_tools -v build --manifest manifest.yaml --output-file $@
117
Alex Fandriantod0233fd2015-10-14 12:50:06 -0700118# Starts the app on the specified ANDROID device.
119# Don't forget to make creds first if they are not present.
Alex Fandrianto3d881692015-08-27 19:28:30 -0700120.PHONY: start
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700121start: croupier.flx env-check packages
Nicolas Lacasse973110f2015-10-07 09:37:42 -0700122ifdef ANDROID
123 # Make creds dir if it does not exist.
124 mkdir -p creds
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700125 adb -s $(DEVICE_ID) push -p $(PWD)/creds $(ANDROID_CREDS_DIR)
Nicolas Lacasse973110f2015-10-07 09:37:42 -0700126endif
127 $(call RUN_SKY_APP,$<)
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700128
129.PHONY: mock
130mock:
131 mv lib/src/syncbase/log_writer.dart lib/src/syncbase/log_writer.dart.backup
Alex Fandrianto8dab3ed2015-10-01 16:15:48 -0700132 mv lib/src/syncbase/settings_manager.dart lib/src/syncbase/settings_manager.dart.backup
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700133 cp lib/src/mocks/log_writer.dart lib/src/syncbase/
Alex Fandrianto8dab3ed2015-10-01 16:15:48 -0700134 cp lib/src/mocks/settings_manager.dart lib/src/syncbase/
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700135
136.PHONY: unmock
137unmock:
138 mv lib/src/syncbase/log_writer.dart.backup lib/src/syncbase/log_writer.dart
Alex Fandrianto8dab3ed2015-10-01 16:15:48 -0700139 mv lib/src/syncbase/settings_manager.dart.backup lib/src/syncbase/settings_manager.dart
Alex Fandrianto7efccfd2015-08-12 18:48:03 -0700140
Alex Fandrianto3d881692015-08-27 19:28:30 -0700141.PHONY: env-check
142env-check:
143ifndef MOJO_DIR
144 $(error MOJO_DIR is not set)
145endif
Nicolas Lacassebdca7092015-09-24 10:03:30 -0700146ifndef JIRI_ROOT
147 $(error JIRI_ROOT is not set)
Alex Fandrianto3d881692015-08-27 19:28:30 -0700148endif
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700149
Alex Fandrianto3d881692015-08-27 19:28:30 -0700150# TODO(alexfandrianto): I split off the syncbase logic from game.dart because it
151# would not run in a stand-alone VM. We will need to add mojo_test eventually.
152.PHONY: test
153test: packages
Alex Fandrianto2c94fd32015-10-21 11:50:13 -0700154 # Mock the syncbase implementations and unmock regardless of the test outcome.
155 $(MAKE) mock
156 pub run test -r expanded $(DART_TEST_FILES) || ($(MAKE) unmock && exit 1)
157 $(MAKE) unmock
Alex Fandrianto3d881692015-08-27 19:28:30 -0700158
159.PHONY: clean
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700160clean:
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -0700161ifdef ANDROID
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700162 # Clean syncbase data dir.
163 adb -s $(DEVICE_ID) shell rm -rf $(APP_HOME_DIR)/syncbase_data
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -0700164endif
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700165 rm -f croupier.flx snapshot_blob.bin
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700166 rm -rf bin tmp
167
168.PHONY: clean-creds
169clean-creds:
170ifdef ANDROID
171 # Clean syncbase creds dir.
172 adb -s $(DEVICE_ID) shell rm -rf $(ANDROID_CREDS_DIR)
173endif
174 rm -rf creds
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700175
176.PHONY: veryclean
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700177veryclean: clean clean-creds
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700178 rm -rf .packages .pub packages pubspec.lock