mirror of
https://github.com/golang/go
synced 2024-11-18 18:04:46 -07:00
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>
This commit is contained in:
parent
0f7f54c9d9
commit
b5ed9db83f
@ -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
|
||||
}
|
||||
|
41
go/gcexportdata/gcexportdata_test.go
Normal file
41
go/gcexportdata/gcexportdata_test.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
BIN
go/gcexportdata/testdata/errors-ae16.a
vendored
Normal file
BIN
go/gcexportdata/testdata/errors-ae16.a
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user