CL 239754 eagerly initialized the environment. This turns out to be a
problem for gopls, which calls ApplyFixes with no ProcessEnv.
Reinitializing it every time seriously harmed the performance of
unimported completions. Move back to lazy initialization.
Working with invalid options has caused a lot of confusion; this is only
the most recent. We have to maintain backwards compatibility in the
externally visible API, but everywhere else we can require fully
populated options. That includes the source byte slice and the options.
LocalPrefix is really more of an Option than an attribute of the
ProcessEnv, and it is needed in ApplyFixes where we really don't want to
have to pass a ProcessEnv. Move it up to Options.
Change-Id: Ib9466c375a640a521721da4587091bf93bbdaa3c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241159
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The existing flag parsing logic doesn't initialize a ProcessEnv struct,
which results in a nil dereference when trying to access the LocalPrefix
property. The fix is to initialize the default options with an initialized
ProcessEnv.
Fixes#39862
Change-Id: I57cff249d6bf0ced6bb70e53174b2515fe9fbb97
GitHub-Last-Rev: 2d6e5f3af226088ddc4ed88198edd5c5ea469240
GitHub-Pull-Request: golang/tools#239
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240019
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
This CL got away from me a little.
For a number of reasons, the existing goimports API of passing in values
for various GO* values was not working. For one, the number of necessary
variables kept growing. For another, we tried to avoid calling `go env`
in GOPATH mode by using `build.Default`, but that turns out to be buggy;
see golang/go#39838. And finally, it created massive confusion about
whether the values were intended to be read from the OS environment, or
fully evaluated by the `go` command.
There are only two users of the internal imports API, so there really
shouldn't need to be more than two modes. For the command line tool, we
have to call `go env` to deal with the `go/build` bug. So we just do it.
Tests use that same path, but can augment the enviroment to set
themselves up. In contrast, `gopls` needs to fully specify the
environment. It can simply pass in the fully evaluated GO* values.
Finally, make the change I was actually here to make: propagate
GOMODCACHE and use it where appropriate.
Fixesgolang/go#39761.
Change-Id: I720c69839d91d66d98e94dfc5f065ba0279c5542
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239754
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Many tools test check for the ability to compile cgo programs.
Consolidate them all into testenv.NeedsTool("cgo").
Change-Id: I62c96e7b4dc72df34b8fdbf10326c7d19e0613e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/234108
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
As of Go 1.14, WriteFile on Windows will set read-only on existing files
if you pass 0 for perms. Pass the pre-existing permissions.
Updates golang/go#38225.
Change-Id: I3174469efd4dc4c7eacc8522386a0712cfa39d11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229297
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Without the bug fix, you get ## followed by #### in the file.
Change-Id: I6af85debf4bc84f9e346732b5641eb3a4e7d7e83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223602
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Accepting Markdown in present is nice, but the job isn't done unless we
actually convert all our existing blog files to the new format. Otherwise we
have two different kinds of files to understand when working in that
directory. This tool lets us mechanically convert all the existing blog articles.
For golang/go#33955.
Change-Id: If8a8dd90eefa171f422644134d0571e2abe4c7cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222847
Reviewed-by: Rob Pike <r@golang.org>
In all cases, use a Logf field to configure debug logging. Non-nil means
that logging is enabled through the given function.
Fixes accidental debug spam from goimports, which had a separate Debug
flag that was supposed to guard logging, but wasn't used when creating
the gocommand.Invocation.
Change-Id: I448fa282111db556ac2e49801268d0affc19ae30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221557
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
While investigating golang/go#36664, the entire output of a failure
could get pretty long - past fifty lines of content. I was getting
confused as to why the output was being cut off.
I had to discard a number of theories (the test being buggy, my expected
output being wrong, etc) before I realised that something was truncating
the output for the sake of the reader.
Since that's what stress is doing, make it add an ellipsis character
too, to further hint to the user that the output is being truncated for
readability. Separate it with a newline to make it easier to notice.
Change-Id: Ie052c13bb48d6fd842d6054848161266d9ea17e6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/215597
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
In a certain case, stringer would generate the following check for an
an unsigned integer i: "0 <= i". This changes stringer to not generate
such a check.
Also adds an additional test case for an unsigned multiple run that does
not include zero. There was already a case ("unum") that included an
unsigned multiple run starting at zero. This case's output was updated
accordingly.
Fixesgolang/go#36461
Change-Id: I57e79384a0b802fa4571e2b3495db168b814bcaa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/214180
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
gopls should always be built in module mode from the gopls module. I
don't think that anyone is relying on this anymore, and we should stop
allowing users to build gopls from within the tools module.
Change-Id: I7dea4339d4c8ffc4ca168e679b810be743e5f92c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212520
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Error positions should be printed, when specified.
Also, made main_test less picky about whitespace before and after
error output.
After this change, the test for cmd/fiximports should pass before and
after CL 210938.
Updates golang/go#36087
Change-Id: I681d1ee07f7f19a0d9716b88678e2737f4c691de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211337
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
goimports now wants various module flags, but I forgot to set them up in
the many places we create environments. Do so.
Change-Id: Ic3817caeb8fc4d564b49006ef6ca6842b2498eaf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211581
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
I have moved this extension out of this repository and into
https://github.com/stamblerre/gopls-debug. It is now published in the VS
Code marketplace. We weren't really doing anything with this, so there's
no need to keep it in this repo. Future integration-related code should
live in golang.org/x/tools/gopls/integration.
Change-Id: Id01e1d55d141a7305fa688a72f8c9ccbee0e28c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208997
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The autocert.go file in x/tools was deleted in CL 162400, but some
related variables were left behind. This change deletes them, since
they are unused by now. (If you're feeling déjà vu, it's likely
because this was done in x/website in CL 197957.)
Updates golang/go#29206
Updates golang/go#32011
Change-Id: I070f711e8bbc7b54f1d169571356fdc24bc00137
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208259
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
When the GOMOD value is the operating system's null device, there
isn't a main module. Return an empty build list right away, since
running 'go list -m all' in Go 1.14 will cause a "cannot match "all":
working directory is not part of a module" error.
Fixesgolang/go#35690
Updates golang/go#35728
Change-Id: I024ca3b7d774835140ce4a1625133aff6554a533
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208258
Reviewed-by: Bryan C. Mills <bcmills@google.com>
The canonical home for the golang.org website by now is
the golang.org/x/website/cmd/golangorg command. That is
the command that should be used to run the website locally
instead of godoc.
This change reduces the scope of x/tools/cmd/godoc to be
a minimal Go Documentation Server. It removes the remaining
pieces of the golang.org website and changes the title from
"The Go Programming Language" to "Go Documentation Server".
The web tree is modified as follows:
• The index page has been modified to redirect to /pkg/,
which serves a list of packages.
• The /doc/ tree is removed.
• The /robots.txt and /opensearch.xml pages are removed, since
the primary use case for godoc now is a local web server.
• The Google Analytics sections are removed from static templates,
since it's always an empty value in local web server mode.
Fixesgolang/go#32011
Updates golang/go#29206
Change-Id: Id62c5f335fa2059774893ef4dcd268649278e99d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207777
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
There's currently a bug which will print additional lines, since append adds to
the end of an array instead of starting from the first open position. That cause
strings.Join to print empty lines for each of the pre-allocated array elements.
So, this CL changes the make to set capacity instead of len, and sets len to 0.
Change-Id: Iaf6d07ca2648d0bbcafcd21a5b485cccd7f0c68c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208137
Run-TryBot: Jean de Klerk <deklerk@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Focus prints the subgraph of all paths through the focused label.
Change-Id: I20fa9fb079f733addcd3cec85aa608f4979fdb24
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184357
Reviewed-by: Jay Conrod <jayconrod@google.com>
When the GOMOD value is the operating system's null device, there
isn't a main module and thus there cannot be module requirements.
Don't try to fill module cache, since running 'go mod download'
would cause a "no modules specified (see 'go help mod download')"
error to be printed, which is confusing.
Fixesgolang/go#35476
Change-Id: Ia1f5ee50797a4dc3e36c3b9773e19da781bd9d39
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206886
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Test function is added for formatNs function in the benchcmp package.
Change-Id: I9a1050be9fba3b5e217741d3faadbf5d913d1d4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206857
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This change implements initial support for viewing Go package
documentation with godoc in module mode. There are no UI changes.
When running the godoc binary in a directory where module mode
is active (i.e., go env GOMOD reports a non-empty path), the
documentation will be shown for packages provided by modules
rather than from the GOPATH workspace.
The mode can be controlled in the same way as the go command, by
changing the GO111MODULE environment variable¹ value. For example,
'GO111MODULE=on godoc' will force godoc to run in module mode, and
'GO111MODULE=off godoc' will force godoc to run in GOPATH mode.
It is implemented by reusing the existing virtual filesystem
abstraction. The main module and all of its dependencies (in
other words, the build list²) are determined by invoking the
go list -m all command in the same directory. An attempt is
made to fill the module cache with any selected module versions
that are not already in the local module cache.
This behavior can be controlled in the same way as the go command,
by setting the GOPROXY environment variable. For example, setting
GOPROXY=off disables downloading of any modules. If any of the
modules could not be fetched, it is printed to stderr and
documentation is shown for all other available packages.
¹ https://golang.org/cmd/go/#hdr-Module_support
² https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_listFixesgolang/go#33655
Change-Id: I86f795537b65acae3771afd19d2e7cb360425467
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196983
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Adds a "-tags" flag that'll allow build tags
to be passed in and added to the very top of the
generated and bundled file.
For example, when generating h2_bundle.go for
net/http, we'll now be able to do:
bundle -tags '!nethttpomithttp2' -o h2_bundle.go
-prefix http2 golang.org/x/net/http2
Updates golang/go#35082
Change-Id: I55edd7227aec8641b60ba560c79e0d50d0692d52
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205017
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL 191309 broke it by adding a newline before the package clause.
Change-Id: Ic039649734ae086a891227b5926e028fe7e62325
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204137
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Currently, vertices are referred to as nodes in (most) user-facing
documentation, and labels in the code itself (and some user-facing
documentation). This CL changes all references to vertices to use the word node.
Change-Id: I0a409c08122f198b11ff891cbea24b41aba89e40
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200938
Reviewed-by: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
After godoc stopped being part of the Go distribution, the location
of the godoc binary and the go binary can be different. Hence the old
GOROOT finding logic does not work anymore.
We shell out to "go env GOROOT" to return the new GOROOT.
Fixesgolang/go#23445
Change-Id: I16e4c0798e3f5cda13d9f6546cf82808a10c4a0b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/199279
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
CL 196979 moved the pollInterval sleep to the bottom of the loop
with the intent of not sleeping before the first readiness check,
but that caused an unintended consequence of the sleep being skipped
when errors happen. Move it back to the top to avoid that problem.
Change-Id: Ia63f09afe47d93df657ca867ceecc4d7df6abccc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197940
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change converts cmd/godoc tests to use the packagestest package
in its basic integration tests. For now, those tests continue to run
in GOPATH mode only. When module support is added to cmd/godoc, then
the same tests will be made to run in module mode too.
Previously, the basic integration test covered godoc functionality
on Go packages in GOROOT only. This change also adds some third
party packages to increase test coverage. This is easy to do with
the packagestest API.
Updates golang/go#33655
Change-Id: If3fce913140b81ed9340556d6bb4b963f5f98813
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196981
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Previously, the waitForServer family of helpers would wait anywhere
between 15 seconds to 2 minutes for the server to become ready.
But if there's a problem that results in the server exiting early,
that wasn't being detected quickly.
This change modifies tests to also wait for command to exit,
and fail the test quickly if so. This helps during development.
Updates golang/go#33655
Change-Id: I16195715449015d7250a2d0de5e55ab9a1ef078d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196979
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
I got tired of spurious 'git' diffs while a 'go test' was running, so
I fixed the test that produced the diffs. (We need to do that anyway
in order to run them in the module cache, plus it's just good hygiene
not to have tests interfering with each other's sources.)
Tested using:
$ chmod -R ugo-w . && go test ./...; chmod -R u+w .
Updates golang/go#28387
Change-Id: Ie17e31aecf0e3cb022df5503d7c443000366a5c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192577
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>