Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
242 lines (209 loc) · 9.92 KB
/
Copy pathMakefile
File metadata and controls
242 lines (209 loc) · 9.92 KB
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
PWD := $(shell pwd)
ifndef NOFIND
DART_FILES := $(shell find example lib test -name "*.dart" -not -path "lib/gen/*")
V23_GO_FILES := $(shell find $(JIRI_ROOT) -name "*.go")
endif
include ../shared/mojo.mk
# Flags for Syncbase service running as Mojo service.
V23_MOJO_FLAGS := --v=0
MOJOM_FILE := mojom/syncbase.mojom
ifdef ANDROID
# Parse the adb devices output to obtain the correct device id.
# sed takes out the ANDROID_PLUS_ONE'th row of the output
# awk takes just the first bit of the line (before whitespace).
ANDROID_PLUS_ONE := $(shell echo $(ANDROID) \+ 1 | bc)
DEVICE_ID := $(shell adb devices | sed -n $(ANDROID_PLUS_ONE)p | awk '{ print $$1; }')
TARGET_DEVICE_FLAG += --target-device $(DEVICE_ID)
MOJO_ANDROID_FLAGS += $(TARGET_DEVICE_FLAG)
SYNCBASE_BUILD_DIR := $(PWD)/gen/mojo/android
# NOTE(nlacasse): Trying to write to a directory that the app does not have
# permission to causes a crash with no stack trace. Because of this, we
# set logtostderr=true to prevent vlog from writing logs to directories we
# don't have permissions on. (Alternatively, we could set --log_dir to a
# directory inside APP_HOME_DIR.) We set syncbase root-dir inside
# APP_HOME_DIR for the same reason.
APP_HOME_DIR = /data/data/org.chromium.mojo.shell/app_home
SYNCBASE_ROOT_DIR=$(APP_HOME_DIR)/mojo_syncbase_data
ANDROID_CREDS_DIR := /sdcard/v23creds
V23_MOJO_FLAGS += --logtostderr=true --root-dir=$(SYNCBASE_ROOT_DIR) --v23.credentials=$(ANDROID_CREDS_DIR)
# For some reason we need to set the origin flag when running on Android,
# but setting it on Linux causes errors.
ORIGIN_FLAG := --origin $(MOJO_SERVICES)
else
SYNCBASE_BUILD_DIR := $(PWD)/gen/mojo/linux_amd64
SYNCBASE_ROOT_DIR := $(PWD)/tmp/syncbase_data$(SYNC_SUFFIX)
V23_MOJO_FLAGS += --root-dir=$(SYNCBASE_ROOT_DIR) --v23.credentials=$(PWD)/creds
endif
# If this is not the first mojo shell, then you must reuse the dev servers
# to avoid a "port in use" error.
ifneq ($(shell fuser 31500/tcp),)
REUSE_FLAG := --reuse-servers
endif
# Use BENCHMARK = the suffix of the syncbase instance (e.g., pingpong/s1)
ifdef BENCHMARK
V23_MOJO_FLAGS += --name=/ns.dev.v.io:8101/tmp/benchmark/$(BENCHMARK)
endif
MOJO_SHELL_FLAGS := $(MOJO_SHELL_FLAGS) \
--config-alias SYNCBASE_DIR=$(PWD) \
--config-alias SYNCBASE_BUILD_DIR=$(SYNCBASE_BUILD_DIR) \
"--args-for=https://mojo.v.io/syncbase_server.mojo $(V23_MOJO_FLAGS)" \
"--args-for=mojo:dart_content_handler --enable-strict-mode" \
$(REUSE_FLAG) \
$(ORIGIN_FLAG)
.DELETE_ON_ERROR:
all: test
.PHONY: build
build: $(SYNCBASE_BUILD_DIR)/syncbase_server.mojo gen-mojom
# Builds mounttabled, principal, and syncbased.
bin: $(V23_GO_FILES) | mojo-env-check
jiri go build -a -o $@/mounttabled v.io/x/ref/services/mounttable/mounttabled
jiri go build -a -o $@/principal v.io/x/ref/cmd/principal
jiri go build -a -o $@/syncbased v.io/x/ref/services/syncbase/syncbased
touch $@
# Mints credentials.
creds: | bin
./bin/principal seekblessings --v23.credentials creds
touch $@
# TODO(nlacasse): These target-specific variables will affect this task and all
# pre-requisite tasks. Luckily none of the prerequisites require that these
# variables have their original value, so everything works. Once we have a
# prereq that requires the original value, we will need to re-work these
# variables.
$(SYNCBASE_BUILD_DIR)/syncbase_server.mojo: $(V23_GO_FILES) gen/go/src/mojom/syncbase/syncbase.mojom.go | mojo-env-check
$(call MOGO_BUILD,v.io/x/ref/services/syncbase/syncbased,$@)
# Formats dart files to follow dart style conventions.
.PHONY: dartfmt
dartfmt: packages
dartfmt --overwrite $(DART_FILES)
# Lints src and test files with dartanalyzer. This takes a few seconds.
.PHONY: dartanalyzer
dartanalyzer: packages gen-mojom
# TODO(nlacasse): Fix dart mojom binding generator so it does not produce files
# that violate dartanalyzer. For now, we use "grep -v" to hide all hints and
# warnings from *.mojom.dart files.
dartanalyzer benchmark/**/*.dart example/*.dart lib/*.dart test/**/*.dart | grep -v "\.mojom\.dart, line"
# Installs dart dependencies.
packages: pubspec.yaml
pub upgrade
.PHONY: gen-mojom
gen-mojom: lib/gen/dart-gen/mojom/lib/mojo/syncbase.mojom.dart gen/go/src/mojom/syncbase/syncbase.mojom.go
# TODO(aghassemi): The mojom compiler is in flux, and updates to it are
# typically not backwards-compatible, so for now we mark this rule as .PHONY in
# order to force recompilation of mojom files with every build. Once the mojom
# compiler stabilizes, we can remove the .PHONY label and avoid recompiling our
# mojom files unnecessarily.
#.PHONY: gen/go/src/mojom/syncbase/syncbase.mojom.go
gen/go/src/mojom/syncbase/syncbase.mojom.go: | mojo-env-check
$(call MOJOM_GEN,$(MOJOM_FILE),.,gen,go)
gofmt -w $@
#.PHONY: lib/gen/dart-gen/mojom/lib/mojo/syncbase.mojom.dart
lib/gen/dart-gen/mojom/lib/mojo/syncbase.mojom.dart: | mojo-env-check
$(call MOJOM_GEN,$(MOJOM_FILE),.,lib/gen,dart)
# TODO(nlacasse): mojom_bindings_generator creates bad symlinks on dart files,
# so we delete them. Stop doing this once the generator is fixed. See
# https://github.com/domokit/mojo/issues/386
rm -f lib/gen/mojom/$(notdir $@)
# TODO(sadovsky): Wipe any existing Syncbase data, as done in test-integration.
.PHONY: run-syncbase-example
run-syncbase-example: $(SYNCBASE_BUILD_DIR)/syncbase_server.mojo packages lib/gen/dart-gen/mojom/lib/mojo/syncbase.mojom.dart | mojo-env-check creds
ifdef ANDROID
adb -s $(DEVICE_ID) push -p $(PWD)/creds $(ANDROID_CREDS_DIR)
endif
$(call MOJO_RUN,"https://mojo.v.io/syncbase_example.dart")
# The pingpong benchmark is meant to run on N devices.
# Pass testID peerID numPeers pattern numTimes as $(ARGS) to this call.
#
# For example, for a 2 Android ping pong benchmark:
# ANDROID=1 BENCHMARK=pingpong/s0 make ARGS="MyTest 0 2 PingPong 100" benchmark-pingpong
# ANDROID=2 BENCHMARK=pingpong/s1 make ARGS="MyTest 1 2 PingPong 100" benchmark-pingpong
#
# You can also run this on Linux, but be sure to use different HOME dirs.
# Note: The first one shouldn't set a HOME dir.
# BENCHMARK=pingpong/s0 SYNC_SUFFIX=s0 make ARGS="MyTest 0 3 Cycle 200" benchmark-pingpong
# HOME=/tmp/test/s1 BENCHMARK=pingpong/s1 SYNC_SUFFIX=s1 make ARGS="MyTest 1 3 Cycle 200" benchmark-pingpong
# HOME=/tmp/test/s2 BENCHMARK=pingpong/s2 SYNC_SUFFIX=s2 make ARGS="MyTest 2 3 Cycle 200" benchmark-pingpong
#
# TODO(alexfandrianto): I think it would be easier if we had a script call the benchmark.
# Note: The Syncbase Creator (peer 0) should be created first; it may even take a minute to be ready.
.PHONY: benchmark-pingpong
benchmark-pingpong: packages $(SYNCBASE_BUILD_DIR)/syncbase_server.mojo gen-mojom test-preparation | mojo-env-check creds
ifdef ANDROID
adb -s $(DEVICE_ID) push -p $(PWD)/creds $(ANDROID_CREDS_DIR)
endif
#$(MOJO_DEVTOOLS)/mojo_run --config-file $(PWD)/mojoconfig --shell-path $(MOJO_SHELL) \
# $(MOJO_SHELL_FLAGS) $(MOJO_ANDROID_FLAGS) "https://benchmark.mojo.v.io/pingpong/pingpong.dart $(ARGS)"
$(call MOJO_RUN,"https://benchmark.mojo.v.io/pingpong/pingpong.dart $(ARGS)")
.PHONY: test-preparation
test-preparation:
ifdef MOUNTTABLE_ADDR
$(error please unset MOUNTTABLE_ADDR before running the tests)
endif
# Make sure Syncbase starts from a clean slate.
ifdef ANDROID
adb -s $(DEVICE_ID) shell run-as org.chromium.mojo.shell rm -rf $(SYNCBASE_ROOT_DIR)
else
rm -rf $(SYNCBASE_ROOT_DIR)
endif
# Note: If "make test" fails with "Connection error to the shell" messages, it
# could be that the Dart VM has crashed (e.g. due to a missing import). In this
# case, "make dartanalyzer" often reveals the problem.
.PHONY: test
test: test-unit test-integration
.PHONY: test-unit
test-unit: packages
pub run test test/unit/*.dart
.PHONY: test-integration
test-integration: packages $(SYNCBASE_BUILD_DIR)/syncbase_server.mojo gen-mojom test-preparation | mojo-env-check
# Delete the 'creds' dir to make sure we are running with in-memory credentials.
# Otherwise tests time out.
# TODO(nlacasse): Figure out why tests time out with dev.v.io credentials. Maybe
# caveat validation?
rm -rf $(PWD)/creds
# NOTE(nlacasse): The "tests" argument must come before the "MOJO_SHELL_FLAGS"
# flags, otherwise mojo_test's argument parser gets confused and exits with an
# error.
$(MOJO_DEVTOOLS)/mojo_test tests --config-file $(PWD)/mojoconfig --shell-path $(MOJO_SHELL) $(MOJO_ANDROID_FLAGS) $(MOJO_SHELL_FLAGS)
.PHONY: publish
# NOTE(aghassemi): This must be inside lib in order to be accessible.
PACKAGE_MOJO_BIN_DIR := lib/mojo_services
ifdef DRYRUN
PUBLISH_FLAGS := --dry-run
endif
# NOTE(aghassemi): Publishing will fail unless you increment the version number
# in pubspec.yaml. See https://www.dartlang.org/tools/pub/versioning.html for
# guidelines.
# TODO(nlacasse): Generate a MOJO_VERSION file and publish that as part of the
# package.
publish: veryclean packages
$(MAKE) test # Test on Linux.
RELEASE=1 $(MAKE) build # Build on Linux.
RELEASE=1 ANDROID=1 $(MAKE) build # Cross-compile for Android.
mkdir -p $(PACKAGE_MOJO_BIN_DIR)
cp -r gen/mojo/* $(PACKAGE_MOJO_BIN_DIR)
# Note: The '-' at the beginning of the following command tells make to ignore
# failures and always continue to the next command.
-pub publish $(PUBLISH_FLAGS)
rm -rf $(PACKAGE_MOJO_BIN_DIR)
# Prepares a local version of the syncbase package that can be accessed via a
# pubspec path. For example, if this is release/projects/croupier, its
# pubspec.yaml will include a syncbase path dependency pointing at
# ../../mojo/syncbase.
# This is helpful when testing local changes to syncbase or a version that has
# not been published on pub yet.
.PHONY: local-publish
local-publish: veryclean packages
$(MAKE) build # Build on Linux.
ANDROID=1 $(MAKE) build # Cross-compile for Android.
mkdir -p $(PACKAGE_MOJO_BIN_DIR)
cp -r gen/mojo/* $(PACKAGE_MOJO_BIN_DIR)
# TODO(aghassemi): Why does mojo generate dart-pkg and mojom dirs?
.PHONY: clean
clean:
rm -rf bin creds gen tmp
rm -rf lib/gen/dart-pkg
rm -rf lib/gen/mojom
rm -rf $(PACKAGE_MOJO_BIN_DIR)
.PHONY: veryclean
veryclean: clean
rm -rf {.packages,pubspec.lock,packages}
jiri goext distclean