From: Josh Bleecher Snyder Date: Thu, 2 Mar 2017 17:04:03 +0000 (-0800) Subject: cmd/vet: support importing from source X-Git-Tag: go1.9beta1~1339 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ddbee9abd45bbb955fec973fc0e395276127d431;p=gostls13.git cmd/vet: support importing from source Add a -source flag to cmd/vet that instructs it to typecheck purely from source code. Updates #16086 Fixes #19332 Change-Id: Ic83d0f14d5bb837a329d539b2873aeccdf7bf669 Reviewed-on: https://go-review.googlesource.com/37690 Reviewed-by: Rob Pike --- diff --git a/src/cmd/vet/doc.go b/src/cmd/vet/doc.go index 5cbe116abe..1ee44a43fc 100644 --- a/src/cmd/vet/doc.go +++ b/src/cmd/vet/doc.go @@ -34,6 +34,9 @@ If any flags are explicitly set to true, only those tests are run. Conversely, i any flag is explicitly set to false, only those tests are disabled. Thus -printf=true runs the printf check, -printf=false runs all checks except the printf check. +By default vet uses the object files generated by 'go install some/pkg' to typecheck the code. +If the -source flag is provided, vet uses only source code. + Available checks: Assembly declarations diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 3da0b3ccf5..ec4cb72797 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -25,6 +25,7 @@ import ( var ( verbose = flag.Bool("v", false, "verbose") + source = flag.Bool("source", false, "import from source instead of compiled object files") tags = flag.String("tags", "", "space-separated list of build tags to apply when parsing") tagList = []string{} // exploded version of tags flag; set in main ) diff --git a/src/cmd/vet/types.go b/src/cmd/vet/types.go index f1927738c4..3a5e71c87c 100644 --- a/src/cmd/vet/types.go +++ b/src/cmd/vet/types.go @@ -61,7 +61,11 @@ func importType(path, name string) types.Type { func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error { if stdImporter == nil { - stdImporter = importer.Default() + if *source { + stdImporter = importer.For("source", nil) + } else { + stdImporter = importer.Default() + } inittypes() } pkg.defs = make(map[*ast.Ident]types.Object)