Merge "veyron/services/mgmt/build: the build server should not fail if the compiled package produces no binaries"
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index a60b1e8..fd45724 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -120,6 +120,39 @@
}
}
+const fooSrc = `package foo
+
+import "fmt"
+
+func foo() {
+ fmt.Println("Hello World!")
+}
+`
+
+// TestEmpty checks that the build server successfully builds a
+// package that does not produce a binary.
+func TestEmpty(t *testing.T) {
+ client, cleanup := startServer(t)
+ defer cleanup()
+
+ files := []build.File{
+ build.File{
+ Name: "test/foo.go",
+ Contents: []byte(fooSrc),
+ },
+ }
+ output, bins, err := invokeBuild(t, client, files)
+ if err != nil {
+ t.FailNow()
+ }
+ if got, expected := strings.TrimSpace(string(output)), "test"; got != expected {
+ t.Fatalf("Unexpected output: got %v, expected %v", got, expected)
+ }
+ if got, expected := len(bins), 0; got != expected {
+ t.Fatalf("Unexpected number of binaries: got %v, expected %v", got, expected)
+ }
+}
+
// TestFailure checks that the build server fails to build a package
// consisting of an empty file.
func TestFailure(t *testing.T) {
diff --git a/services/mgmt/build/impl/invoker.go b/services/mgmt/build/impl/invoker.go
index 82de34a..fb5bed9 100644
--- a/services/mgmt/build/impl/invoker.go
+++ b/services/mgmt/build/impl/invoker.go
@@ -83,12 +83,12 @@
}
binDir := filepath.Join(root, "go", "bin")
files, err := ioutil.ReadDir(binDir)
- if err != nil {
+ if err != nil && !os.IsNotExist(err) {
vlog.Errorf("ReadDir(%v) failed: %v", binDir, err)
return nil, errInternalError
}
- // TODO(jsimsa): Analyze the binary files for non-standard shared
- // library dependencies.
+ // 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)