1
0
mirror of https://github.com/golang/go synced 2024-11-07 08:46:19 -07:00
Commit Graph

2910 Commits

Author SHA1 Message Date
Michael Stapelberg
138c20b932 go/callgraph/rta: fix comment
Change-Id: I52d37297118f9e99f3a71d3a9cf47a01da4aa72c
Reviewed-on: https://go-review.googlesource.com/c/38260
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-09 15:26:31 +00:00
Nicholas Ng
8542fc29bd go/ssa: updated inconsistent docs after Program.Method rename
Fixes golang/go#20225

Change-Id: Ifd069546698981f3c6a3673dd73a1bd770560f8b
Reviewed-on: https://go-review.googlesource.com/c/42570
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-09 15:25:51 +00:00
matematik7
84d77ece31 cmd/bundle: permit empty -prefix
This enables bundling of programs with `main` method to single file.
I used this to upload code for the new codejam.

Change-Id: I9e65ba8717c1d81d6fb9bef8f234c21fc5b91421
GitHub-Last-Rev: 5d0d623c46ff1629e7371693ddf0916df328e319
GitHub-Pull-Request: golang/tools#32
Reviewed-on: https://go-review.googlesource.com/c/105515
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-09 15:23:16 +00:00
Alan Donovan
879803d4ad go/analysis/passes/unmarshal: port vet's unmarshal checker
The checker has been modified to avoid making two memory allocations
for every CallExpr in the program.

Originally: https://go-review.googlesource.com/c/139997
Updates golang/go#27564

Change-Id: I168869272a1d78d47d84c049aba619bb223cad70
Reviewed-on: https://go-review.googlesource.com/c/148562
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-09 14:28:11 +00:00
Alan Donovan
77439c5518 go/analysis/passes/shadow: add shadow command
In vet, the shadow check is experimental, meaning not on by default.
The new analysis API has no concept of experimental, but you can
easily supply a different checker. By providing a shadow command, we
make it easy for users that want it to run it:

  $ go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
  $ go vet -vettool $(which shadow) my/project

Change-Id: I25dc7f3c830296121c7217e4615e8ff90e1b7c79
Reviewed-on: https://go-review.googlesource.com/c/148565
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-08 22:19:41 +00:00
Fazlul Shahriar
5b8b0ce6cc go/packages: pass TestConfigDefaultEnv on Plan 9
Change-Id: Ice0d44c97dc76bf0ebfe433577d55eb6763cb6d3
Reviewed-on: https://go-review.googlesource.com/c/132601
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 22:19:39 +00:00
Alan Donovan
fc0741f0ff go/analysis/printf: delete
The printf checker is in the passes/ subdirectory.

Change-Id: I0a912231280bc954fee3088050541ba5ecb17dde
Reviewed-on: https://go-review.googlesource.com/c/148571
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 21:04:34 +00:00
Alan Donovan
353f99afd4 go/analysis/passes/cgocall: fix typo in comment
Change-Id: Ie71f93c1fa0d5e7de498ad2af611c4db8a27171d
Reviewed-on: https://go-review.googlesource.com/c/148561
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-08 19:46:55 +00:00
Alan Donovan
e5d4b58ff5 go/analysis/passes/cgocall: analyze raw cgo files (again)
The cgocall analyzer was originally written in vet to analyze "raw" cgo files,
which are type-checked on a best-effort basis.  However, the go/analysis
API presents analyzers with "cooked" cgo files, which are well-typed
legal Go but obscure the relationship between a call C.f(...) and its arguments.
Prior to this CL, cgocall attempted to "uncook" the file, which was
as predictably fragile as it sounds, and it rapidly broke as the cgo
recipe evolved.

This change causes cgocall to parse, modify, type-check and analyze "raw"
cgo files. The approach (based on dot-importing the "cooked" package)
is rather too clever but should be more robust than the one it replaces.

Fixes golang/go#28566

Change-Id: I3092a313c64d27153eaaa115fe8635abfed17023
Reviewed-on: https://go-review.googlesource.com/c/147317
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-08 19:39:40 +00:00
Brad Fitzpatrick
dfbbb7b6d4 go/packages, go/analysis/internal/unitchecker: skip broken tests for now
Updates golang/go#28609
Updates golang/go#28676

