Skip to content

Commit 699a7c0

Browse files
aofeiJay Conrod
authored and
Jay Conrod
committed
cmd/go/internal/modconv: involve GOPROXY in ConvertLegacyConfig
Fixes #33767 Change-Id: Ia2d6dd32bcb0e142f59346232b3b1aa3babb034a Reviewed-on: https://go-review.googlesource.com/c/go/+/306809 Trust: Jay Conrod <[email protected]> Trust: Bryan C. Mills <[email protected]> Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Aofei Sheng <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 7ed6d1f commit 699a7c0

File tree

8 files changed

+82
-256
lines changed

8 files changed

+82
-256
lines changed

src/cmd/go/internal/modconv/convert.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313

1414
"cmd/go/internal/base"
15-
"cmd/go/internal/modfetch"
1615

1716
"golang.org/x/mod/modfile"
1817
"golang.org/x/mod/module"
@@ -21,7 +20,7 @@ import (
2120

2221
// ConvertLegacyConfig converts legacy config to modfile.
2322
// The file argument is slash-delimited.
24-
func ConvertLegacyConfig(f *modfile.File, file string, data []byte) error {
23+
func ConvertLegacyConfig(f *modfile.File, file string, data []byte, queryPackage func(path, rev string) (module.Version, error)) error {
2524
i := strings.LastIndex(file, "/")
2625
j := -2
2726
if i >= 0 {
@@ -62,15 +61,13 @@ func ConvertLegacyConfig(f *modfile.File, file string, data []byte) error {
6261
sem <- token{}
6362
go func(i int, m module.Version) {
6463
defer func() { <-sem }()
65-
repo, info, err := modfetch.ImportRepoRev(m.Path, m.Version)
64+
version, err := queryPackage(m.Path, m.Version)
6665
if err != nil {
6766
fmt.Fprintf(os.Stderr, "go: converting %s: stat %s@%s: %v\n", base.ShortPath(file), m.Path, m.Version, err)
6867
return
6968
}
7069

71-
path := repo.ModulePath()
72-
versions[i].Path = path
73-
versions[i].Version = info.Version
70+
versions[i] = version
7471
}(i, m)
7572
}
7673
// Fill semaphore channel to wait for all tasks to finish.

src/cmd/go/internal/modconv/convert_test.go

Lines changed: 0 additions & 189 deletions
This file was deleted.

src/cmd/go/internal/modfetch/repo.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,6 @@ type RevInfo struct {
169169
// and it can check that the path can be resolved to a target repository.
170170
// To avoid version control access except when absolutely necessary,
171171
// Lookup does not attempt to connect to the repository itself.
172-
//
173-
// The ImportRepoRev function is a variant of Import which is limited
174-
// to code in a source code repository at a particular revision identifier
175-
// (usually a commit hash or source code repository tag, not necessarily
176-
// a module version).
177-
// ImportRepoRev is used when converting legacy dependency requirements
178-
// from older systems into go.mod files. Those older systems worked
179-
// at either package or repository granularity, and most of the time they
180-
// recorded commit hashes, not tagged versions.
181172

182173
var lookupCache par.Cache
183174

@@ -297,53 +288,6 @@ func lookupCodeRepo(rr *vcs.RepoRoot) (codehost.Repo, error) {
297288
return code, nil
298289
}
299290

300-
// ImportRepoRev returns the module and version to use to access
301-
// the given import path loaded from the source code repository that
302-
// the original "go get" would have used, at the specific repository revision
303-
// (typically a commit hash, but possibly also a source control tag).
304-
func ImportRepoRev(path, rev string) (Repo, *RevInfo, error) {
305-
if cfg.BuildMod == "vendor" || cfg.BuildMod == "readonly" {
306-
return nil, nil, fmt.Errorf("repo version lookup disabled by -mod=%s", cfg.BuildMod)
307-
}
308-
309-
// Note: Because we are converting a code reference from a legacy
310-
// version control system, we ignore meta tags about modules
311-
// and use only direct source control entries (get.IgnoreMod).
312-
security := web.SecureOnly
313-
if module.MatchPrefixPatterns(cfg.GOINSECURE, path) {
314-
security = web.Insecure
315-
}
316-
rr, err := vcs.RepoRootForImportPath(path, vcs.IgnoreMod, security)
317-
if err != nil {
318-
return nil, nil, err
319-
}
320-
321-
code, err := lookupCodeRepo(rr)
322-
if err != nil {
323-
return nil, nil, err
324-
}
325-
326-
revInfo, err := code.Stat(rev)
327-
if err != nil {
328-
return nil, nil, err
329-
}
330-
331-
// TODO: Look in repo to find path, check for go.mod files.
332-
// For now we're just assuming rr.Root is the module path,
333-
// which is true in the absence of go.mod files.
334-
335-
repo, err := newCodeRepo(code, rr.Root, rr.Root)
336-
if err != nil {
337-
return nil, nil, err
338-
}
339-
340-
info, err := repo.(*codeRepo).convert(revInfo, rev)
341-
if err != nil {
342-
return nil, nil, err
343-
}
344-
return repo, info, nil
345-
}
346-
347291
// A loggingRepo is a wrapper around an underlying Repo
348292
// that prints a log message at the start and end of each call.
349293
// It can be inserted when debugging.

src/cmd/go/internal/modload/init.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,17 @@ func setDefaultBuildMod() {
728728
// convertLegacyConfig imports module requirements from a legacy vendoring
729729
// configuration file, if one is present.
730730
func convertLegacyConfig(modPath string) (from string, err error) {
731+
noneSelected := func(path string) (version string) { return "none" }
732+
queryPackage := func(path, rev string) (module.Version, error) {
733+
pkgMods, modOnly, err := QueryPattern(context.Background(), path, rev, noneSelected, nil)
734+
if err != nil {
735+
return module.Version{}, err
736+
}
737+
if len(pkgMods) > 0 {
738+
return pkgMods[0].Mod, nil
739+
}
740+
return modOnly.Mod, nil
741+
}
731742
for _, name := range altConfigs {
732743
cfg := filepath.Join(modRoot, name)
733744
data, err := os.ReadFile(cfg)
@@ -737,7 +748,7 @@ func convertLegacyConfig(modPath string) (from string, err error) {
737748
return "", nil
738749
}
739750
cfg = filepath.ToSlash(cfg)
740-
err := modconv.ConvertLegacyConfig(modFile, cfg, data)
751+
err := modconv.ConvertLegacyConfig(modFile, cfg, data, queryPackage)
741752
return name, err
742753
}
743754
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[short] skip
2+
3+
env GO111MODULE=on
4+
env GOPROXY=
5+
env GOSUMDB=
6+
7+
go mod download github.com/docker/[email protected]
8+
mkdir x/Godeps
9+
cp $GOPATH/pkg/mod/github.com/docker/[email protected]/Godeps/Godeps.json x/Godeps
10+
cd x
11+
go mod init github.com/docker/distribution
12+
cmpenv go.mod go.mod.want
13+
14+
go mod download github.com/fishy/[email protected]
15+
cp $GOPATH/pkg/mod/github.com/fishy/[email protected]/Gopkg.lock ../y
16+
cd ../y
17+
go mod init github.com/fishy/gcsbucket
18+
cmpenv go.mod go.mod.want
19+
20+
-- x/go.mod.want --
21+
module github.com/docker/distribution
22+
23+
go $goversion
24+
25+
require (
26+
github.com/AdRoll/goamz v0.0.0-20150130162828-d3664b76d905
27+
github.com/MSOpenTech/azure-sdk-for-go v0.0.0-20150323223030-d90753bcad2e
28+
github.com/Sirupsen/logrus v0.7.3
29+
github.com/bugsnag/bugsnag-go v1.0.3-0.20141110184014-b1d153021fcd
30+
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b
31+
github.com/bugsnag/panicwrap v0.0.0-20141110184334-e5f9854865b9
32+
github.com/codegangsta/cli v1.4.2-0.20150131031259-6086d7927ec3
33+
github.com/docker/docker v1.4.2-0.20150204013315-165ea5c158cf
34+
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1
35+
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7
36+
github.com/gorilla/context v0.0.0-20140604161150-14f550f51af5
37+
github.com/gorilla/handlers v0.0.0-20140825150757-0e84b7d810c1
38+
github.com/gorilla/mux v0.0.0-20140926153814-e444e69cbd2e
39+
github.com/jlhawn/go-crypto v0.0.0-20150401213827-cd738dde20f0
40+
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43
41+
github.com/yvasiyarov/gorelic v0.0.7-0.20141212073537-a9bba5b9ab50
42+
github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f
43+
golang.org/x/net v0.0.0-20150202051010-1dfe7915deaf
44+
gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789
45+
gopkg.in/yaml.v2 v2.0.0-20150116202057-bef53efd0c76
46+
)
47+
-- y/go.mod.want --
48+
module github.com/fishy/gcsbucket
49+
50+
go $goversion
51+
52+
require (
53+
cloud.google.com/go v0.18.0
54+
github.com/fishy/fsdb v0.0.0-20180217030800-5527ded01371
55+
github.com/golang/protobuf v1.0.0
56+
github.com/googleapis/gax-go v2.0.0+incompatible
57+
golang.org/x/net v0.0.0-20180216171745-136a25c244d3
58+
golang.org/x/oauth2 v0.0.0-20180207181906-543e37812f10
59+
golang.org/x/text v0.3.1-0.20180208041248-4e4a3210bb54
60+
google.golang.org/api v0.0.0-20180217000815-c7a403bb5fe1
61+
google.golang.org/appengine v1.0.0
62+
google.golang.org/genproto v0.0.0-20180206005123-2b5a72b8730b
63+
google.golang.org/grpc v1.10.0
64+
)

src/cmd/go/testdata/script/mod_convert_tsv_insecure.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
env GO111MODULE=on
2+
env GOPROXY=direct
3+
env GOSUMDB=off
24

35
[!net] skip
46
[!exec:git] skip

0 commit comments

Comments
 (0)