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