Change-Id: Id0fbc6cb0ce14aed9b20afcd0488708df33d5a62
Reviewed-on: https://go-review.googlesource.com/c/148637
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 18:34:11 +00:00
Rebecca Stambler
c26e340d2f internal/lsp: refactor completion and move into source directory
The completion function belongs in internal/lsp/source, so move it
there. Some small refactoring of completion, by moving each type of
completion into helper functions that append to the list of results.

Change-Id: I8599092906609591d499183657fe2d21d1f74df1
Reviewed-on: https://go-review.googlesource.com/c/148397
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-08 16:15:53 +00:00
Heschi Kreinick
a28dfb48e0 revert "imports: create named imports for name/path mismatches"
This reverts CL 145699 (commit 864069cfd1)

Reason for revert: If the mismatch is bad enough that goimports can't find
it again, then the import is just removed, even if the user adds it back again.

Fixes #28645.

Change-Id: I6c8fc5434c2b56c73b260bcec2c12d8746fac4ad
Reviewed-on: https://go-review.googlesource.com/c/148237
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-07 22:50:58 +00:00
Dmitri Shuralyov
4ca49954c3 go/ast/astutil: allow AddNamedImport to add imports with different names
This change makes AddNamedImport more symmetrical to DeleteNamedImport
in behavior, signature, and documentation.

In Go, it is valid to import a package (identified by an import path)
with different names in a single .go file¹. For example, this is ok,
and the program will build as long as there are no unused imports²:

	import (
		"path"
		. "path"
		_ "path"
		pathpkg "path"
	)

The four imports (represented by ast.ImportSpec type) have the same
import path, but different names.

It's currently possible to use DeleteNamedImport to delete the exact
{name, import path} ast.ImportSpec from an AST.

Previously, it wasn't possible to use AddNamedImport to add an exact
{name, import path} ast.ImportSpec if the AST already has another
ast.ImportSpec with the same import path (but different name).
This change fixes that, making it possible to use AddNamedImport as
expected.

Rename the ipath parameter to path in AddNamedImport for consistency
with DeleteNamedImport. Also change the language used in its
documentation to be more precise and consistent with DeleteNamedImport.

Add test cases for this behavior. The DeleteNamedImport test cases
were passing before any changes to the astutil code.

Add test coverage for the return bool value of {Add,Delete}NamedImport.
Document the behavior of DeleteNamedImport when there are duplicate
matching imports.

Simplify string(buf.Bytes()) to buf.String() in test helper code.

¹ https://golang.org/ref/spec#Import_declarations
² https://play.golang.org/p/bi6L34rQbcD

Fixes golang/go#28605
Fixes golang/go#16411

Change-Id: I70e887f5174764ab1cf32a761c8c734e216eea67
Reviewed-on: https://go-review.googlesource.com/c/147448
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-07 22:33:19 +00:00
Michael Matloob
34b416bd17 go/packages: change the driverResponse.Sizes to have type StdSizes
This will allow Sizes to be marshalled and unmarshalled. All the Sizes
we care about ane StdSizes anyways.

Change-Id: I79d1dcaebba32f7730de4375945e372eeefa78fe
Reviewed-on: https://go-review.googlesource.com/c/147978
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-07 21:56:32 +00:00
Heschi Kreinick
42c3d2e9aa internal/gopathwalk: ignore $GOROOT/.../vendor/ in module mode
go list in module mode doesn't like looking at vendor directories in
GOROOT. Skip them.

Change-Id: Iec501fbab70914ea6dd76dcbed97ecda461358d0
Reviewed-on: https://go-review.googlesource.com/c/148159
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-07 20:51:50 +00:00
Heschi Kreinick
864069cfd1 imports: create named imports for name/path mismatches
For clarity and performance reasons, we want the fast path of goimports
to be purely syntactic. Packages whose import paths don't match their
package names make this harder. Before this CL, we parsed each imported
package to get its real package name. Now, we make named imports for
such packages, and on subsequent runs we don't have to do the extra
work.

A package name matches its import path if the name is the last segment
of the path, or the next-to-last before a version suffix vNN. gopkg.in
style .vNN suffixes are considered mismatching.

