v23proxy: fix build + serv and cli same mach + switch to mojo config

Change-Id: Ic57445fc61cbf94e549f7c92cfcec8fa16c467e5
diff --git a/.gitignore b/.gitignore
index 3e05c60..0e37f5c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
 *.iml
 gen/
 mojom/mojo/
+.mojo_sdk
 .packages
 .pub
 pubspec.lock
diff --git a/Makefile b/Makefile
index a53b715..bd7d3a8 100644
--- a/Makefile
+++ b/Makefile
@@ -43,12 +43,16 @@
 	dartanalyzer lib/client.dart | grep -v "\[warning\] The imported libraries"
 	dartanalyzer dart-examples/echo/lib/main.dart | grep -v "\[warning\] The imported libraries"
 
+.PHONY: link-mojo_sdk
+link-mojo_sdk:
+	ln -sf $(MOJO_SDK) .mojo_sdk
+
 # Installs dart dependencies.
-packages:
+packages: link-mojo_sdk
 	pub get
 
 .PHONY: upgrade-packages
-upgrade-packages:
+upgrade-packages: link-mojo_sdk
 	pub upgrade
 
 build-go-examples: $(BUILD_DIR)/echo_client.mojo $(BUILD_DIR)/echo_server.mojo $(BUILD_DIR)/fortune_client.mojo $(BUILD_DIR)/fortune_server.mojo
@@ -114,7 +118,7 @@
 	gofmt -w $@
 
 gen/mojo/public/interfaces/bindings/mojom_types/mojom_types.mojom.dart: mojom/mojo/public/interfaces/bindings/mojom_types.mojom packages | mojo-env-check
