go: update go build rules
Replace go_shared_library with go_mojo_application
that does the same + copies library to root_build_dir.
It makes go applications more convenient to use.
Updating README files with new instructions.
Also changing go echo client to talk to go echo server.
R=jamesr@chromium.org
Review URL: https://codereview.chromium.org/1105443002
diff --git a/examples/go/BUILD.gn b/examples/go/BUILD.gn
index edd29e0..78412ab 100644
--- a/examples/go/BUILD.gn
+++ b/examples/go/BUILD.gn
@@ -12,7 +12,7 @@
]
}
- go_shared_library("go_echo_client") {
+ go_mojo_application("go_echo_client") {
sources = [
"echo_client.go",
]
@@ -25,7 +25,7 @@
]
}
- go_shared_library("go_echo_server") {
+ go_mojo_application("go_echo_server") {
sources = [
"echo_server.go",
]
diff --git a/examples/go/README.txt b/examples/go/README.txt
index e424382..cdfc603 100644
--- a/examples/go/README.txt
+++ b/examples/go/README.txt
@@ -5,9 +5,4 @@
1) Follow steps from //mojo/go/sample_app/README.txt
To run client:
-$ mojo/tools/android_mojo_shell.py --url-mappings="mojo:go_echo_client"="http://10.0.2.2:4444/obj/examples/go/go_echo_client","mojo:echo_server"="http://10.0.2.2:4444/echo_server.mojo" "mojo:go_echo_client"
-
-To run server:
-$ mojo/tools/android_mojo_shell.py --url-mappings="mojo:echo_server"="http://10.0.2.2:4444/obj/examples/go/go_echo_server","mojo:echo_client"="http://10.0.2.2:4444/echo_client.mojo" "mojo:echo_client"
-
-You can't run two go mojo applications at the same time now as they need separated processes.
+$ mojo/tools/android_mojo_shell.py --enable-multiprocess mojo:go_echo_client
diff --git a/examples/go/echo_client.go b/examples/go/echo_client.go
index 1fdd0b3..92d3477 100644
--- a/examples/go/echo_client.go
+++ b/examples/go/echo_client.go
@@ -26,11 +26,11 @@
func (delegate *EchoClientDelegate) Initialize(ctx application.Context) {
echoRequest, echoPointer := echo.CreateMessagePipeForEcho()
- ctx.ConnectToApplication("mojo:echo_server").ConnectToService(&echoRequest)
+ ctx.ConnectToApplication("mojo:go_echo_server").ConnectToService(&echoRequest)
delegate.echo = echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter())
response, err := delegate.echo.EchoString(bindings.StringPointer("Hello, Go world!"))
if response != nil {
- fmt.Println(*response)
+ fmt.Printf("client: %s\n", *response)
} else {
log.Println(err)
}
diff --git a/examples/go/echo_server.go b/examples/go/echo_server.go
index 4118ec4..f0d9be3 100644
--- a/examples/go/echo_server.go
+++ b/examples/go/echo_server.go
@@ -22,7 +22,7 @@
type EchoImpl struct{}
func (echo *EchoImpl) EchoString(inValue *string) (outValue *string, err error) {
- log.Println(*inValue)
+ log.Printf("server: %s\n", *inValue)
return inValue, nil
}
diff --git a/mojo/go/BUILD.gn b/mojo/go/BUILD.gn
index 212bcd3..172ec06 100644
--- a/mojo/go/BUILD.gn
+++ b/mojo/go/BUILD.gn
@@ -60,7 +60,7 @@
":go_sample_app",
]
}
- go_shared_library("go_sample_app") {
+ go_mojo_application("go_sample_app") {
sources = [
"sample_app/app.go",
]
@@ -98,11 +98,10 @@
]
deps = [
":application",
- ":bindings",
":platform_cgo",
+ "//examples/echo",
"//mojo/edk/system",
"//mojo/public/interfaces/bindings/tests:test_interfaces",
- "//examples/echo",
]
}
}
diff --git a/mojo/go/rules.gni b/mojo/go/rules.gni
index a3daafe..40047b7 100644
--- a/mojo/go/rules.gni
+++ b/mojo/go/rules.gni
@@ -91,22 +91,22 @@
}
}
-template("go_shared_library") {
+template("go_mojo_application") {
# Only available on android for now.
assert(is_android)
assert(defined(invoker.sources))
assert(go_build_tool != "")
static_library_name = target_name + "_static_library"
-
static_library(static_library_name) {
complete_static_lib = true
deps = invoker.deps
}
- action(target_name) {
+ go_library_name = target_name + "_go"
+ action(go_library_name) {
deps = [
- ":$static_library_name",
+ ":${static_library_name}",
]
script = "//mojo/go/go.py"
inputs = invoker.sources
@@ -134,4 +134,16 @@
"-ldflags=-shared",
] + rebase_path(invoker.sources, build_dir)
}
+
+ copy(target_name) {
+ deps = [
+ ":${go_library_name}",
+ ]
+ sources = [
+ "${target_out_dir}/${go_library_name}",
+ ]
+ outputs = [
+ "${root_out_dir}/${target_name}.mojo",
+ ]
+ }
}
diff --git a/mojo/go/sample_app/README.txt b/mojo/go/sample_app/README.txt
index eff1179..ba807c7 100644
--- a/mojo/go/sample_app/README.txt
+++ b/mojo/go/sample_app/README.txt
@@ -34,12 +34,6 @@
$ ninja -C out/android_Debug go_sample_app
To run the app:
-1) configure port forwarding 4444 -> localhost:4444 on android device or
- use 10.0.2.2 instead of 127.0.0.1 if you are running an android emulator
-2) open new terminal and run
-$ cd out/android_Debug
-$ python -m SimpleHTTPServer 4444
-3) in the previous terminal run
-$ mojo/tools/android_mojo_shell.py --url-mappings="mojo:go_sample_app"="http://127.0.0.1:4444/obj/mojo/go/go_sample_app" "mojo:go_sample_app"
+$ mojo/tools/android_mojo_shell.py --enable-multiprocess mojo:go_sample_app
More inforamtion about building mojo: https://github.com/domokit/mojo/blob/master/README.md