goimports already had almost exactly the desired logic, but only when
adding a new import. So the bulk of this change is simply removing the
logic that allowed it to recognize that a mismatched import satisfied
some uses. With that gone, it will remove those imports as unused, then
add a new renamed import. Some comments may be destroyed.

Fixes golang/go#28428

Change-Id: I53846e6046affb420f41719f84c71086c5b9e5e6
Reviewed-on: https://go-review.googlesource.com/c/145699
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-07 19:53:05 +00:00
Ian Cottrell
15ad1aa0cb internal/lsp: implement go to definition
This enables go to definition for the lsp.
It has one known non working case (where the filenames have $GOROOT in them)

Change-Id: I142c6e04b8691c5076dfcd55592ea710b4b361a4
Reviewed-on: https://go-review.googlesource.com/c/148158
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:43:41 +00:00
Ian Cottrell
d0600fd9f1 internal/lsp: make source independent of protocol
I realized this was a mistake, we should try to keep the source
directory independent of the LSP protocol itself, and adapt in
the outer layer.
This will keep us honest about capabilities, let us add the
caching and conversion layers easily, and also allow for a future
where we expose the source directory as a supported API for other
tools.
The outer lsp package then becomes the adapter from the core
features to the specifics of the LSP protocol.

Change-Id: I68fd089f1b9f2fd38decc1cbc13c6f0f86157b94
Reviewed-on: https://go-review.googlesource.com/c/148157
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:42:35 +00:00
Michael Matloob
aa0cdd1ef5 go/packages: remove contains: query. it's been superceeded by file=
Change-Id: I472787d50e799ef0ee663168201933dd70a1a487
Reviewed-on: https://go-review.googlesource.com/c/147977
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-07 16:12:02 +00:00
Michael Matloob
e21233ffa6 go/packages: remove unnecessary TODO
See adonovan's comment here:
https://go-review.googlesource.com/c/tools/+/146757/6/go/packages/golist.go#330

Change-Id: I7885fc1e7787c6b265be345f8622476b69d14325
Reviewed-on: https://go-review.googlesource.com/c/147447
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-06 21:36:28 +00:00
Rebecca Stambler
6f4a86804e internal/lsp: add implementation of completion to LSP
Add an autocompletion implementation to the LSP. Also, add a function
that type-checks a package at a certain position, returning an *ast.File
and token.Pos for querying completion.

Change-Id: I288d4e6ed168e6014e79a4436f31f5b4a99b7139
Reviewed-on: https://go-review.googlesource.com/c/147657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-06 21:04:51 +00:00
Michael Matloob
78dc5bac0c go/packages: determine sizes by calling go list
This is more reliable than looking in the environment.

Change-Id: I96c093b89faaece6b6256eefb4a4aac4d66b9cc9
Reviewed-on: https://go-review.googlesource.com/c/146757
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-05 23:00:42 +00:00
Ian Cottrell
e504f914a8 internal/lsp: make file a first class concept
A file is strongly associated with a view, and knows how to manage it's own
contents.
We can also now track files that are not "active"

Change-Id: Ib9474cd40e5caa3db6596548612a9f90168b8a19
Reviewed-on: https://go-review.googlesource.com/c/147204
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-05 21:38:40 +00:00
Ian Cottrell
9b5bafe36f internal/lsp: extract view to its own package
This allows us to write the lsp verbs in terms of a stable underlying source
management layer.
This should make it easier to refactor the underlying layer to add more powerful
caching and incremental modes as we go.

Change-Id: Iab97b061d80394a6fa6748a93a4c68f2deb46129
Reviewed-on: https://go-review.googlesource.com/c/147201
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-05 21:38:13 +00:00
Ainar Garipov
f1b4bd93c9 go/ssa: fix vet issues
The new go/analysis/cmd/vet tool found a few issues. Fix them by
explicitly ignoring results where needed and renaming examples in
accordance to package testing's guidelines to make them appear on the
godoc pages.

This change doesn't touch go/ssa/interp/external.go because the
possible misuse of package unsafe there looks intentional.