-	$(call MOJOM_GEN,$<,.,lib/gen,dart)
+	$(call MOJOM_GEN,$<,mojom,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
@@ -125,7 +129,7 @@
 	gofmt -w $@
 
 gen/v23proxy.mojom.dart: mojom/mojom/v23proxy.mojom packages gen/mojo/public/interfaces/bindings/mojom_types/mojom_types.mojom.dart | mojo-env-check
-	$(call MOJOM_GEN,$<,.,lib/gen,dart)
+	$(call MOJOM_GEN,$<,mojom,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
@@ -136,25 +140,23 @@
 
 # Run the Mojo shell with map-origin. This is common to Linux and Android since
 # the latter cannot accept a config-file.
-# $1 is for any extra flags, like --enable-multiprocess.
-# $2 is for the name and/or path to the mojo or dart file.
-# $3 is for $ARGS, any arguments you might want to pass to the mojo program.
-# $4 is for 'dart'. This is temporary so that the --map-origin works out.
+# $1 is for the name and/or path to the mojo or dart file.
+# $2 is for $ARGS, any arguments you might want to pass to the mojo program.
 # TODO(alexfandrianto): Figure out how to make this mapping work without
 # needing a distinct URL.
 define RUN_MOJO_SHELL
 	$(MOJO_DEVTOOLS)/mojo_run \
-	$1 \
+	https://mojo.v.io/$1 \
+	--config-file $(PWD)/mojoconfig \
 	--shell-path $(MOJO_SHELL) \
 	$(ANDROID_FLAG) \
-	$(DEVICE_FLAG) \
-	--no-config-file \
-	$(REUSE_FLAG) \
-	$(ORIGIN_FLAG) \
-	--map-origin="https://mojo.v.io/=$(BUILD_DIR)" \
-	--map-origin="https://mojodart.v.io/=$(PWD)" \
-	--args-for="https://mojo$4.v.io/$2 $3" \
-	https://mojo$4.v.io/$2
+  	--enable-multiprocess \
+  	--config-alias V23PROXY_DIR=$(PWD) \
+  	--config-alias V23PROXY_BUILD_DIR=$(BUILD_DIR) \
+  	"--args-for=https://mojo.v.io/$1 $(ARGS) $(V23_MOJO_FLAGS)" \
+  	"--args-for=mojo:dart_content_handler --enable-strict-mode" \
+  	$(ORIGIN_FLAG)
+	$(MOJO_SHELL_FLAGS)
 endef
 
 # Start the v23proxy (server-side). This runs the v23proxy in its own shell and
@@ -168,7 +170,7 @@
 # ANDROID={device number} make start-v23proxy
 .PHONY: start-v23proxy
 start-v23proxy: build-go
-	$(call RUN_MOJO_SHELL,--enable-multiprocess,v23proxy.mojo,,)
+	$(call RUN_MOJO_SHELL,v23proxy.mojo,)
 
 
 # Start the echo client. This uses the v23proxy (client-side) to speak Vanadium
@@ -184,7 +186,7 @@
 # Note2: Setting HOME ensures that we avoid a db LOCK that is created per mojo shell instance.
 .PHONY: start-echo-client
 start-echo-client: build-go
-	$(call RUN_MOJO_SHELL,,echo_client.mojo,${ARGS},)
+	$(call RUN_MOJO_SHELL,echo_client.mojo,${ARGS})
 
 # Like the start-echo-client but using a Dart client instead.
 # Note: Uses --enable-multiprocess since it looks like the Dart VM and Go VM
@@ -192,7 +194,7 @@
 # is not used.
 .PHONY: start-dart-echo-client
 start-dart-echo-client: build-dart
-	$(call RUN_MOJO_SHELL,--enable-multiprocess,dart-examples/echo/lib/main.dart,${ARGS},dart)
+	$(call RUN_MOJO_SHELL,dart-examples/echo/lib/main.dart,${ARGS})
 
 
 # Start the fortune client. This uses the v23proxy (client-side) to speak Vanadium
@@ -208,7 +210,7 @@
 # Note2: Setting HOME ensures that we avoid a db LOCK that is created per mojo shell instance.
 .PHONY: start-fortune-client
 start-fortune-client: build-go
-	$(call RUN_MOJO_SHELL,,fortune_client.mojo,${ARGS},)
+	$(call RUN_MOJO_SHELL,fortune_client.mojo,${ARGS})
 
 # Like the start-fortune-client but using a Dart client instead.
 # Note: Uses --enable-multiprocess since it looks like the Dart VM and Go VM
@@ -216,7 +218,7 @@
 # is not used.
 .PHONY: start-dart-fortune-client
 start-dart-fortune-client: build-dart
-	$(call RUN_MOJO_SHELL,--enable-multiprocess,dart-examples/fortune/lib/main.dart,${ARGS},dart)
+	$(call RUN_MOJO_SHELL,dart-examples/fortune/lib/main.dart,${ARGS})
 
 
 .PHONY: clean
diff --git a/dart-examples/echo/pubspec.yaml b/dart-examples/echo/pubspec.yaml
index f612278..58b3a29 100644
--- a/dart-examples/echo/pubspec.yaml
+++ b/dart-examples/echo/pubspec.yaml
@@ -13,6 +13,6 @@
   sdk: '>=1.12.0 <2.0.0'
 dependency_overrides:
   mojo:
-    path: ../../../../../../../mojo/src/out/Debug/gen/dart-pkg/mojo
+    path: ../../.mojo_sdk/mojo/src/out/Debug/gen/dart-pkg/mojo
   v23proxy:
-    path: ../..
\ No newline at end of file
+    path: ../..
diff --git a/dart-examples/fortune/pubspec.yaml b/dart-examples/fortune/pubspec.yaml
index a336251..1647935 100644
--- a/dart-examples/fortune/pubspec.yaml
+++ b/dart-examples/fortune/pubspec.yaml
@@ -13,6 +13,6 @@
   sdk: '>=1.12.0 <2.0.0'
 dependency_overrides:
   mojo:
-    path: ../../../../../../../mojo/src/out/Debug/gen/dart-pkg/mojo
+    path: ../../.mojo_sdk/mojo/src/out/Debug/gen/dart-pkg/mojo
   v23proxy:
-    path: ../..
\ No newline at end of file
+    path: ../..
diff --git a/go/src/examples/echo/client/echo_client.go b/go/src/examples/echo/client/echo_client.go
index ae592db..e5aca16 100644
--- a/go/src/examples/echo/client/echo_client.go
+++ b/go/src/examples/echo/client/echo_client.go
@@ -47,7 +47,7 @@
 	if err == nil {
 		fmt.Printf("client: %s\n", response)
 	} else {
-		log.Println(err)
+		fmt.Printf("error: %v\n", err)
 	}
 
 	log.Printf("RemoteEchoClientDelegate.Initialize calling EchoX...")
diff --git a/lib/client.dart b/lib/client.dart
index c78e442..dd4cd0c 100644
--- a/lib/client.dart
+++ b/lib/client.dart
@@ -4,7 +4,7 @@
 
 library v23proxy;
 
-import 'gen/dart-gen/mojom/lib/v23proxy/v23proxy.mojom.dart';
+import 'gen/dart-gen/mojom/lib/mojo/bindings/types/v23proxy.mojom.dart';
 
 import 'package:mojo/application.dart' as application;
 import 'package:mojo/bindings.dart' as bindings;
@@ -31,4 +31,4 @@
   v23proxy.ptr.setupProxy(v23Name, serviceDescription.getTopLevelInterface(),
     serviceDescription.getAllTypeDefinitions(), proxy.name,
     pipe.endpoints[1]);
-}
\ No newline at end of file
+}
diff --git a/lib/dart-pkg/mojom/lib b/lib/dart-pkg/mojom/lib
new file mode 120000
index 0000000..01692dc
--- /dev/null
+++ b/lib/dart-pkg/mojom/lib
@@ -0,0 +1 @@
+../../gen/dart-gen/mojom/lib/
\ No newline at end of file
diff --git a/lib/dart-pkg/mojom/pubspec.yaml b/lib/dart-pkg/mojom/pubspec.yaml
new file mode 100644
index 0000000..385df9e
--- /dev/null
+++ b/lib/dart-pkg/mojom/pubspec.yaml
@@ -0,0 +1 @@
+name: mojom
diff --git a/mojoconfig b/mojoconfig
new file mode 100644
index 0000000..c20d5fc
--- /dev/null
+++ b/mojoconfig
@@ -0,0 +1,25 @@
+# Derived from $MOJO_DIR/mojoconfig.
+
+{
+  'dev_servers': [
+    {
+      'host': 'https://mojo.v.io/',
+      'port': 0,
+      'mappings': [
+        ('', [
+          # For v23proxy.mojo.
+          '@{V23PROXY_BUILD_DIR}',
+          # For examples.
+          '@{V23PROXY_DIR}/example'
+        ]),
+      ],
+    },
+    {
+      'host': 'https://test.mojo.v.io/',
+      'port': 0,
+      'mappings': [
+        ('', ['@{V23PROXY_DIR}/test']),
+      ],
+    },
+  ],
+}
diff --git a/pubspec.yaml b/pubspec.yaml
index 1a9bcee..5f93a28 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -5,6 +5,8 @@
 version: 0.0.1
 dependencies:
   mojo: '>=0.3.0 <0.4.0'
+  mojom:
+    path: lib/dart-pkg/mojom
 dev_dependencies:
   dart_style: any
   test: any
@@ -12,4 +14,4 @@
   sdk: '>=1.12.0 <2.0.0'
 dependency_overrides:
   mojo:
-    path: ../../../../../mojo/src/out/Debug/gen/dart-pkg/mojo
\ No newline at end of file
+    path: .mojo_sdk/src/out/Debug/gen/dart-pkg/mojo