blob: 8317a008828cea629977f5d2f5f021a3034e070f [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 Fandrianto84bed742015-11-18 15:15:48 -080024 DISCOVERY_MOJO_BIN_DIR := packages/v23discovery/mojo_services/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 Fandriantoa41f4b42015-11-18 13:29:44 -080029 NAME := croupierAlex
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) \
Alex Fandriantoa41f4b42015-11-18 13:29:44 -080037 --v23.proxy=proxy
38
39 #--v23.namespace.root=$(MOUNTTABLE) \
Alex Fandriantob3ff3762015-10-13 13:31:12 -070040
Alex Fandriantob3ff3762015-10-13 13:31:12 -070041ifeq ($(ANDROID), 1)
42 # If ANDROID is set to 1 exactly, then treat it like the first device.
43 # TODO(alexfandrianto): If we can do a better job of this, we won't have to
44 # special-case the first device.
Alex Fandriantoa41f4b42015-11-18 13:29:44 -080045 SYNCBASE_FLAGS += --name=$(MOUNTTABLE)/$(NAME)
Alex Fandriantob3ff3762015-10-13 13:31:12 -070046endif
47
Alex Fandrianto1be468c2015-11-15 15:55:25 -080048# If this is not the first mojo shell, then you must reuse the devservers
49# to avoid a "port in use" error.
50ifneq ($(shell fuser 31841/tcp),)
51 REUSE_FLAG := --reuse-servers
52endif
53
Alex Fandrianto3d881692015-08-27 19:28:30 -070054else
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070055 SYNCBASE_MOJO_BIN_DIR := packages/syncbase/mojo_services/linux_amd64
Alex Fandrianto84bed742015-11-18 15:15:48 -080056 DISCOVERY_MOJO_BIN_DIR := packages/v23discovery/mojo_services/linux_amd64
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070057 SYNCBASE_FLAGS += --root-dir=$(PWD)/tmp/syncbase_data --v23.credentials=$(PWD)/creds
Alex Fandrianto3d881692015-08-27 19:28:30 -070058endif
59
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070060# We should consider combining these URLs and hosting our *.mojo files.
61# https://github.com/vanadium/issues/issues/834
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070062export SYNCBASE_SERVER_URL := https://mojo.v.io/syncbase_server.mojo
Alex Fandriantof6ce4eb2015-10-27 10:49:18 -070063export DISCOVERY_SERVER_URL := https://mojo2.v.io/discovery.mojo
64MOJO_SHELL_FLAGS := --enable-multiprocess \
65 --map-origin="https://mojo2.v.io=$(DISCOVERY_MOJO_BIN_DIR)" --args-for="$(DISCOVERY_SERVER_URL) host$(ANDROID) mdns" \
66 --map-origin="https://mojo.v.io=$(SYNCBASE_MOJO_BIN_DIR)" --args-for="$(SYNCBASE_SERVER_URL) $(SYNCBASE_FLAGS)"
Nicolas Lacasse973110f2015-10-07 09:37:42 -070067
68ifdef ANDROID
Ali Ghassemi46ee96b2015-10-20 08:39:05 -070069 MOJO_SHELL_FLAGS += --target-device $(DEVICE_ID)
Nicolas Lacasse973110f2015-10-07 09:37:42 -070070endif
71
72# Runs a sky app.
73# $1 is location of flx file.
74define RUN_SKY_APP
Alex Fandriantoa41f4b42015-11-18 13:29:44 -080075 pub run flutter_tools -v --very-verbose run_mojo \
Nicolas Lacasse973110f2015-10-07 09:37:42 -070076 --app $1 \
77 $(MOJO_ANDROID_FLAGS) \
Alex Fandriantoa41f4b42015-11-18 13:29:44 -080078 --mojo-path $(MOJO_DIR)/src \
Nicolas Lacasse973110f2015-10-07 09:37:42 -070079 --checked \
80 --mojo-debug \
Alex Fandriantob3ff3762015-10-13 13:31:12 -070081 -- $(MOJO_SHELL_FLAGS) \
Alex Fandrianto1be468c2015-11-15 15:55:25 -080082 $(REUSE_FLAG) \
83 --no-config-file
Nicolas Lacasse973110f2015-10-07 09:37:42 -070084endef
85
Alex Fandrianto3d881692015-08-27 19:28:30 -070086.DELETE_ON_ERROR:
87
Alex Fandrianto598a93c2015-08-25 10:47:25 -070088# Get the packages used by the dart project, according to pubspec.yaml
Alex Fandriantoe74249f2015-08-25 18:34:30 -070089# Can also use `pub get`, but Sublime occasionally reverts me to an ealier version.
90# Only `pub upgrade` can escape such a thing.
Alex Fandrianto3d881692015-08-27 19:28:30 -070091packages: pubspec.yaml
Alex Fandrianto598a93c2015-08-25 10:47:25 -070092 pub upgrade
Alex Fandrianto7efccfd2015-08-12 18:48:03 -070093
Nicolas Lacasse973110f2015-10-07 09:37:42 -070094# Builds mounttabled and principal.
95bin: | env-check
96 jiri go build -a -o $@/mounttabled v.io/x/ref/services/mounttable/mounttabled
97 jiri go build -a -o $@/principal v.io/x/ref/cmd/principal
98 touch $@
99
100.PHONY: creds
101creds: | bin
102 ./bin/principal seekblessings --v23.credentials creds
103 touch $@
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700104
Alex Fandrianto3d881692015-08-27 19:28:30 -0700105.PHONY: dartfmt
106dartfmt:
Alex Fandriantoc95dd192015-10-05 14:21:16 -0700107 dartfmt -w $(DART_LIB_FILES_ALL) $(DART_TEST_FILES_ALL)
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700108
Alex Fandrianto3d881692015-08-27 19:28:30 -0700109.PHONY: lint
Nicolas Lacasse48f74202015-09-10 11:33:36 -0700110lint: packages
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700111 dartanalyzer lib/main.dart | grep -v "\[warning\] The imported libraries"
112 dartanalyzer $(DART_TEST_FILES) | grep -v "\[warning\] The imported libraries"
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700113
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700114.PHONY: build
115build: croupier.flx
116
Nicolas Lacasse973110f2015-10-07 09:37:42 -0700117croupier.flx: packages $(DART_LIB_FILES_ALL)
Alex Fandriantoa41f4b42015-11-18 13:29:44 -0800118 pub run flutter_tools -v build --manifest manifest.yaml --output-file $@
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700119
Alex Fandriantod0233fd2015-10-14 12:50:06 -0700120# Starts the app on the specified ANDROID device.
121# Don't forget to make creds first if they are not present.
Alex Fandrianto3d881692015-08-27 19:28:30 -0700122.PHONY: start
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700123start: croupier.flx env-check packages
Nicolas Lacasse973110f2015-10-07 09:37:42 -0700124ifdef ANDROID
125 # Make creds dir if it does not exist.
126 mkdir -p creds
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700127 adb -s $(DEVICE_ID) push -p $(PWD)/creds $(ANDROID_CREDS_DIR)
Nicolas Lacasse973110f2015-10-07 09:37:42 -0700128endif
129 $(call RUN_SKY_APP,$<)
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700130
131.PHONY: mock
132mock:
133 mv lib/src/syncbase/log_writer.dart lib/src/syncbase/log_writer.dart.backup
Alex Fandrianto8dab3ed2015-10-01 16:15:48 -0700134 mv lib/src/syncbase/settings_manager.dart lib/src/syncbase/settings_manager.dart.backup
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700135 cp lib/src/mocks/log_writer.dart lib/src/syncbase/
Alex Fandrianto8dab3ed2015-10-01 16:15:48 -0700136 cp lib/src/mocks/settings_manager.dart lib/src/syncbase/
Alex Fandriantocbf5fa22015-09-01 14:59:01 -0700137
138.PHONY: unmock
139unmock:
140 mv lib/src/syncbase/log_writer.dart.backup lib/src/syncbase/log_writer.dart
Alex Fandrianto8dab3ed2015-10-01 16:15:48 -0700141 mv lib/src/syncbase/settings_manager.dart.backup lib/src/syncbase/settings_manager.dart
Alex Fandrianto7efccfd2015-08-12 18:48:03 -0700142
Alex Fandrianto3d881692015-08-27 19:28:30 -0700143.PHONY: env-check
144env-check:
145ifndef MOJO_DIR
146 $(error MOJO_DIR is not set)
147endif
Nicolas Lacassebdca7092015-09-24 10:03:30 -0700148ifndef JIRI_ROOT
149 $(error JIRI_ROOT is not set)
Alex Fandrianto3d881692015-08-27 19:28:30 -0700150endif
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700151
Alex Fandrianto3d881692015-08-27 19:28:30 -0700152# TODO(alexfandrianto): I split off the syncbase logic from game.dart because it
153# would not run in a stand-alone VM. We will need to add mojo_test eventually.
154.PHONY: test
155test: packages
Alex Fandrianto2c94fd32015-10-21 11:50:13 -0700156 # Mock the syncbase implementations and unmock regardless of the test outcome.
157 $(MAKE) mock
158 pub run test -r expanded $(DART_TEST_FILES) || ($(MAKE) unmock && exit 1)
159 $(MAKE) unmock
Alex Fandrianto3d881692015-08-27 19:28:30 -0700160
161.PHONY: clean
Alex Fandrianto598a93c2015-08-25 10:47:25 -0700162clean:
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -0700163ifdef ANDROID
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700164 # Clean syncbase data dir.
165 adb -s $(DEVICE_ID) shell rm -rf $(APP_HOME_DIR)/syncbase_data
Nicolas Lacassec8bc76d2015-10-09 11:21:08 -0700166endif
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700167 rm -f croupier.flx snapshot_blob.bin
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700168 rm -rf bin tmp
169
170.PHONY: clean-creds
171clean-creds:
172ifdef ANDROID
173 # Clean syncbase creds dir.
174 adb -s $(DEVICE_ID) shell rm -rf $(ANDROID_CREDS_DIR)
175endif
176 rm -rf creds
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700177
178.PHONY: veryclean
Alex Fandriantob3ff3762015-10-13 13:31:12 -0700179veryclean: clean clean-creds
Nicolas Lacasse71ba5982015-09-23 18:08:35 -0700180 rm -rf .packages .pub packages pubspec.lock