Change-Id: Id63109e3797818a5e869fe8ed1bc1476959541f2
Reviewed-on: https://go-review.googlesource.com/c/147297
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-05 21:34:10 +00:00
Ian Cottrell
fc67db3d9a go/packages: fix crash
This is based on 147340 and has the same test, but with a different fix.
We now produce a nice error if there is an empty root, instead of
crashing, and the cause of empty roots in go list has been fixed.
The underlying call to go list is returning the same package more than
once, and we only fix the first entry in the root list, so the second
one got left blank.
The fix was to not add the second duplicate copy to the output of the
driver at all.

Change-Id: I9f1b2f0fd63635ba101cdd3c8a5108530e968ba9
Reviewed-on: https://go-review.googlesource.com/c/147440
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-05 21:21:22 +00:00
Rebecca Stambler
c76e1ad98a internal/lsp: add copyright notices to files that were missing them
Change-Id: Ifb3bedeed7a38366da234b2329c4078931d1a208
Reviewed-on: https://go-review.googlesource.com/c/147441
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-05 19:56:57 +00:00
Rebecca Stambler
ebdbadb46e internal/lsp: fix LSP tests to be compatible with Go 1.10
Change golang/go#145697 added tests for diagnostics in the LSP implementation,
but these test did not work with Go 1.10. This change skips tests that
require Go 1.11.

Change-Id: I52bd2df484b5786395edac2c1c8592c83ac1aaa4
Reviewed-on: https://go-review.googlesource.com/c/147439
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-05 19:42:43 +00:00
Ian Cottrell
96e9e165b7 cmd/golsp: format logging for the lsp inspector
This improves the logging capabilities of the jsonrpc 2 library to always
include the method and also an optional elapsed time.
This is used to implement an lsp inspector compatible logging mode in the golsp.

Change-Id: I2f7ac8b9298c4364b1b89cf6f696b534557ed139
Reviewed-on: https://go-review.googlesource.com/c/146157
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-02 22:32:51 +00:00
Heschi Kreinick
1a6034dbfc go/packages: small fixes
For performance, bail out of runNamedQueries before running go env if
there's nothing to do.

Add t.Helper() calls to packagestest.TestAll.

Escape # in packagestest.Export. The testing package adds #NN suffixes
to subtests that have redundant names.

Log how long gopathwalk.Walk took for name= queries when debug is on.

Change-Id: I37cb0ed11cf58e1693e29dea04697e5885ecc62b
Reviewed-on: https://go-review.googlesource.com/c/147203
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 22:11:10 +00:00
Rebecca Stambler
f7a8a58e8d internal/lsp: use packagestest markers to test diagnostics
Add some basic tests for diagnostics using the new
go/packages/packagestest framework.

Change-Id: I6a7bfba6c392928a9eb123ab71ceb73785c12600
Reviewed-on: https://go-review.googlesource.com/c/145697
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 21:57:01 +00:00
Heschi Kreinick
633a9364ed go/packages: disable network, improve debug logging
When the name= query constructs the temporary module, it may find things
that don't resolve. In at least some cases (#28518), allowing go list
to access the network results in not just bad performance but actual
failures. Default GOPROXY to "off" when doing queries on the temporary
module to try to address that.

Also, add some more debug logging, including various environment
variables, so that it's easier to reproduce failing commands.

Change-Id: I1a6d3ffa5c845271ce48e9fe802a2491ccadcd7c
Reviewed-on: https://go-review.googlesource.com/c/146477
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 21:01:51 +00:00
Alan Donovan
c3ef14e642 go/analysis/passes/cgocall: disable test in go1.12
The test correctly identified a problem.
Suppressing test to keep dashboard cleean, pending a fix.

Updates golang/go#28566

Change-Id: Ib3a8dbdd617c9f5701b5d6673434917d284dfb32
Reviewed-on: https://go-review.googlesource.com/c/147199
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 19:56:55 +00:00
Alan Donovan
896f44f055 go/analysis/.../unitchecker: suppress test unless go1.12
Change-Id: I1af89b9e077cf7eddeeeed72e66cd88f650492a2
Reviewed-on: https://go-review.googlesource.com/c/147197
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
2018-11-02 19:17:09 +00:00
Ian Cottrell
619897c5a2 go/packages/packagestest: add marker support
This adds a library that allows markers and actions inside comments in go source
files.
It then also adds an easy way to use that library for tests using packagestest.Expect
This is used to easily write code inspection and manipulation tests in a
language that is common to all tests.

