{veyron,veyron2}/services/mgmt/build: enabling cross-compilation for
the build service
Change-Id: Ied50ff15b32a58b581e637c3ef172d4de9bd83b1
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index 6084b70..65b3311 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -50,9 +50,10 @@
}
func invokeBuild(t *testing.T, client build.Build, files []build.File) ([]byte, []build.File, error) {
- stream, err := client.Build(rt.R().NewContext())
+ arch, opsys := getArch(), getOS()
+ stream, err := client.Build(rt.R().NewContext(), arch, opsys)
if err != nil {
- t.Errorf("Build() failed: %v", err)
+ t.Errorf("Build(%v, %v) failed: %v", err, arch, opsys)
return nil, nil, err
}
for _, file := range files {
diff --git a/services/mgmt/build/impl/invoker.go b/services/mgmt/build/impl/invoker.go
index fb5bed9..1548c59 100644
--- a/services/mgmt/build/impl/invoker.go
+++ b/services/mgmt/build/impl/invoker.go
@@ -36,8 +36,11 @@
// TODO(jsimsa): Add support for building for a specific profile
// specified as a suffix the Build().
-func (i *invoker) Build(_ ipc.ServerContext, stream build.BuildServiceBuildStream) ([]byte, error) {
- vlog.VI(1).Infof("Build() called.")
+//
+// TODO(jsimsa): Analyze the binary files for shared library
+// dependencies and ship these back.
+func (i *invoker) Build(_ ipc.ServerContext, arch build.Architecture, opsys build.OperatingSystem, stream build.BuildServiceBuildStream) ([]byte, error) {
+ vlog.VI(1).Infof("Build(%v, %v) called.", arch, opsys)
dir, prefix := "", ""
dirPerm, filePerm := os.FileMode(0700), os.FileMode(0600)
root, err := ioutil.TempDir(dir, prefix)
@@ -70,6 +73,8 @@
return nil, errInternalError
}
cmd := exec.Command(i.gobin, "install", "-v", "...")
+ cmd.Env = append(cmd.Env, "GOARCH="+archString(arch))
+ cmd.Env = append(cmd.Env, "GOOS="+osString(opsys))
cmd.Env = append(cmd.Env, "GOPATH="+filepath.Dir(srcDir))
var output bytes.Buffer
cmd.Stdout = &output
@@ -87,8 +92,6 @@
vlog.Errorf("ReadDir(%v) failed: %v", binDir, err)
return nil, errInternalError
}
- // TODO(jsimsa): Analyze the binary files for shared library
- // dependencies and ship these back.
for _, file := range files {
binPath := filepath.Join(root, "go", "bin", file.Name())
bytes, err := ioutil.ReadFile(binPath)