aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/query.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2020-06-30 17:51:52 -0400
committerMichael Matloob <matloob@golang.org>2020-08-17 19:52:21 +0000
commitc0cf190d226cc3defb71d17c01d0b45bf49a8a85 (patch)
treec0a77e4d51c22dec30af472f7de473212773fa13 /src/cmd/go/internal/modload/query.go
parent797124f5ff4bb80957007adbf3115287a4e90870 (diff)
downloadgo-c0cf190d226cc3defb71d17c01d0b45bf49a8a85.tar.gz
go-c0cf190d226cc3defb71d17c01d0b45bf49a8a85.zip
cmd/go: do context propagation for tracing downloads
This change does context propagation (and only context propagation) necessary to add context to modfetch.Download and pkg.LoadImport. This was done by adding context to their callers, and then adding context to all call-sites, and then repeating adding context to callers of those enclosing functions and their callers until none were left. In some cases the call graph expansion was pruned by using context.TODOs. The next CL will add a span to Download. I kept it out of this change to avoid making it any larger (and harder to review) than it needs to be. Updates #38714 Change-Id: I5bf2d599aafef67334c384dfccd5e255198c85b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/248327 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r--src/cmd/go/internal/modload/query.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go
index acc886bf21..39a813447c 100644
--- a/src/cmd/go/internal/modload/query.go
+++ b/src/cmd/go/internal/modload/query.go
@@ -5,6 +5,7 @@
package modload
import (
+ "context"
"errors"
"fmt"
"os"
@@ -55,10 +56,10 @@ import (
//
// If path is the path of the main module and the query is "latest",
// Query returns Target.Version as the version.
-func Query(path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
+func Query(ctx context.Context, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
var info *modfetch.RevInfo
err := modfetch.TryProxies(func(proxy string) (err error) {
- info, err = queryProxy(proxy, path, query, current, allowed)
+ info, err = queryProxy(ctx, proxy, path, query, current, allowed)
return err
})
return info, err
@@ -75,7 +76,7 @@ func (queryDisabledError) Error() string {
return fmt.Sprintf("cannot query module due to -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
}
-func queryProxy(proxy, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
+func queryProxy(ctx context.Context, proxy, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
if current != "" && !semver.IsValid(current) {
return nil, fmt.Errorf("invalid previous version %q", current)
}
@@ -243,7 +244,7 @@ func queryProxy(proxy, path, query, current string, allowed func(module.Version)
if err != nil {
return nil, err
}
- releases, prereleases, err := filterVersions(path, versions, ok, preferIncompatible)
+ releases, prereleases, err := filterVersions(ctx, path, versions, ok, preferIncompatible)
if err != nil {
return nil, err
}
@@ -327,7 +328,7 @@ func matchSemverPrefix(p, v string) bool {
// 1. versions that do not satisfy the 'ok' predicate, and
// 2. "+incompatible" versions, if a compatible one satisfies the predicate
// and the incompatible version is not preferred.
-func filterVersions(path string, versions []string, ok func(module.Version) bool, preferIncompatible bool) (releases, prereleases []string, err error) {
+func filterVersions(ctx context.Context, path string, versions []string, ok func(module.Version) bool, preferIncompatible bool) (releases, prereleases []string, err error) {
var lastCompatible string
for _, v := range versions {
if !ok(module.Version{Path: path, Version: v}) {
@@ -343,7 +344,7 @@ func filterVersions(path string, versions []string, ok func(module.Version) bool
// https://golang.org/issue/34165.) Note that we even prefer a
// compatible pre-release over an incompatible release.
- ok, err := versionHasGoMod(module.Version{Path: path, Version: lastCompatible})
+ ok, err := versionHasGoMod(ctx, module.Version{Path: path, Version: lastCompatible})
if err != nil {
return nil, nil, err
}
@@ -380,12 +381,12 @@ type QueryResult struct {
// If the package is in the main module, QueryPackage considers only the main
// module and only the version "latest", without checking for other possible
// modules.
-func QueryPackage(path, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
+func QueryPackage(ctx context.Context, path, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
m := search.NewMatch(path)
if m.IsLocal() || !m.IsLiteral() {
return nil, fmt.Errorf("pattern %s is not an importable package", path)
}
- return QueryPattern(path, query, allowed)
+ return QueryPattern(ctx, path, query, allowed)
}
// QueryPattern looks up the module(s) containing at least one package matching
@@ -401,7 +402,7 @@ func QueryPackage(path, query string, allowed func(module.Version) bool) ([]Quer
// If any matching package is in the main module, QueryPattern considers only
// the main module and only the version "latest", without checking for other
// possible modules.
-func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
+func QueryPattern(ctx context.Context, pattern, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
base := pattern
firstError := func(m *search.Match) error {
@@ -417,7 +418,7 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q
base = pathpkg.Dir(pattern[:i+3])
match = func(mod module.Version, root string, isLocal bool) *search.Match {
m := search.NewMatch(pattern)
- matchPackages(m, imports.AnyTags(), omitStd, []module.Version{mod})
+ matchPackages(ctx, m, imports.AnyTags(), omitStd, []module.Version{mod})
return m
}
} else {
@@ -472,12 +473,12 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q
queryModule := func(path string) (r QueryResult, err error) {
current := findCurrentVersion(path)
r.Mod.Path = path
- r.Rev, err = queryProxy(proxy, path, query, current, allowed)
+ r.Rev, err = queryProxy(ctx, proxy, path, query, current, allowed)
if err != nil {
return r, err
}
r.Mod.Version = r.Rev.Version
- root, isLocal, err := fetch(r.Mod)
+ root, isLocal, err := fetch(ctx, r.Mod)
if err != nil {
return r, err
}
@@ -698,8 +699,8 @@ func (e *PackageNotInModuleError) ImportPath() string {
}
// ModuleHasRootPackage returns whether module m contains a package m.Path.
-func ModuleHasRootPackage(m module.Version) (bool, error) {
- root, isLocal, err := fetch(m)
+func ModuleHasRootPackage(ctx context.Context, m module.Version) (bool, error) {
+ root, isLocal, err := fetch(ctx, m)
if err != nil {
return false, err
}
@@ -707,8 +708,8 @@ func ModuleHasRootPackage(m module.Version) (bool, error) {
return ok, err
}
-func versionHasGoMod(m module.Version) (bool, error) {
- root, _, err := fetch(m)
+func versionHasGoMod(ctx context.Context, m module.Version) (bool, error) {
+ root, _, err := fetch(ctx, m)
if err != nil {
return false, err
}