Change-Id: I755caaad1557c9b8779ad9ecda2b3309550d6976
Reviewed-on: https://go-review.googlesource.com/c/142998
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 18:21:53 +00:00
Alan Donovan
15a0f8a7f1 go/analysis/internal/unitchecker: a 'go vet'-compatible driver
Also:
- add cmd/vet-lite, a version of cmd/vet that doesn't depend on
  go/packages and must be run under "go vet". This will be vendored
  into $GOROOT/src/cmd/vet.
- add an integration test for a unitchecker-based command under "go vet".

Change-Id: Id613dac2812816c6d6372fa6d1536c8d4e4c2676
Reviewed-on: https://go-review.googlesource.com/c/143418
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 17:49:05 +00:00
Agniva De Sarker
92b943e6bf cmd/tip: enable playground on tip.golang.org
Updates golang/go#28536

Change-Id: I3ece72aacd4635f4580be404672394a47791a1e8
Reviewed-on: https://go-review.googlesource.com/c/146917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-02 05:00:50 +00:00
Ian Cottrell
d51e88b5ae go/packages: make visit order stable
Change-Id: Iee9b29364dd986e1f1676ff0aa989267c4149c30
Reviewed-on: https://go-review.googlesource.com/c/146357
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 02:37:01 +00:00
David Symonds
45ff765b48 cmd/stringer: accept simple type conversion expressions in constant ValueSpec
This permits constants of the form `const X = T(A)` to add `X` to the
stringer output for type `T`.

While those constants can be rewritten as `const X T = T(A)`, that
becomes tedious and visually noisy when `T` is a long name. It is quite
easy to address this easy and common case, while not attempting to solve
this with full generality.

Fixes #11581.

Change-Id: Ifb8e43515f05493de190e02577260d94dd851581
Reviewed-on: https://go-review.googlesource.com/c/146577
Run-TryBot: David Symonds <dsymonds@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-11-01 07:19:27 +00:00
Ian Cottrell
3a10b9bf0a go/packages: change so no results are sorted
We do insist that drivers are stable (not sorted, just stable) and that
refine is also stable, which allows us to promise a stable output.
I also changed refine so it returns the root set in the same order that
the original root id list was supplied, as this seems to be a strictly
better experience.

Change-Id: I8eb0bffd7547865d14a6c6f18646018b9af140bd
Reviewed-on: https://go-review.googlesource.com/c/145877
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-10-31 16:53:50 +00:00
Heschi Kreinick
6c7e314b65 go/packages/packagestest: make versioned modules
If a Module's Name ends with a version suffix (v2), create its module
with an appropriate version number (v2.0.0).

Change-Id: I1a16f054fac5717e79871ba1bf9a6343c0ce2f5b
Reviewed-on: https://go-review.googlesource.com/c/146097
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-10-30 22:17:26 +00:00
Paul Jolly
240a8bfde1 cmd/stringer: move away from using os.Args[0]
stringer's usage currently uses os.Args[0] to refer to the program name
as a defensive measure in case stringer is compiled and then run using a
name other than stringer, e.g. mystringer. However, the following lines
of the usage docs hardcode "stringer." So it seems this has little
benefit.

Indeed this style of using os.Args[0] can make the usage information of
stringer extremely ugly when stringer itself is invoked with an absolute
path:

Usage of /tmp/tmp.ahddh3ZjE7/.gobincache/golang.org/x/tools/@v/v0.0.0-20181030000716-a0a13e073c7b/golang.org/x/tools/cmd/stringer/stringer:
        stringer [flags] -type T [directory]
        stringer [flags] -type T files... # Must be a single package

...

Instead, opt for the simpler approach of hardcoding stringer throughout.

Change-Id: Ia296c8d9a91c94e77b7cc2b6242908c959fb5985
Reviewed-on: https://go-review.googlesource.com/c/145799
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2018-10-30 21:27:03 +00:00
Ian Cottrell
bb28844c46 go/packages: make packagestest.Export call t.Helper
Change-Id: Ib95ab480899ee14fb8ae841b0210734ecbc0d0d9
Reviewed-on: https://go-review.googlesource.com/c/145698
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-10-30 15:17:51 +00:00
Heschi Kreinick
a0a13e073c imports: make tests compatible with modules
Tweak the goimports tests to be more module-compatible. This should be
the last big change to the tests; they all pass with the new
implementation.

