mirror of
https://github.com/golang/go
synced 2024-11-05 15:16:11 -07:00
refactor/importgraph: don't ignore imports in packages with errors.
And in gomvpkg, don't stop just because some packages had errors. This is inevitable in a large GOPATH tree. Fixes issue golang/go#10907 Change-Id: I9a60b070228d06d44880202eeef54394e914f5d5 Reviewed-on: https://go-review.googlesource.com/10715 Reviewed-by: Sameer Ajmani <sameer@golang.org>
This commit is contained in:
parent
f671283c22
commit
a9866431ad
@ -54,7 +54,8 @@ func (g Graph) Search(roots ...string) map[string]bool {
|
|||||||
// Build scans the specified Go workspace and builds the forward and
|
// Build scans the specified Go workspace and builds the forward and
|
||||||
// reverse import dependency graphs for all its packages.
|
// reverse import dependency graphs for all its packages.
|
||||||
// It also returns a mapping from import paths to errors for packages
|
// It also returns a mapping from import paths to errors for packages
|
||||||
// that could not be loaded.
|
// whose loading was not entirely successful.
|
||||||
|
// A package may appear in the graph and in the errors mapping.
|
||||||
func Build(ctxt *build.Context) (forward, reverse Graph, errors map[string]error) {
|
func Build(ctxt *build.Context) (forward, reverse Graph, errors map[string]error) {
|
||||||
type importEdge struct {
|
type importEdge struct {
|
||||||
from, to string
|
from, to string
|
||||||
@ -75,14 +76,17 @@ func Build(ctxt *build.Context) (forward, reverse Graph, errors map[string]error
|
|||||||
ch <- pathError{path, err}
|
ch <- pathError{path, err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bp, err := ctxt.Import(path, "", 0)
|
bp, err := ctxt.Import(path, "", 0)
|
||||||
if _, ok := err.(*build.NoGoError); ok {
|
|
||||||
return // empty directory is not an error
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if _, ok := err.(*build.NoGoError); ok {
|
||||||
|
// empty directory is not an error
|
||||||
|
} else {
|
||||||
ch <- pathError{path, err}
|
ch <- pathError{path, err}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
// Even in error cases, Import usually returns a package.
|
||||||
|
}
|
||||||
|
if bp != nil {
|
||||||
for _, imp := range bp.Imports {
|
for _, imp := range bp.Imports {
|
||||||
ch <- importEdge{path, imp}
|
ch <- importEdge{path, imp}
|
||||||
}
|
}
|
||||||
@ -92,6 +96,7 @@ func Build(ctxt *build.Context) (forward, reverse Graph, errors map[string]error
|
|||||||
for _, imp := range bp.XTestImports {
|
for _, imp := range bp.XTestImports {
|
||||||
ch <- importEdge{path, imp}
|
ch <- importEdge{path, imp}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -61,11 +61,12 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
|
|||||||
// Build the import graph and figure out which packages to update.
|
// Build the import graph and figure out which packages to update.
|
||||||
fwd, rev, errors := importgraph.Build(ctxt)
|
fwd, rev, errors := importgraph.Build(ctxt)
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
|
// With a large GOPATH tree, errors are inevitable.
|
||||||
|
// Report them but proceed.
|
||||||
fmt.Fprintf(os.Stderr, "While scanning Go workspace:\n")
|
fmt.Fprintf(os.Stderr, "While scanning Go workspace:\n")
|
||||||
for path, err := range errors {
|
for path, err := range errors {
|
||||||
fmt.Fprintf(os.Stderr, "Package %q: %s.\n", path, err)
|
fmt.Fprintf(os.Stderr, "Package %q: %s.\n", path, err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to construct import graph")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the affected packages---the set of packages whose import
|
// Determine the affected packages---the set of packages whose import
|
||||||
|
@ -254,6 +254,8 @@ func Main(ctxt *build.Context, offsetFlag, fromFlag, to string) error {
|
|||||||
// Scan the workspace and build the import graph.
|
// Scan the workspace and build the import graph.
|
||||||
_, rev, errors := importgraph.Build(ctxt)
|
_, rev, errors := importgraph.Build(ctxt)
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
|
// With a large GOPATH tree, errors are inevitable.
|
||||||
|
// Report them but proceed.
|
||||||
fmt.Fprintf(os.Stderr, "While scanning Go workspace:\n")
|
fmt.Fprintf(os.Stderr, "While scanning Go workspace:\n")
|
||||||
for path, err := range errors {
|
for path, err := range errors {
|
||||||
fmt.Fprintf(os.Stderr, "Package %q: %s.\n", path, err)
|
fmt.Fprintf(os.Stderr, "Package %q: %s.\n", path, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user