mirror of
https://github.com/golang/go
synced 2024-11-18 20:54:40 -07:00
go/packages: allow Load to use source if no export data is possible
We ask the underlying tool to produce export data if needed, but if it cant we should fall back to source rather than just failing. Change-Id: I376d41b4c8ad4d3c1aef3ca4ab4e3d0466b83b56 Reviewed-on: https://go-review.googlesource.com/126875 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
cfaff8d5db
commit
ade7853a2a
@ -17,9 +17,10 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/tools/go/gcexportdata"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/gcexportdata"
|
||||
)
|
||||
|
||||
// A LoadMode specifies the amount of detail to return when loading packages.
|
||||
@ -296,11 +297,6 @@ func (ld *loader) load(patterns ...string) ([]*Package, error) {
|
||||
// See if the extra process invocation can be avoided.
|
||||
list, err := listfunc(rawCfg, patterns...)
|
||||
if _, ok := err.(GoTooOldError); ok {
|
||||
if ld.Config.Mode >= LoadTypes {
|
||||
// Upgrade to LoadAllSyntax because we can't depend on the existance
|
||||
// of export data. We can remove this once iancottrell's cl is in.
|
||||
ld.Config.Mode = LoadAllSyntax
|
||||
}
|
||||
listfunc = golistPackagesFallback
|
||||
list, err = listfunc(rawCfg, patterns...)
|
||||
}
|
||||
@ -358,8 +354,7 @@ func (ld *loader) loadFrom(list ...*rawPackage) ([]*Package, error) {
|
||||
GoFiles: pkg.GoFiles,
|
||||
OtherFiles: pkg.OtherFiles,
|
||||
},
|
||||
// TODO: should needsrc also be true if pkg.Export == ""
|
||||
needsrc: ld.Mode >= LoadAllSyntax,
|
||||
needsrc: ld.Mode >= LoadAllSyntax || pkg.Export == "",
|
||||
}
|
||||
ld.pkgs[lpkg.ID] = lpkg
|
||||
if !pkg.DepOnly {
|
||||
|
@ -533,13 +533,12 @@ func TestTypeCheckError(t *testing.T) {
|
||||
wantTypes bool
|
||||
wantSyntax bool
|
||||
wantIllTyped bool
|
||||
wantErrs []string
|
||||
}{
|
||||
{"a", true, true, true, nil},
|
||||
{"b", true, true, true, nil},
|
||||
{"c", true, true, true, []string{"could not import d (no export data file)"}},
|
||||
{"d", false, false, true, nil}, // missing export data
|
||||
{"e", false, false, false, nil}, // type info not requested (despite type error)
|
||||
{"a", true, true, true},
|
||||
{"b", true, true, true},
|
||||
{"c", true, true, true},
|
||||
{"d", false, false, true}, // missing export data
|
||||
{"e", false, false, false}, // type info not requested (despite type error)
|
||||
} {
|
||||
if usesOldGolist && test.id == "c" || test.id == "d" || test.id == "e" {
|
||||
// Behavior is different for old golist because it upgrades to wholeProgram.
|
||||
@ -568,9 +567,6 @@ func TestTypeCheckError(t *testing.T) {
|
||||
if p.IllTyped != test.wantIllTyped {
|
||||
t.Errorf("IllTyped was %t for %s", p.IllTyped, test.id)
|
||||
}
|
||||
if errs := errorMessages(p.Errors); !reflect.DeepEqual(errs, test.wantErrs) {
|
||||
t.Errorf("in package %s, got errors %s, want %s", p, errs, test.wantErrs)
|
||||
}
|
||||
}
|
||||
|
||||
// Check value of constant.
|
||||
|
Loading…
Reference in New Issue
Block a user