wire: use go/packages for analysis (google/go-cloud#623)
Unfortunately, this does come with a ~4x slowdown to Wire, as it is now pulling source for all transitively depended packages, but not trimming comments or function bodies. This is due to limitations with the ParseFile callback in go/packages. This comes with a single semantic change: when performing analysis, Wire will now evaluate everything with the wireinject build tag. I updated the build tags tests accordingly. Prior to this PR, only the packages directly named by the package patterns would be evaluated with the wireinject build tag. Dependencies would not have the wireinject build tag applied. There isn't a way to selectively apply build tags in go/packages, and there isn't a clear benefit to applying it selectively. Being consistent with other Go tooling provides greater benefit. I deleted the vendoring test, as non-top-level vendoring becomes obsolete with modules. go/packages now parses comments by default, so now the generated code includes comments for non-injector declarations. Fixes google/go-cloud#78
This commit is contained in:
@@ -44,11 +44,11 @@ type call struct {
|
||||
// out is the type this step produces.
|
||||
out types.Type
|
||||
|
||||
// importPath and name identify the provider to call for kind ==
|
||||
// pkg and name identify the provider to call for kind ==
|
||||
// funcProviderCall or the type to construct for kind ==
|
||||
// structProvider.
|
||||
importPath string
|
||||
name string
|
||||
pkg *types.Package
|
||||
name string
|
||||
|
||||
// args is a list of arguments to call the provider with. Each element is:
|
||||
// a) one of the givens (args[i] < len(given)), or
|
||||
@@ -199,7 +199,7 @@ dfs:
|
||||
}
|
||||
calls = append(calls, call{
|
||||
kind: kind,
|
||||
importPath: p.ImportPath,
|
||||
pkg: p.Pkg,
|
||||
name: p.Name,
|
||||
args: args,
|
||||
fieldNames: p.Fields,
|
||||
@@ -419,7 +419,7 @@ func verifyAcyclic(providerMap *typeutil.Map, hasher typeutil.Hasher) []error {
|
||||
fmt.Fprintf(sb, "cycle for %s:\n", types.TypeString(a, nil))
|
||||
for j := i; j < len(curr); j++ {
|
||||
p := providerMap.At(curr[j]).(*ProvidedType).Provider()
|
||||
fmt.Fprintf(sb, "%s (%s.%s) ->\n", types.TypeString(curr[j], nil), p.ImportPath, p.Name)
|
||||
fmt.Fprintf(sb, "%s (%s.%s) ->\n", types.TypeString(curr[j], nil), p.Pkg.Path(), p.Name)
|
||||
}
|
||||
fmt.Fprintf(sb, "%s\n", types.TypeString(a, nil))
|
||||
ec.add(errors.New(sb.String()))
|
||||
|
||||
Reference in New Issue
Block a user