veyron/tools/*: Remove dependence on rt.R()/rt.Init()

Change-Id: I2dd04028a2eaefdf99efa1177926dada7d54f91c
diff --git a/tools/build/impl.go b/tools/build/impl.go
index a4b9b87..e03779f 100644
--- a/tools/build/impl.go
+++ b/tools/build/impl.go
@@ -6,13 +6,12 @@
 	"io/ioutil"
 	"os"
 	"path/filepath"
-	"runtime"
+	goruntime "runtime"
 	"strings"
 	"time"
 
 	"veyron.io/lib/cmdline"
 	"veyron.io/veyron/veyron2/context"
-	"veyron.io/veyron/veyron2/rt"
 	vbuild "veyron.io/veyron/veyron2/services/mgmt/build"
 )
 
@@ -22,8 +21,8 @@
 )
 
 func init() {
-	cmdBuild.Flags.StringVar(&flagArch, "arch", runtime.GOARCH, "Target architecture.")
-	cmdBuild.Flags.StringVar(&flagOS, "os", runtime.GOOS, "Target operating system.")
+	cmdBuild.Flags.StringVar(&flagArch, "arch", goruntime.GOARCH, "Target architecture.")
+	cmdBuild.Flags.StringVar(&flagOS, "os", goruntime.GOOS, "Target operating system.")
 }
 
 var cmdRoot = &cmdline.Command{
@@ -140,7 +139,6 @@
 	binaries := make(chan vbuild.File)
 	go func() {
 		defer close(binaries)
-		rt.Init()
 		client := vbuild.BuilderClient(name)
 		stream, err := client.Build(ctx, vbuild.Architecture(flagArch), vbuild.OperatingSystem(flagOS))
 		if err != nil {
@@ -211,7 +209,7 @@
 	cancel, errchan := make(chan struct{}), make(chan error)
 	defer close(errchan)
 
-	ctx, ctxCancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, ctxCancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer ctxCancel()
 
 	// Start all stages of the pipeline.
diff --git a/tools/build/impl_test.go b/tools/build/impl_test.go
index 2778896..4f4d3f7 100644
--- a/tools/build/impl_test.go
+++ b/tools/build/impl_test.go
@@ -5,6 +5,7 @@
 	"strings"
 	"testing"
 
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/naming"
 	"veyron.io/veyron/veyron2/rt"
@@ -39,8 +40,8 @@
 
 type dispatcher struct{}
 
-func startServer(t *testing.T) (ipc.Server, naming.Endpoint) {
-	server, err := rt.R().NewServer()
+func startServer(runtime veyron2.Runtime, t *testing.T) (ipc.Server, naming.Endpoint) {
+	server, err := runtime.NewServer()
 	if err != nil {
 		t.Fatalf("NewServer failed: %v", err)
 	}
@@ -62,8 +63,12 @@
 }
 
 func TestBuildClient(t *testing.T) {
-	rt.Init()
-	server, endpoint := startServer(t)
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	server, endpoint := startServer(runtime, t)
 	defer stopServer(t, server)
 
 	cmd := root()
diff --git a/tools/build/main.go b/tools/build/main.go
index 9e5d556..66c4112 100644
--- a/tools/build/main.go
+++ b/tools/build/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }