1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:08:36 -06:00
Commit Graph

24 Commits

Author SHA1 Message Date
Bryan C. Mills
c17b040389 all: skip tests if required tools are not found
Fixes golang/go#33950

Change-Id: Iefcb757e773bc052793611c099c25a457fd7e243
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192400
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-30 15:40:57 +00:00
Alan Donovan
aa46a01996 go/ssa/ssautil: add AllPackages method
In go1.10, go/packages falls back to loading all packages
from source but not typechecking function bodies for imports.
The ssautil.Packages function would nonetheless provide
the partially-typed ASTs to the SSA builder, which would crash.
Now Packages only passes syntax trees to the SSA builder for
the initial packages, which are the only ones guaranteed to be
fully typed.

It is impossible to discern whether the caller of Packages intends to
build SSA code for dependencies, as in some clients such as
cmd/callgraph, so we add a new function, AllPackages, that expresses
this intent.

Fixes golang/go#28106

Change-Id: I6a88b7c7545e9de90b61f5bee0e6de3d2e21b548
Reviewed-on: https://go-review.googlesource.com/c/141686
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-15 18:41:29 +00:00
Bryan C. Mills
9fb5a2f241 all: set GO111MODULE=off for tests that use GOPATHs in testdata.
Some users may set GO111MODULE=on, and we will eventually want to be able to
build x/tools itself in module mode.

Updates golang/go#27858
Updates golang/go#27852

Change-Id: Iaf488b2a89e6526471530245cb580f1f0391a770
Reviewed-on: https://go-review.googlesource.com/137815
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-10-03 17:21:27 +00:00
Michael Matloob
0aa4b8830f go/packages: remove the Config.Error hook
Errors relating to a particular package (as opposed to the Load
operation as a whole) are now only recorded in the Errors
field of the corresponding Package.
Clients are responsible for printing or otherwise handling errors.
This is a breaking API change.

The PrintErrors function prints all accumulated errors,
dependencies first, and is provided for convenience.

PrintErrors is based on Visit, another helper function, which
visits each Package in an import graph.

Also:
- add an Example documenting typical use.
- update clients to handle errors explicitly.

Depends on https://go-review.googlesource.com/c/tools/+/130576

Change-Id: I39407ab7f46dae2f0dd0fdde21080e172e1258aa
Reviewed-on: https://go-review.googlesource.com/131015
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-09-04 20:52:37 +00:00
Alan Donovan
87c7dcbd5d cmd/callgraph: temporarily disable failing tests on go1.10
go1.10 and earlier versions of go list do not report test main packages.
Furthermore, go/packages has errors in its Imports under go1.10.

The long-term fix is for go/packages to synthesize test main packages
when working with older versions of the go command, but in the
meantime we will disable the tests.

Updates golang/go#11811

Change-Id: Ifd5e37d5b68a01134e911fda90e30a39fc25b88d
Reviewed-on: https://go-review.googlesource.com/129175
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-13 17:53:22 +00:00
Alan Donovan
1bd72987c2 cmd/callgraph: use go/packages
Because go/packages presents each synthesized test main package
as a first-class package, the tests now analyze all of the dependencies
of "testing", which they previously avoided.  This makes the tests
slower and the resulting call graph much larger,
so they now look for a subset match, not an exact match,
on the set of graph edges.

Change-Id: I9d7acf420e41cbffc03ca8423f5afb3ef671d775
Reviewed-on: https://go-review.googlesource.com/128695
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-08-09 16:04:36 +00:00
Dmitri Shuralyov
5831d16d18 cmd/callgraph: fix "import path of the enclosing package" example in usage
Caller is *ssa.Function. Its Pkg field is *ssa.Package. But ssa.Package
struct doesn't contain either field or method named Object.

