godoc is erroneously detecting paths like syscall and unsafe as possible
commands.
A previous attempt at a fix adjusted the parameters of pkgHandler in
pres.go, but that change had unexpected ripple effects that broke links
and other features of godoc. This change is scoped only to the godoc
command line tool.
cmdline_test.go is updated to match the parameters used in the real
pkgHandler in pres.go.
Fixesgolang/go#14447
Change-Id: I8f740c6847e46523b8443722b16942192bdf9cb8
GitHub-Last-Rev: cfc24f2d4c3519c4c87628b2021f65a4725cda6b
GitHub-Pull-Request: golang/tools#27
Reviewed-on: https://go-review.googlesource.com/96515
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The gccgo compiler does not provide a gc-style GOROOT with standard
library sources. The effect is that guru may not fully work when using
gccgo. However, it can fully work if the GOROOT environment variable
points to valid gc-style GOROOT. In that case, make it work by telling
the go/build package to use gc mode.
Change-Id: Iadff8be61be8cc9a7ff2ca0a067b116b62895451
Reviewed-on: https://go-review.googlesource.com/117997
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
There is one non-test change: have FakeContext change the compiler to
"gc", as callers expect to be accessing a gc-style GOROOT.
The go/pointer, go/ssa, and go/ssa/interp tests still fail with gccgo.
Change-Id: I850c9618401f6b9e63d7ca7196f91931b03f1524
Reviewed-on: https://go-review.googlesource.com/117395
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
When program has no output and vet errors are encountered,
initialize data.Events as an empty array.
Fixesgolang/go#25455.
Change-Id: Icedd77685b784505da3bb6383629cdfa8b8b22e9
Reviewed-on: https://go-review.googlesource.com/113875
Run-TryBot: Yury Smolsky <yury@smolsky.by>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This CL adds a missing closing double-quote to the documentation string
of gomvpkg.
Change-Id: I000fe33fb9ddc5342bbf51c36595a884d6aa4eab
Reviewed-on: https://go-review.googlesource.com/114115
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change adds an error return value to BExportData and replaces the
various calls to log.Fatal within that library with panics that
propagate the internal error up the call stack to BExportData which
recovers and returns the error.
Fixesgolang/go#25431
Change-Id: Id628c63a04145bb469bd6fbc7fbab1b0fa291b2c
Reviewed-on: https://go-review.googlesource.com/113457
Reviewed-by: David Symonds <dsymonds@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This change adds an option to run "go vet" for the playground program
and display errors before any output. To enable this, the playground
function has to be supplied with opts.enableVet set to true.
Vet check is performed only for succesfully run programs,
meaning that the "/compile" endpoint returned no errors.
This change highlights lines printed to stderr as errors (in red).
There is a corresponding change for the Playground: CL 100776.
Updates golang/go#7597
Updates golang/go#24576
Change-Id: I8c0f8c1189c461338b5bce57777b12aecab268fb
Reviewed-on: https://go-review.googlesource.com/107455
Run-TryBot: Yury Smolsky <yury@smolsky.by>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This part of a multi-repo change. See CL 108677 for details.
Note: this change also requires a CL to golang/go to complete the fix,
though either CL without the other is harmless.
Updates golang/go#24997.
Change-Id: I99ca9a4e6df16347b8706f24cef9689b3345854a
Reviewed-on: https://go-review.googlesource.com/108678
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Moved the code which generates static.go to remain in the static package.
This makes the code testable.
Additionally, it is very easy for developers to forget to run "go generate"
to update static.go. Because while development, the templates directory
can be directly passed as a flag to read the files from it.
This test catches that.
Change-Id: I314907b98907bb14e4eabfd3c532ba2d84ce7c5f
Reviewed-on: https://go-review.googlesource.com/110158
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
- Setting the GOROOT build path to the value passed from the command line.
- Clarified the return values to named parameters for extra clarity.
- And while here, added some missed out error handling. Just logging the error
to preserve original behavior.
Fixesgolang/go#13296
Change-Id: I91427eee790928a3cfb51ae207747e9a17bd5496
Reviewed-on: https://go-review.googlesource.com/110275
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
I felt guilty about leaving 2% on the table in CL 108878,
so I thought I'd get it a different way.
Teach readFile to accept a re-usable bytes.Buffer to read into,
to reduce the amount of garbage created.
To limit the possible memory impact of giant files,
only re-use the buffer for the duration of a single package.
Even that is enough to help.
name old time/op new time/op delta
Referrers 4.67s ± 3% 4.58s ± 2% -1.96% (p=0.029 n=10+10)
name old user-time/op new user-time/op delta
Referrers 16.5s ± 3% 15.8s ± 1% -4.39% (p=0.000 n=10+8)
name old sys-time/op new sys-time/op delta
Referrers 16.1s ± 3% 15.9s ± 3% ~ (p=0.218 n=10+10)
This work supported by Sourcegraph.
Change-Id: I594ef25c0fd5ccb766ff5b98dbbd1a75a7a4f957
Reviewed-on: https://go-review.googlesource.com/108935
Reviewed-by: Alan Donovan <adonovan@google.com>
This simplifies and unifies the code.
It also improves the output:
Now the initial result is referred to from the perspective of
the query site, rather than from the perspective of the package
containing the query object, which seems more natural.
This work supported by Sourcegraph.
Change-Id: Ie7a77d39dd6568334e72d894dc66d35494ed4ac4
Reviewed-on: https://go-review.googlesource.com/108936
Reviewed-by: Alan Donovan <adonovan@google.com>
This change parallelizes the outer loop in globalReferrersPkgLevel,
which loops over packages to inspect.
There is also an easily parallelizable inner loop.
However, parallelizing it adds complication
(deffiles needs a mutex, inQueryPackage requires a wait group)
and offers only a 2% speed-up.
Benchmarks for this change, looking for encoding/json.MarshalIndent:
name old time/op new time/op delta
Referrers 5.31s ± 2% 4.67s ± 3% -11.95% (p=0.000 n=10+10)
name old user-time/op new user-time/op delta
Referrers 15.9s ± 2% 16.5s ± 3% +3.71% (p=0.000 n=10+10)
name old sys-time/op new sys-time/op delta
Referrers 15.7s ± 3% 16.1s ± 3% +2.73% (p=0.011 n=10+10)
Fixesgolang/go#24272
Updates golang/go#25017
This work supported by Sourcegraph.
Change-Id: I5dcda9017103cdff59d0ffdf5e87d2c2c955a33a
Reviewed-on: https://go-review.googlesource.com/108878
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Global, package-level queries can be done without typechecking.
This makes it significantly cheaper.
Instead of typechecking, consider all packages that directly
import the query package. In each of those packages, filter out:
* files that don't contain the query name
* files that don't import the query package
Fully parse the remaining files and look for selector expressions
matching the query package and name.
There are a few twists (dot imports, the query package, xtests).
They are described, along with how they are handled,
in the large comment at the beginning of globalReferrersPkgLevel.
On my machine and GOPATH, this reduces typical time
needed to find referrers to encoding/json.MarshalIndent
from (roughly)
real 0m39.946s
user 2m27.844s
sys 0m54.774s
to (roughly)
real 0m5.687s
user 0m15.793s
sys 0m16.001s
The processing of packages could be parallelized;
that is left for a future change, to ease reviewing.
Benefits from that will be limited;
building the reverse import graph accounts for 73%
of the runtime, and that is dominated by syscalls.
Optimization idea from Alan Donovan.
This work supported by Sourcegraph.
Change-Id: Ib19e25fcdcb27673fb03d7300dba2a53198901ad
Reviewed-on: https://go-review.googlesource.com/97800
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
When uploading a new release, it deserializes the payload into
a File struct for processing. It needs the Version field to
determine which release it's in.
Change-Id: I171f416dbb1b1b6c354948ea9a31b9c8694f892e
Reviewed-on: https://go-review.googlesource.com/110627
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Previously, goyacc's line number tracking would run off by one whenever
a multiline comment was used inside of an action, like so:
expr:
TOKEN
{
/* Hello. */
}
This is because the character after the multi-line comment close marker
(i.e., the character immediately after `*/`) was blindly printed out
instead of properly accounted for. A newline character after a
multi-line comment would fail to increment lineno, for example, and any
error messages generated after that point would refer to the wrong line.
Similarly, a variable reference after a multi-line comment, like
$$.val = &someStruct{Value: /* oops */$1}
would copy the $ literally into the resulting Go code. (This was not a
problem in practice because multi-line comments are typically followed
by whitespace.)
Adjust the control flow so the character after the multi-line comment
close marker character gets run through the relevant switch statement
and accounted for.
Change-Id: I276b6ffdb7626101f76811b7ee4804bacc6ef740
Reviewed-on: https://go-review.googlesource.com/110495
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Before this change, findImportGoPath used a field within the
(otherwise read-only) structs in the dirScan map to cache the distance
from the importing package to the candidate package to be imported. As
a result, the top-level imports.Process function was not safe to call
concurrently: one goroutine could overwrite the distances while
another was attempting to sort by them. Furthermore, there were some
internal write-after-write races (writing the same cached distance to
the same address) that otherwise violate the Go memory model.
This change fixes those races, simplifies the concurrency patterns,
and clarifies goroutine lifetimes. The functions in the imports
package now wait for the goroutines they spawn to finish before
returning, eliminating the need for an awkward test-only mutex that
could otherwise mask real races in the production code paths.
See also:
https://golang.org/wiki/CodeReviewComments#goroutine-lifetimeshttps://golang.org/wiki/CodeReviewComments#synchronous-functionsFixesgolang/go#25030.
Change-Id: I8fec735e0d4ff7abab406dea9d0c11d1bd93d775
Reviewed-on: https://go-review.googlesource.com/109156
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
All major browsers support the border-radius directive
without any vendor prefix. Hence, removing them.
https://caniuse.com/#search=border-radius
Change-Id: I2da5f109296df3c7f191df95876bd6849f51d9ae
Reviewed-on: https://go-review.googlesource.com/110155
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
To scale the website elements independently of the default font size,
we use the css rem unit. This scales the elements proportionally if the
user has set a different font size than the default.
We make all calculations assuming that 1rem=16px, which is the
default font size for browsers.
Tested manually on FF 59 and Chrome 65 with permutations of different
resolutions and different default font-sizes upto 36px.
Fixesgolang/go#6150
Change-Id: I7ded227ee2c55178271667009ab98ee0b4e7e8b3
Reviewed-on: https://go-review.googlesource.com/94935
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Support indexed export data in the x/tools gcimporter. Fixes tests with
tip.
This is just a copy of the bimport.go and iimport.go files in the
standard library gcimporter package, including some minor fixes to the
existing bimport.go. The iexport logic in x/tools still needs to be
updated.
Fixesgolang/go#25052
Change-Id: I2858e5c0853735c904f32b7b27c1c288a9e62e88
Reviewed-on: https://go-review.googlesource.com/109595
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Rename to avoid imports/import stutter and export.
It will be used soon by guru's referrers command.
This work supported by Sourcegraph.
Change-Id: Ibfc39d061d6269a336a59d9b6979188a94537d94
Reviewed-on: https://go-review.googlesource.com/108877
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
If test files are not included here,
then results in those files will be missing
for queries within a single package.
This work supported by Sourcegraph.
Change-Id: I8136ea250ba980179228d9b408d9e7409c49a873
Reviewed-on: https://go-review.googlesource.com/97799
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This make it possible to easily run individual guru tests.
It also slightly speeds up the overall test run,
from 23s to 18s on my machine;
the TestGuru/calls is now the limiting factor,
by a significant margin.
This work supported by Sourcegraph.
Change-Id: If61ebf1cc60441a65274f3fddd31f69c7ca23b48
Reviewed-on: https://go-review.googlesource.com/108876
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
It is going to be used by a new tool.
Moved to an internal package so it does not become a publicly supported
api.
Modified the tests so they don't depend on the fix_test infrastructure.
Change-Id: Ib8ebef24dc23e180960af04aa3d06b5f41a7c02b
Reviewed-on: https://go-review.googlesource.com/99678
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL 107155 introduced this bug due to oversight. There can be
a scenario where a folder has no source .go or .c files,
but has an ignored .go file. In that case, both the if conditions
to check the length of pkgfiles slice will evaluate to true.
Added a test case for it to prevent this happening in future.
Change-Id: I7181699bbf7580888a6f7923c5aeb842356941a8
Reviewed-on: https://go-review.googlesource.com/107195
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
I'd like to propose changes to the directory scanner implementation,
and it would be good to be able to measure how changes compare in
terms of allocations and time taken.
Change-Id: I4ff4bbd38b5e3522f50d31473f2ac607bb0de802
Reviewed-on: https://go-review.googlesource.com/94904
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
- Remove a stray comment which was no longer needed. The accompanying
issue golang.org/issue/7524 was discussed and closed.
- Combine 2 if conditions into a single if-else because
length of a slice can never be negative.
- Remove http links from golangOrgAbsLinkReplacer now that all
links have been changed to https in the blog articles.
Change-Id: I2fe2ec245b580a91760c9331e9626b367f1b6740
Reviewed-on: https://go-review.googlesource.com/107155
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The blog repo can still be imported by older Go versions. Hence,
we need to maintain backward compatibility.
Change-Id: I0235d888734c2f191d04924815f8ffea0239aace
Reviewed-on: https://go-review.googlesource.com/107175
Run-TryBot: Kevin Burke <kev@inburke.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Currently, links inside blog articles are absolute links to golang.org.
But when a godoc server is run locally, the blog package should
serve local links pointing to the local godoc server. It is not possible
to simply change the links inside the blog templates to relative urls
because the blog articles are independant pages on their own.
And moreover, they are served from blog.golang.org.
Rather, the blog package consumes and serves blog articles.
So, a flag was added in the Config struct to denote whether
to convert the links or not. This flag is then set from the
call site in godoc package where the blog server is initialized from.
This was required because "golang.org/x/tools/blog" is a package
which can be used by other code to serve blog pages and not just godoc.
This preserves existing functionality for all working code which
imports "golang.org/x/tools/blog" and changes the functionality only
when a godoc server is run locally.
And while here, replace relevant bytes.Buffer occurences
with strings.Builder.
Fixesgolang/go#22681
Change-Id: I7dbf9c5f2f93fd0b7e17915238de1c084fcd1431
Reviewed-on: https://go-review.googlesource.com/105835
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The comment of Process() implies src can be nil, but it didn't handle
nil src correctly before because parse() doesn't expect nil src.
Passing []byte(nil) to parser.ParseFile() results in error and parse()
tries to parse again by modifying src if src is statement list.
This problem isn't related with cmd/goimports because goimports doesn't
pass []byte(nil) to Process() as src.
Fixesgolang/go#19676
Change-Id: Idbaa6646c3907690763eabc798860c56bb9963d4
Reviewed-on: https://go-review.googlesource.com/38613
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
- Removed the StandAlone and Asset root types as they were just there
for other vfses to satisfy the FileSystem interface and causing unnecessary
confusion. Returning just empty strings in those scenarios now to clarify
that it is a dummy placeholder.
- Removed the prefix "Fs" from RootType as it was unnecessary.
- Using the RootType type to pass down to the html templates
instead of converting to string. The templates are capable of converting
to the actual string representation when comparing the value.
Change-Id: Iadc039f1354ecd814eec0af1e52cdbaaeff0cc89
Reviewed-on: https://go-review.googlesource.com/106196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL 100077 added the syscall_fcntl function in the internal/syscall/unix
package to refer to syscall.fcntl outside of the syscall package in a
unified way.
Add a replacement that simulates a successful fcntl call to fix the
interp tests.
Change-Id: I05847d222f18a19cb30f1395497e708a027a002e
Reviewed-on: https://go-review.googlesource.com/106415
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Separate the templates of package root directory and other
directories. This removes several if-else conditions and
makes the template code much cleaner.
To be merged after CL 95835.
For golang/go#3305
Change-Id: I435441dbe214e4c89271483173df7c30a42ee28f
Reviewed-on: https://go-review.googlesource.com/101295
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This CL groups the package list into two groups - standard library(GOROOT),
and third-party code(GOPATH).
It also wraps the list with a collapsible div header used in the package
documentation page. This makes the entire page easy to view and manage, and also
makes it consistent with the rest of the pages.
To implement this, a new function was added to the filesystem interface
which returns the root type of the filesystem. In most cases, it is either GOROOT
or GOPATH. There are other kinds of filesystems which are not used in the home page,
so additional values have been added to satisfy the interface.
A side effect of this is that the html template code has become a bit spaghetti-like
with if conditions all over. This is because the same template is used to render
a package directory as well as the package home page. A better way is to use
two separate templates for the different tasks. This cleans out a lot of the
if conditions and make for a much cleaner code. This has been taken care in CL 101295.
Fixesgolang/go#3305Fixesgolang/go#15020
Change-Id: I876357dc76280a7df2ed08d7c6bc53d9a41e69ab
Reviewed-on: https://go-review.googlesource.com/95835
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>