Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 1 | DART_LIB_FILES_ALL := $(shell find lib -name *.dart) |
| 2 | DART_TEST_FILES_ALL := $(shell find test -name *.dart) |
| 3 | DART_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 Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 6 | CROUPIER_DIR := $(shell pwd) |
Alex Fandrianto | f6ce4eb | 2015-10-27 10:49:18 -0700 | [diff] [blame] | 7 | DISCOVERY_DIR := $(JIRI_ROOT)/release/mojo/discovery |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 8 | SHELL := /bin/bash -euo pipefail |
| 9 | |
Nicolas Lacasse | f5916c7 | 2015-10-05 17:03:25 -0700 | [diff] [blame] | 10 | # Flags for Syncbase service running as Mojo service. |
Alex Fandrianto | f6ce4eb | 2015-10-27 10:49:18 -0700 | [diff] [blame] | 11 | SYNCBASE_FLAGS := --v=0 |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 12 | |
| 13 | ifdef 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; }') |
| 19 | endif |
Nicolas Lacasse | f5916c7 | 2015-10-05 17:03:25 -0700 | [diff] [blame] | 20 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 21 | ifdef ANDROID |
| 22 | MOJO_ANDROID_FLAGS := --android |
Ali Ghassemi | 46ee96b | 2015-10-20 08:39:05 -0700 | [diff] [blame] | 23 | SYNCBASE_MOJO_BIN_DIR := packages/syncbase/mojo_services/android |
Alex Fandrianto | 84bed74 | 2015-11-18 15:15:48 -0800 | [diff] [blame] | 24 | DISCOVERY_MOJO_BIN_DIR := packages/v23discovery/mojo_services/android |
Nicolas Lacasse | f5916c7 | 2015-10-05 17:03:25 -0700 | [diff] [blame] | 25 | |
Nicolas Lacasse | c8bc76d | 2015-10-09 11:21:08 -0700 | [diff] [blame] | 26 | # Location of mounttable on syncslides-alpha network. |
| 27 | MOUNTTABLE := /192.168.86.254:8101 |
| 28 | # Name to mount under. |
Alex Fandrianto | a41f4b4 | 2015-11-18 13:29:44 -0800 | [diff] [blame] | 29 | NAME := croupierAlex |
Nicolas Lacasse | c8bc76d | 2015-10-09 11:21:08 -0700 | [diff] [blame] | 30 | |
Nicolas Lacasse | f5916c7 | 2015-10-05 17:03:25 -0700 | [diff] [blame] | 31 | APP_HOME_DIR = /data/data/org.chromium.mojo.shell/app_home |
| 32 | ANDROID_CREDS_DIR := /sdcard/v23creds |
Nicolas Lacasse | c8bc76d | 2015-10-09 11:21:08 -0700 | [diff] [blame] | 33 | |
Ali Ghassemi | 46ee96b | 2015-10-20 08:39:05 -0700 | [diff] [blame] | 34 | SYNCBASE_FLAGS += --logtostderr=true \ |
Nicolas Lacasse | c8bc76d | 2015-10-09 11:21:08 -0700 | [diff] [blame] | 35 | --root-dir=$(APP_HOME_DIR)/syncbase_data \ |
| 36 | --v23.credentials=$(ANDROID_CREDS_DIR) \ |
Alex Fandrianto | a41f4b4 | 2015-11-18 13:29:44 -0800 | [diff] [blame] | 37 | --v23.proxy=proxy |
| 38 | |
| 39 | #--v23.namespace.root=$(MOUNTTABLE) \ |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 40 | |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 41 | ifeq ($(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 Fandrianto | a41f4b4 | 2015-11-18 13:29:44 -0800 | [diff] [blame] | 45 | SYNCBASE_FLAGS += --name=$(MOUNTTABLE)/$(NAME) |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 46 | endif |
| 47 | |
Alex Fandrianto | 1be468c | 2015-11-15 15:55:25 -0800 | [diff] [blame] | 48 | # If this is not the first mojo shell, then you must reuse the devservers |
| 49 | # to avoid a "port in use" error. |
| 50 | ifneq ($(shell fuser 31841/tcp),) |
| 51 | REUSE_FLAG := --reuse-servers |
| 52 | endif |
| 53 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 54 | else |
Ali Ghassemi | 46ee96b | 2015-10-20 08:39:05 -0700 | [diff] [blame] | 55 | SYNCBASE_MOJO_BIN_DIR := packages/syncbase/mojo_services/linux_amd64 |
Alex Fandrianto | 84bed74 | 2015-11-18 15:15:48 -0800 | [diff] [blame] | 56 | DISCOVERY_MOJO_BIN_DIR := packages/v23discovery/mojo_services/linux_amd64 |
Ali Ghassemi | 46ee96b | 2015-10-20 08:39:05 -0700 | [diff] [blame] | 57 | SYNCBASE_FLAGS += --root-dir=$(PWD)/tmp/syncbase_data --v23.credentials=$(PWD)/creds |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 58 | endif |
| 59 | |
Alex Fandrianto | f6ce4eb | 2015-10-27 10:49:18 -0700 | [diff] [blame] | 60 | # We should consider combining these URLs and hosting our *.mojo files. |
| 61 | # https://github.com/vanadium/issues/issues/834 |
Ali Ghassemi | 46ee96b | 2015-10-20 08:39:05 -0700 | [diff] [blame] | 62 | export SYNCBASE_SERVER_URL := https://mojo.v.io/syncbase_server.mojo |
Alex Fandrianto | f6ce4eb | 2015-10-27 10:49:18 -0700 | [diff] [blame] | 63 | export DISCOVERY_SERVER_URL := https://mojo2.v.io/discovery.mojo |
| 64 | MOJO_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 Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 67 | |
| 68 | ifdef ANDROID |
Ali Ghassemi | 46ee96b | 2015-10-20 08:39:05 -0700 | [diff] [blame] | 69 | MOJO_SHELL_FLAGS += --target-device $(DEVICE_ID) |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 70 | endif |
| 71 | |
| 72 | # Runs a sky app. |
| 73 | # $1 is location of flx file. |
| 74 | define RUN_SKY_APP |
Alex Fandrianto | a41f4b4 | 2015-11-18 13:29:44 -0800 | [diff] [blame] | 75 | pub run flutter_tools -v --very-verbose run_mojo \ |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 76 | --app $1 \ |
| 77 | $(MOJO_ANDROID_FLAGS) \ |
Alex Fandrianto | a41f4b4 | 2015-11-18 13:29:44 -0800 | [diff] [blame] | 78 | --mojo-path $(MOJO_DIR)/src \ |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 79 | --checked \ |
| 80 | --mojo-debug \ |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 81 | -- $(MOJO_SHELL_FLAGS) \ |
Alex Fandrianto | 1be468c | 2015-11-15 15:55:25 -0800 | [diff] [blame] | 82 | $(REUSE_FLAG) \ |
| 83 | --no-config-file |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 84 | endef |
| 85 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 86 | .DELETE_ON_ERROR: |
| 87 | |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 88 | # Get the packages used by the dart project, according to pubspec.yaml |
Alex Fandrianto | e74249f | 2015-08-25 18:34:30 -0700 | [diff] [blame] | 89 | # Can also use `pub get`, but Sublime occasionally reverts me to an ealier version. |
| 90 | # Only `pub upgrade` can escape such a thing. |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 91 | packages: pubspec.yaml |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 92 | pub upgrade |
Alex Fandrianto | 7efccfd | 2015-08-12 18:48:03 -0700 | [diff] [blame] | 93 | |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 94 | # Builds mounttabled and principal. |
| 95 | bin: | 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 |
| 101 | creds: | bin |
| 102 | ./bin/principal seekblessings --v23.credentials creds |
| 103 | touch $@ |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 104 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 105 | .PHONY: dartfmt |
| 106 | dartfmt: |
Alex Fandrianto | c95dd19 | 2015-10-05 14:21:16 -0700 | [diff] [blame] | 107 | dartfmt -w $(DART_LIB_FILES_ALL) $(DART_TEST_FILES_ALL) |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 108 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 109 | .PHONY: lint |
Nicolas Lacasse | 48f7420 | 2015-09-10 11:33:36 -0700 | [diff] [blame] | 110 | lint: packages |
Alex Fandrianto | cbf5fa2 | 2015-09-01 14:59:01 -0700 | [diff] [blame] | 111 | dartanalyzer lib/main.dart | grep -v "\[warning\] The imported libraries" |
| 112 | dartanalyzer $(DART_TEST_FILES) | grep -v "\[warning\] The imported libraries" |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 113 | |
Nicolas Lacasse | 71ba598 | 2015-09-23 18:08:35 -0700 | [diff] [blame] | 114 | .PHONY: build |
| 115 | build: croupier.flx |
| 116 | |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 117 | croupier.flx: packages $(DART_LIB_FILES_ALL) |
Alex Fandrianto | a41f4b4 | 2015-11-18 13:29:44 -0800 | [diff] [blame] | 118 | pub run flutter_tools -v build --manifest manifest.yaml --output-file $@ |
Nicolas Lacasse | 71ba598 | 2015-09-23 18:08:35 -0700 | [diff] [blame] | 119 | |
Alex Fandrianto | d0233fd | 2015-10-14 12:50:06 -0700 | [diff] [blame] | 120 | # Starts the app on the specified ANDROID device. |
| 121 | # Don't forget to make creds first if they are not present. |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 122 | .PHONY: start |
Nicolas Lacasse | 71ba598 | 2015-09-23 18:08:35 -0700 | [diff] [blame] | 123 | start: croupier.flx env-check packages |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 124 | ifdef ANDROID |
| 125 | # Make creds dir if it does not exist. |
| 126 | mkdir -p creds |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 127 | adb -s $(DEVICE_ID) push -p $(PWD)/creds $(ANDROID_CREDS_DIR) |
Nicolas Lacasse | 973110f | 2015-10-07 09:37:42 -0700 | [diff] [blame] | 128 | endif |
| 129 | $(call RUN_SKY_APP,$<) |
Alex Fandrianto | cbf5fa2 | 2015-09-01 14:59:01 -0700 | [diff] [blame] | 130 | |
| 131 | .PHONY: mock |
| 132 | mock: |
| 133 | mv lib/src/syncbase/log_writer.dart lib/src/syncbase/log_writer.dart.backup |
Alex Fandrianto | 8dab3ed | 2015-10-01 16:15:48 -0700 | [diff] [blame] | 134 | mv lib/src/syncbase/settings_manager.dart lib/src/syncbase/settings_manager.dart.backup |
Alex Fandrianto | cbf5fa2 | 2015-09-01 14:59:01 -0700 | [diff] [blame] | 135 | cp lib/src/mocks/log_writer.dart lib/src/syncbase/ |
Alex Fandrianto | 8dab3ed | 2015-10-01 16:15:48 -0700 | [diff] [blame] | 136 | cp lib/src/mocks/settings_manager.dart lib/src/syncbase/ |
Alex Fandrianto | cbf5fa2 | 2015-09-01 14:59:01 -0700 | [diff] [blame] | 137 | |
| 138 | .PHONY: unmock |
| 139 | unmock: |
| 140 | mv lib/src/syncbase/log_writer.dart.backup lib/src/syncbase/log_writer.dart |
Alex Fandrianto | 8dab3ed | 2015-10-01 16:15:48 -0700 | [diff] [blame] | 141 | mv lib/src/syncbase/settings_manager.dart.backup lib/src/syncbase/settings_manager.dart |
Alex Fandrianto | 7efccfd | 2015-08-12 18:48:03 -0700 | [diff] [blame] | 142 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 143 | .PHONY: env-check |
| 144 | env-check: |
| 145 | ifndef MOJO_DIR |
| 146 | $(error MOJO_DIR is not set) |
| 147 | endif |
Nicolas Lacasse | bdca709 | 2015-09-24 10:03:30 -0700 | [diff] [blame] | 148 | ifndef JIRI_ROOT |
| 149 | $(error JIRI_ROOT is not set) |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 150 | endif |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 151 | |
Alex Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 152 | # 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 |
| 155 | test: packages |
Alex Fandrianto | 2c94fd3 | 2015-10-21 11:50:13 -0700 | [diff] [blame] | 156 | # 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 Fandrianto | 3d88169 | 2015-08-27 19:28:30 -0700 | [diff] [blame] | 160 | |
| 161 | .PHONY: clean |
Alex Fandrianto | 598a93c | 2015-08-25 10:47:25 -0700 | [diff] [blame] | 162 | clean: |
Nicolas Lacasse | c8bc76d | 2015-10-09 11:21:08 -0700 | [diff] [blame] | 163 | ifdef ANDROID |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 164 | # Clean syncbase data dir. |
| 165 | adb -s $(DEVICE_ID) shell rm -rf $(APP_HOME_DIR)/syncbase_data |
Nicolas Lacasse | c8bc76d | 2015-10-09 11:21:08 -0700 | [diff] [blame] | 166 | endif |
Nicolas Lacasse | 71ba598 | 2015-09-23 18:08:35 -0700 | [diff] [blame] | 167 | rm -f croupier.flx snapshot_blob.bin |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 168 | rm -rf bin tmp |
| 169 | |
| 170 | .PHONY: clean-creds |
| 171 | clean-creds: |
| 172 | ifdef ANDROID |
| 173 | # Clean syncbase creds dir. |
| 174 | adb -s $(DEVICE_ID) shell rm -rf $(ANDROID_CREDS_DIR) |
| 175 | endif |
| 176 | rm -rf creds |
Nicolas Lacasse | 71ba598 | 2015-09-23 18:08:35 -0700 | [diff] [blame] | 177 | |
| 178 | .PHONY: veryclean |
Alex Fandrianto | b3ff376 | 2015-10-13 13:31:12 -0700 | [diff] [blame] | 179 | veryclean: clean clean-creds |
Nicolas Lacasse | 71ba598 | 2015-09-23 18:08:35 -0700 | [diff] [blame] | 180 | rm -rf .packages .pub packages pubspec.lock |