diff --git a/go/gcexportdata/gcexportdata.go b/go/gcexportdata/gcexportdata.go index 99d79d81388..99a1eca1e77 100644 --- a/go/gcexportdata/gcexportdata.go +++ b/go/gcexportdata/gcexportdata.go @@ -25,6 +25,7 @@ package gcexportdata // import "golang.org/x/tools/go/gcexportdata" import ( "bufio" + "bytes" "fmt" "go/token" "go/types" @@ -76,6 +77,13 @@ func Read(in io.Reader, fset *token.FileSet, imports map[string]*types.Package, 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 00000000000..69133db9752 --- /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 00000000000..3f1dad54f07 Binary files /dev/null and b/go/gcexportdata/testdata/errors-ae16.a differ