go/gcexportdata: support old export data (again), needed by AE1.6
+ test
Change-Id: I0842795ece634e4441b17a10009d26bfc2a8481a
Reviewed-on: https://go-review.googlesource.com/31818
Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/go/gcexportdata/gcexportdata.go b/go/gcexportdata/gcexportdata.go
index 99d79d8..99a1eca 100644
--- a/go/gcexportdata/gcexportdata.go
+++ b/go/gcexportdata/gcexportdata.go
@@ -25,6 +25,7 @@
import (
"bufio"
+ "bytes"
"fmt"
"go/token"
"go/types"
@@ -76,6 +77,13 @@
if err != nil {
return nil, fmt.Errorf("reading export data for %q: %v", path, err)
}
+
+ // The App Engine Go runtime v1.6 uses the old export data format.
+ // TODO(adonovan): delete once v1.7 has been around for a while.
+ if bytes.HasPrefix(data, []byte("package ")) {
+ return gcimporter.ImportData(imports, path, path, bytes.NewReader(data))
+ }
+
_, pkg, err := gcimporter.BImportData(fset, imports, data, path)
return pkg, err
}
diff --git a/go/gcexportdata/gcexportdata_test.go b/go/gcexportdata/gcexportdata_test.go
new file mode 100644
index 0000000..69133db
--- /dev/null
+++ b/go/gcexportdata/gcexportdata_test.go
@@ -0,0 +1,41 @@
+package gcexportdata_test
+
+import (
+ "go/token"
+ "go/types"
+ "log"
+ "os"
+ "testing"
+
+ "golang.org/x/tools/go/gcexportdata"
+)
+
+// Test to ensure that gcexportdata can read files produced by App
+// Engine Go runtime v1.6.
+func TestAppEngine16(t *testing.T) {
+ // Open and read the file.
+ f, err := os.Open("testdata/errors-ae16.a")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ r, err := gcexportdata.NewReader(f)
+ if err != nil {
+ log.Fatalf("reading export data: %v", err)
+ }
+
+ // Decode the export data.
+ fset := token.NewFileSet()
+ imports := make(map[string]*types.Package)
+ pkg, err := gcexportdata.Read(r, fset, imports, "errors")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Print package information.
+ got := pkg.Scope().Lookup("New").Type().String()
+ want := "func(text string) error"
+ if got != want {
+ t.Errorf("New.Type = %s, want %s", got, want)
+ }
+}
diff --git a/go/gcexportdata/testdata/errors-ae16.a b/go/gcexportdata/testdata/errors-ae16.a
new file mode 100644
index 0000000..3f1dad5
--- /dev/null
+++ b/go/gcexportdata/testdata/errors-ae16.a
Binary files differ