The primary change is to avoid using packages not provided by the test's
modules. Other modules will be downloaded at test time, which is
nonhermetic and quite slow.

Other miscellanea:

- The appengine grouping tests have to be split out so
they can be GOPATH-only, because modules have to have dots in their
names.
- The tests for .goimportsignore and node_modules are GOPATH-only
because we decided not to include those behaviors in go/packages in
module mode.
- Some vendoring tests are GOPATH-only because vendoring is not a thing
in module mode.
- TestFindImportInLocalGoFiles changes content, because the existing
test was incorrect: bogus.net/bytes was a viable candidate even though
it isn't on disk. I'm not sure why it wasn't flaky.

Change-Id: I35a3aac92d3fb7f70a1a8f027f0b423282420a4d
Reviewed-on: https://go-review.googlesource.com/c/145138
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-30 00:07:16 +00:00
Heschi Kreinick
00c5fa5868 go/packages: find mismatched top level packages in name=
Treat the top-level package of a module specially so that the VCS
working dir name doesn't have to match the package name. Generally we
take the position that directory names should match packages, but for
the top-level package that's a pretty strict requirement. Now we always
check the top-level directory, just in case.

Change-Id: I2e96751bf46736fbaef434fa9788fdc1339c37b9
Reviewed-on: https://go-review.googlesource.com/c/144817
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-30 00:03:57 +00:00
Ian Cottrell
2d2de62981 go/packages: sort root list in Load
The builders are currently flaky failing because of a root order being
wrong.
This causes all root lists to be sorted before being returned, so the
order is always stable no matter which underlying driver is running.

Fixes golang/go#27594

Change-Id: I09db45c67ad00f23dfaec8e271acbd13fc338888
Reviewed-on: https://go-review.googlesource.com/c/143737
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-29 18:14:17 +00:00
Alan Donovan
9aea6da185 go/analysis/internal/facts: fact serialization support
Package facts provides an implementation of the Import/Export methods
of the analysis.Pass interface and functions to encode and decode
facts, using Gob encoding, to a file. It will be part of the vet-lite
driver (invoked by go vet) but the same logic has been validated in
other build systems such as Blaze.

Change-Id: I60ef561e84e833b9a3b17c269ab358e7d0800ff3
Reviewed-on: https://go-review.googlesource.com/c/144737
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-10-29 17:32:15 +00:00
Heschi Kreinick
f60e5f99f0 go/packages/packagestest: use a module proxy
Instead of writing replace directives to link the test's modules
together, fill a GOPROXY dir and use `go mod download` to fill a real
GOCACHE with them. This makes the tests more realistic, since replace
directives will be somewhat unusual. It also gives the name= query
something to search.

Actually doing this in a way that's compatible with packagestest's
abstraction is a little tricky, since it wants to know where the files
will be. The actual files will be created by go mod download, so we have
to get Export to put them there to begin with, then move them out of the
way.

Since the GOPROXY zip format doesn't support symlinks, those will only
work in the primary module.

Change-Id: I6bc1d368f1c950d789e409213107d60bb1389802
Reviewed-on: https://go-review.googlesource.com/c/144498
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-10-26 18:38:34 +00:00
Heschi Kreinick
e74f1bd585 imports: port tests to packagestest
I tried to introduce new modules where it made sense. I deleted the
weird goroot test because I removed the optimization it was testing in
an earlier CL.

Change-Id: I219ddaa4f462a4aeb640f62215d16f246511a5fe
Reviewed-on: https://go-review.googlesource.com/c/144497
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-26 18:23:19 +00:00
Brad Fitzpatrick
a2dc47679d Revert "imports: support repairing import grouping/ordering"
This reverts commit CL 116795 12a7c317e8.

Reason for revert: mangles comments in imports. See comments
on issue golang/go#20818.

Updates golang/go#20818

Change-Id: Iff82f8dc310dceb982b48d82b26176ea279fef10
Reviewed-on: https://go-review.googlesource.com/c/144339
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2018-10-24 17:12:08 +00:00