ether: specify v23 flags using env var

Change-Id: Ia035180e08e2705caf7e4d5e918507176e900978
diff --git a/.gitignore b/.gitignore
index 82e486e..8210b0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
 # Build artifacts
+/bin
+/creds
 /gen
 
 # Dart dependencies
diff --git a/Makefile b/Makefile
index bb385e0..de1b1eb 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,13 @@
 GO_FILES := $(shell find go/src -name "*.go")
 V23_GO_FILES := $(shell find $(V23_ROOT) -name "*.go")
 
+# Flags for Syncbase service running as Mojo service.
+# See v.io/x/ref/runtime/internal/mojo_util.go for the wonderful magic that
+# makes this work.
+MOUNTTABLE_ADDR := 127.0.0.1:4001
+SYNCBASED_ADDR := 127.0.0.1:4002
+V23_MOJO_FLAGS := '--v=5 --alsologtostderr=false --root-dir=/tmp/syncbase_mojo --name=syncbase_mojo --v23.namespace.root=/$(MOUNTTABLE_ADDR) --v23.tcp.address=$(SYNCBASED_ADDR) --v23.permissions.literal={"Admin":{"In":["..."]},"Write":{"In":["..."]},"Read":{"In":["..."]},"Resolve":{"In":["..."]},"Debug":{"In":["..."]}} --v23.credentials=$(V23_ROOT)/experimental/projects/ether/creds'
+
 ifndef MOJO_DIR
 	$(error MOJO_DIR is not set: $(MOJO_DIR))
 endif
@@ -62,8 +69,22 @@
 	$(MOJOM_BIN) $1 -d . -o $2 -g $3
 endef
 
+.DELETE_ON_ERROR:
+
 all: test
 
+# Builds mounttabled, principal, and syncbased.
+bin: $(V23_GO_FILES)
+	v23 go build -a -o $@/mounttabled v.io/x/ref/services/mounttable/mounttabled
+	v23 go build -a -o $@/principal v.io/x/ref/cmd/principal
+	v23 go build -a -o $@/syncbased v.io/syncbase/x/ref/services/syncbase/syncbased
+	touch $@
+
+# Mints credentials.
+creds: bin
+	./bin/principal seekblessings --v23.credentials creds
+	touch $@
+
 # Builds the shared library that Mojo services must be linked with.
 $(MOJO_SHARED_LIB):
 ifeq ($(wildcard $(MOJO_BUILD_DIR)),)
@@ -105,7 +126,7 @@
 gen/mojo/syncbase_server.mojo: $(GO_FILES) $(V23_GO_FILES) gen-mojom $(MOJO_SHARED_LIB)
 	$(call MOGO_BUILD,v.io/syncbase/x/ref/services/syncbase/syncbased,$@)
 
-# Check that the dart-style is being met. Note: Comments are ignored when
+# Checks that the dart-style is being met. Note: Comments are ignored when
 # checking whitespace.
 .PHONY: check-fmt
 check-fmt:
@@ -127,7 +148,7 @@
 # are stable enough to reliably test syncbase.
 .PHONY: run-syncbase-app
 run-syncbase-app: gen/mojo/syncbase_server.mojo gen-mojom dart/packages
-	$(MOJO_DIR)/src/mojo/devtools/common/mojo_run $(MOJO_FLAGS) -v --enable-multiprocess $(PWD)/dart/bin/syncbase.dart
+	V23_MOJO_FLAGS=$(V23_MOJO_FLAGS) $(MOJO_DIR)/src/mojo/devtools/common/mojo_run $(MOJO_FLAGS) -v --enable-multiprocess $(PWD)/dart/bin/syncbase.dart
 
 .PHONY: test
 test: dart/packages gen-mojom gen/mojo/echo_server.mojo
diff --git a/dart/bin/syncbase.dart b/dart/bin/syncbase.dart
index 011997e..9ccb845 100644
--- a/dart/bin/syncbase.dart
+++ b/dart/bin/syncbase.dart
@@ -12,7 +12,7 @@
 
   // TODO(nlacasse): Switch to serving these files over http rather than
   // directly from the filesystem, so they can be accessed by Android.
-  String url = args[1].replaceFirst('dart/bin/syncbase.dart', 'gen/mojo/syncbase_server.mojo');
+  String url = 'file://' + args[1].replaceFirst('dart/bin/syncbase.dart', 'gen/mojo/syncbase_server.mojo');
 
   SyncbaseClient c = new SyncbaseClient(handle, url);
   await c.connect();
diff --git a/dart/lib/syncbase_client.dart b/dart/lib/syncbase_client.dart
index 112b708..94b2069 100644
--- a/dart/lib/syncbase_client.dart
+++ b/dart/lib/syncbase_client.dart
@@ -21,7 +21,7 @@
   // TODO(nlacasse): Test this function with working syncbase mojo service.
   Future<bool> appExists(String name) async {
     mojom.SyncbaseAppExistsResponseParams v = await _proxy.ptr.appExists(name);
-    if (v.err != null) {
+    if (v.err.id != '') {
       throw v.err;
     }
     return v.exists;