aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/query.go
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2020-08-18 10:54:11 -0400
committerDmitri Shuralyov <dmitshur@golang.org>2020-08-18 15:45:01 +0000
commitc12d9ed87596688aeeeb61111e408f6a176aa287 (patch)
tree38501e2cde85ed04ad5af741c0ad524264e7611b /src/cmd/go/internal/modload/query.go
parent6e876f19857a8fbd259571080f7f91bc03276559 (diff)
downloadgo-c12d9ed87596688aeeeb61111e408f6a176aa287.tar.gz
go-c12d9ed87596688aeeeb61111e408f6a176aa287.zip
cmd/go: revert 3 CLs affecting par.Work, context propagation, tracing
This reverts the following changes: • cmd/go: add tracing for querying and downloading from the proxy CL 242786, commit 1a3558341860357c2400e37773e5076bb3a51628 • cmd/go: do context propagation for tracing downloads CL 248327, commit c0cf190d226cc3defb71d17c01d0b45bf49a8a85 • cmd/go/internal: remove some users of par.Work CL 248326, commit f30044a03bc7cf107dbec03c02fb6d0072878252 Reason for revert: broke linux 386 and amd64 longtest builders. The problem started with CL 248326, but CL 248327 and CL 242786 are reverted as well due to conflicts. Updates #38714. Fixes #40861. Change-Id: I68496b4e5a27e47a42183553c3a645b288edac83 Reviewed-on: https://go-review.googlesource.com/c/go/+/249017 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r--src/cmd/go/internal/modload/query.go55
1 files changed, 20 insertions, 35 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go
index e82eb1506f..acc886bf21 100644
--- a/src/cmd/go/internal/modload/query.go
+++ b/src/cmd/go/internal/modload/query.go
@@ -5,7 +5,6 @@
package modload
import (
- "context"
"errors"
"fmt"
"os"
@@ -19,7 +18,6 @@ import (
"cmd/go/internal/modfetch"
"cmd/go/internal/search"
"cmd/go/internal/str"
- "cmd/go/internal/trace"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
@@ -57,10 +55,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(ctx context.Context, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
+func Query(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(ctx, proxy, path, query, current, allowed)
+ info, err = queryProxy(proxy, path, query, current, allowed)
return err
})
return info, err
@@ -77,10 +75,7 @@ func (queryDisabledError) Error() string {
return fmt.Sprintf("cannot query module due to -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
}
-func queryProxy(ctx context.Context, proxy, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
- ctx, span := trace.StartSpan(ctx, "modload.queryProxy "+path+" "+query)
- defer span.Done()
-
+func queryProxy(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)
}
@@ -248,7 +243,7 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
if err != nil {
return nil, err
}
- releases, prereleases, err := filterVersions(ctx, path, versions, ok, preferIncompatible)
+ releases, prereleases, err := filterVersions(path, versions, ok, preferIncompatible)
if err != nil {
return nil, err
}
@@ -332,7 +327,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(ctx context.Context, path string, versions []string, ok func(module.Version) bool, preferIncompatible bool) (releases, prereleases []string, err error) {
+func filterVersions(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}) {
@@ -348,7 +343,7 @@ func filterVersions(ctx context.Context, path string, versions []string, ok func
// https://golang.org/issue/34165.) Note that we even prefer a
// compatible pre-release over an incompatible release.
- ok, err := versionHasGoMod(ctx, module.Version{Path: path, Version: lastCompatible})
+ ok, err := versionHasGoMod(module.Version{Path: path, Version: lastCompatible})
if err != nil {
return nil, nil, err
}
@@ -385,12 +380,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(ctx context.Context, path, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
+func QueryPackage(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(ctx, path, query, allowed)
+ return QueryPattern(path, query, allowed)
}
// QueryPattern looks up the module(s) containing at least one package matching
@@ -406,10 +401,7 @@ func QueryPackage(ctx context.Context, path, query string, allowed func(module.V
// 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(ctx context.Context, pattern, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
- ctx, span := trace.StartSpan(ctx, "modload.QueryPattern "+pattern+" "+query)
- defer span.Done()
-
+func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
base := pattern
firstError := func(m *search.Match) error {
@@ -425,7 +417,7 @@ func QueryPattern(ctx context.Context, pattern, query string, allowed func(modul
base = pathpkg.Dir(pattern[:i+3])
match = func(mod module.Version, root string, isLocal bool) *search.Match {
m := search.NewMatch(pattern)
- matchPackages(ctx, m, imports.AnyTags(), omitStd, []module.Version{mod})
+ matchPackages(m, imports.AnyTags(), omitStd, []module.Version{mod})
return m
}
} else {
@@ -477,18 +469,15 @@ func QueryPattern(ctx context.Context, pattern, query string, allowed func(modul
}
err := modfetch.TryProxies(func(proxy string) error {
- queryModule := func(ctx context.Context, path string) (r QueryResult, err error) {
- ctx, span := trace.StartSpan(ctx, "modload.QueryPattern.queryModule ["+proxy+"] "+path)
- defer span.Done()
-
+ queryModule := func(path string) (r QueryResult, err error) {
current := findCurrentVersion(path)
r.Mod.Path = path
- r.Rev, err = queryProxy(ctx, proxy, path, query, current, allowed)
+ r.Rev, err = queryProxy(proxy, path, query, current, allowed)
if err != nil {
return r, err
}
r.Mod.Version = r.Rev.Version
- root, isLocal, err := fetch(ctx, r.Mod)
+ root, isLocal, err := fetch(r.Mod)
if err != nil {
return r, err
}
@@ -509,7 +498,7 @@ func QueryPattern(ctx context.Context, pattern, query string, allowed func(modul
}
var err error
- results, err = queryPrefixModules(ctx, candidateModules, queryModule)
+ results, err = queryPrefixModules(candidateModules, queryModule)
return err
})
@@ -553,10 +542,7 @@ type prefixResult struct {
err error
}
-func queryPrefixModules(ctx context.Context, candidateModules []string, queryModule func(ctx context.Context, path string) (QueryResult, error)) (found []QueryResult, err error) {
- ctx, span := trace.StartSpan(ctx, "modload.queryPrefixModules")
- defer span.Done()
-
+func queryPrefixModules(candidateModules []string, queryModule func(path string) (QueryResult, error)) (found []QueryResult, err error) {
// If the path we're attempting is not in the module cache and we don't have a
// fetch result cached either, we'll end up making a (potentially slow)
// request to the proxy or (often even slower) the origin server.
@@ -569,9 +555,8 @@ func queryPrefixModules(ctx context.Context, candidateModules []string, queryMod
var wg sync.WaitGroup
wg.Add(len(candidateModules))
for i, p := range candidateModules {
- ctx := trace.StartGoroutine(ctx)
go func(p string, r *result) {
- r.QueryResult, r.err = queryModule(ctx, p)
+ r.QueryResult, r.err = queryModule(p)
wg.Done()
}(p, &results[i])
}
@@ -713,8 +698,8 @@ func (e *PackageNotInModuleError) ImportPath() string {
}
// ModuleHasRootPackage returns whether module m contains a package m.Path.
-func ModuleHasRootPackage(ctx context.Context, m module.Version) (bool, error) {
- root, isLocal, err := fetch(ctx, m)
+func ModuleHasRootPackage(m module.Version) (bool, error) {
+ root, isLocal, err := fetch(m)
if err != nil {
return false, err
}
@@ -722,8 +707,8 @@ func ModuleHasRootPackage(ctx context.Context, m module.Version) (bool, error) {
return ok, err
}
-func versionHasGoMod(ctx context.Context, m module.Version) (bool, error) {
- root, _, err := fetch(ctx, m)
+func versionHasGoMod(m module.Version) (bool, error) {
+ root, _, err := fetch(m)
if err != nil {
return false, err
}