So one gets the following error:

	$ callgraph -format '{{.Caller.Pkg.Object.Path}} -> {{.Callee.Pkg.Object.Path}}' \
	    $(go env GOROOT)/src/net/http/triv.go | sort | uniq
	callgraph: template: -format:1:9: executing "-format" at <.Caller.Pkg.Object.P...>: can't evaluate field Object in type *ssa.Package

ssa.Package contains Pkg field:

	Pkg     *types.Package    // the corresponding go/types.Package

types.Package contains Path() method that returns the package path.

That appears to be the right way to get the "import path of the
enclosing package" with the current x/tools/go/ssa API.

Fixes golang/go#20459.

Change-Id: I3cb7b61b767148f5c771d57f8f5e7e6ab20aea87
Reviewed-on: https://go-review.googlesource.com/43812
Reviewed-by: Avelino <t@avelino.xxx>
Reviewed-by: Alan Donovan <adonovan@google.com>
2017-08-08 14:46:45 +00:00
David R. Jenni
718875e4f9 x/tools: simplify and format code
Semi-mechanical changes using gofmt -s
and honnef.co/go/tools/cmd/gosimple.

Change-Id: I41bcf4bea5b16c4776b7cf6534b76aa59b3c022d
Reviewed-on: https://go-review.googlesource.com/37447
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-28 14:15:42 +00:00
Alan Donovan
8e53eb937b go/ssa: support custom TestMain functions in test packages
Supporting user-defined TestMain functions requires that we generate a
"testmain" package for each testable package, rather than a single one
for the entire program.  This entails these API changes:

1. (*ssa.Program).{CreateTestMainPackage,FindTests} both now
   accept only a single package.  Existing clients that pass them
   multiple packages must call them from a loop.

2. (*ssa.Program).FindTests returns an additional result, the the
   optional TestMain *ssa.Function.  Existing clients may discard it.

Also:
- Test the new logic using the SSA interpreter
- add ssautil.MainPackages helper
- callgraph: allow multiple main packages, and analyze them all
- ssadump -run: allow multiple main/test packages, and run each in a new interpreter
- minor simplifications to some callers (e.g. guru)

Fixes golang/go#9553

Change-Id: Ia7de9bd27448fb08b8d172ba5cdbcf37a762b7a0
Reviewed-on: https://go-review.googlesource.com/25102
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-10-19 17:50:59 +00:00
Alan Donovan
c0008c5889 x/tools/cmd/callgraph: add -ptalog flag
Since this tool is a handy way to run the pointer analysis during debugging.

Change-Id: If9a62f71dd8651ad6c782ead85bb84f09c703cba
Reviewed-on: https://go-review.googlesource.com/17382
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-04 17:49:28 +00:00
Alan Donovan
afcda55b39 go/ssa: rename some API features (incompatible change)
Rename the following exported names:
	(*Program).BuildAll → Build
	(*Program).Method   → MethodValue
	Package.Object      → Pkg
Also:
	(*Function).pkgobj  → pkg

Change-Id: Iff7e6c240ebe6786ba759278ac0daa3d66698013
Reviewed-on: https://go-review.googlesource.com/14134
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-08-31 22:20:12 +00:00
Robert Griesemer
d02228d185 cmd/callgraph: exclude test for Android
For golang/go#11811.

Change-Id: I4cec398a0a6d43f3297c205f73193522928a5b31
Reviewed-on: https://go-review.googlesource.com/13280
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-06 01:46:44 +00:00
Alan Donovan
8ccf558e8a cmd/callgraph: update flag docstring
And add a TODO.

Change-Id: I51c63b32e9ac4309cdfb8228348a5d528f36a919
Reviewed-on: https://go-review.googlesource.com/10489
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-05-29 17:21:31 +00:00
Alan Donovan
ee9a07d373 go/buildutil: TagsFlag provides a flag.Value for setting build.Context.BuildTags from -tags flag.
Add -tags flag to oracle, ssadump, callgraph, gomvpkg, gorename, eg.

Change-Id: I4a818501b2331c4ea589caca37a3ad9d381dc8af
Reviewed-on: https://go-review.googlesource.com/9172
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-23 14:10:21 +00:00
Alan Donovan
9c57c19a58 go/loader: eliminate ImportFromBinary option and PackageCreated hook
The loader package now loads, parses, and type-checks a whole program
from source, and that is all.

Also:
- simplified loader logic
- ssa.Create is gone; use ssautil.CreateProgram.
- ssautil.LoadPackage renamed to BuildPackage.
  It is now independent of go/types' Import hook and the Packages map.
- ssadump: -importbin flag removed.
  The value of this flag was that it caused the tool to print IR
  for only a single package; this is now the normal behaviour.

Fixes #9955

Change-Id: I4571118258ab1a46dccece3241b7dc51401a3acc
Reviewed-on: https://go-review.googlesource.com/8953
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-04-17 18:58:17 +00:00
Alan Donovan
69db398fe0 go/loader: rename SourceImports flag to ImportFromBinary and invert sense
...since the zero value is more useful by far.

This is a breaking API change, obviously.  (One or two tests in this
CL have intentional been left using the zero value, i.e., they now
load source.)

Change-Id: I42287bfcdb1afef8ee84e5eac12534dd0a1fd5d2
Reviewed-on: https://go-review.googlesource.com/5653
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-23 23:01:10 +00:00
Alan Donovan
159ae4d163 cmd/callgraph: fix careless quoting bug
Change-Id: I809a2ea711bb1a516dfcf8abf5e4d26061b4daf0
Reviewed-on: https://go-review.googlesource.com/4230
Reviewed-by: Sameer Ajmani <sameer@golang.org>
2015-02-09 17:53:43 +00:00
Alan Donovan
e079f6c632 go/ssa: change import path of synthetic test package to "test$main"
...to avoid namespace conflicts.
Also make its name "main", since it defines func main().

And fix 2 typos.

Change-Id: I7cf7894d6bed134907b3d2742255e5a82426071b
Reviewed-on: https://go-review.googlesource.com/3150
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-21 22:21:01 +00:00
David Symonds
24257c8cd2 tools: add import comments.
Change-Id: Idda6e64580432cb9a731e4ebf4005ee4ceb4202d
Reviewed-on: https://go-review.googlesource.com/1244
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 22:42:16 +00:00
Alan Donovan
a9651d6ad7 cmd/callgraph: add -algo=static and -algo=cha options.
"static" ignores dynamic calls altogether.

"cha" uses Class Hierarchy Analysis, which assumes that a
dynamic call may dispatch to any func or method that satisfies
the type.

Both these algorithms can work on partial programs,
e.g. libraries without a main function or tests.

(This feature was requested after my talk last night.)

+ Tests.

LGTM=sameer
R=sameer, minux
CC=golang-codereviews, gri
https://golang.org/cl/176780043
2014-11-21 11:07:56 -05:00
Alan Donovan
4162082cba x/tools/*: print program name, not "Error", when reporting command error messages.
Such messages are more informative when the error occurs deep within a script.

Also: add tool name to digraph's usage messages.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/173380043
2014-11-17 12:58:28 -05:00
Alan Donovan
c13d674f5e go/callgraph/rta: rename from go/rta
LGTM=sameer
R=sameer
CC=golang-codereviews, gri
https://golang.org/cl/175770043
2014-11-14 11:02:44 -05:00
Robert Griesemer
c2b324b9b4 cmd/callgraph: fix build
TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/171640043
2014-11-12 16:49:47 -08:00
Alan Donovan
b8a5fcfcec cmd/callgraph: a utility for dumping the callgraph of a Go program.
(This functionality is provided by the oracle, but its output
format is inflexible, and the functionality is better suited
to a shell utility.  I may remove the oracle 'callgraph' feature.)

See Usage for details.

+ Test.

LGTM=sameer
R=sameer
CC=golang-codereviews, gri
https://golang.org/cl/164460044
2014-11-12 17:36:22 -05:00