Skip to content

Commit 545cd82

Browse files
author
Jay Conrod
committed
cmd/go: remove support for the 'go get -m' flag
Fixes golang#32038 Change-Id: Ib4981f76572405363f404ee5038a45cb1752a2ad Reviewed-on: https://go-review.googlesource.com/c/go/+/177879 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 8ca524a commit 545cd82

24 files changed

Lines changed: 117 additions & 346 deletions

src/cmd/go/alldocs.go

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/modget/get.go

Lines changed: 43 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"cmd/go/internal/par"
1818
"cmd/go/internal/search"
1919
"cmd/go/internal/semver"
20-
"cmd/go/internal/str"
2120
"cmd/go/internal/work"
2221
"errors"
2322
"fmt"
@@ -29,9 +28,9 @@ import (
2928
)
3029

3130
var CmdGet = &base.Command{
32-
// Note: -d -m -u are listed explicitly because they are the most common get flags.
31+
// Note: -d -u are listed explicitly because they are the most common get flags.
3332
// Do not send CLs removing them because they're covered by [get flags].
34-
UsageLine: "go get [-d] [-m] [-t] [-u] [-v] [-insecure] [build flags] [packages]",
33+
UsageLine: "go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]",
3534
Short: "add dependencies to current module and install them",
3635
Long: `
3736
Get resolves and adds dependencies to the current development module
@@ -97,18 +96,6 @@ this automatically. Similarly, downgrading one dependency may
9796
require downgrading other dependencies, and 'go get' does
9897
this automatically as well.
9998
100-
The -m flag instructs get to stop here, after resolving, upgrading,
101-
and downgrading modules and updating go.mod. When using -m,
102-
each specified package path must be a module path as well,
103-
not the import path of a package below the module root.
104-
105-
When the -m and -u flags are used together, 'go get' will upgrade
106-
modules that provide packages depended on by the modules named on
107-
the command line. For example, 'go get -u -m A' will upgrade A and
108-
any module providing packages imported by packages in A.
109-
'go get -u -m' will upgrade modules that provided packages needed
110-
by the main module.
111-
11299
The -insecure flag permits fetching from repositories and resolving
113100
custom domains using insecure schemes such as HTTP. Use with caution.
114101
@@ -227,8 +214,7 @@ type querySpec struct {
227214
// vers specifies what version of the module to get.
228215
vers string
229216

230-
// forceModulePath is true if path should be interpreted as a module path
231-
// even if -m is not specified.
217+
// forceModulePath is true if path should be interpreted as a module path.
232218
forceModulePath bool
233219

234220
// prevM is the previous version of the module. prevM is needed
@@ -267,6 +253,9 @@ func runGet(cmd *base.Command, args []string) {
267253
if *getFix {
268254
fmt.Fprintf(os.Stderr, "go get: -fix flag is a no-op when using modules\n")
269255
}
256+
if *getM {
257+
base.Fatalf("go get: -m flag is no longer supported")
258+
}
270259
modload.LoadTests = *getT
271260

272261
if cfg.BuildMod == "vendor" {
@@ -318,12 +307,7 @@ func runGet(cmd *base.Command, args []string) {
318307
// contains no wildcards (...), check that it is a package in
319308
// the main module. If the path contains wildcards but matches no
320309
// packages, we'll warn after package loading.
321-
if len(args) > 0 && *getM {
322-
base.Errorf("go get %s: -m requires a module path, but a relative path must be a package in the main module", arg)
323-
continue
324-
}
325-
326-
if !*getM && !strings.Contains(path, "...") {
310+
if !strings.Contains(path, "...") {
327311
pkgPath := modload.DirImportPath(filepath.FromSlash(path))
328312
if pkgs := modload.TargetPackages(pkgPath); len(pkgs) == 0 {
329313
abs, err := filepath.Abs(path)
@@ -341,25 +325,7 @@ func runGet(cmd *base.Command, args []string) {
341325
}
342326

343327
case strings.Contains(path, "..."):
344-
// If we're using -m, look up modules in the build list that match
345-
// the pattern. Report an error if no modules match.
346-
if *getM {
347-
match := search.MatchPattern(path)
348-
matched := false
349-
for _, m := range modload.BuildList() {
350-
if match(m.Path) || str.HasPathPrefix(path, m.Path) {
351-
queries = append(queries, &query{querySpec: querySpec{path: m.Path, vers: vers, prevM: m, forceModulePath: true}, arg: arg})
352-
matched = true
353-
}
354-
}
355-
if !matched {
356-
base.Errorf("go get %s: pattern matches no modules in build list", arg)
357-
continue
358-
}
359-
break
360-
}
361-
362-
// If we're not using -m, wait until we load packages to look up modules.
328+
// Wait until we load packages to look up modules.
363329
// We don't know yet whether any modules in the build list provide
364330
// packages matching the pattern. For example, suppose
365331
// golang.org/x/tools and golang.org/x/tools/playground are separate
@@ -369,34 +335,34 @@ func runGet(cmd *base.Command, args []string) {
369335
// upgrade golang.org/x/tools.
370336

371337
case path == "all":
372-
// This is the package pattern "all" not the module pattern "all",
373-
// even if *getM. We won't create any queries yet, since we're going to
374-
// need to load packages anyway.
338+
// Don't query modules until we load packages. We'll automatically
339+
// look up any missing modules.
375340

376341
case search.IsMetaPackage(path):
377342
base.Errorf("go get %s: explicit requirement on standard-library module %s not allowed", path, path)
378343
continue
379344

380345
default:
381-
// The argument is a package path or module path or both.
382-
q := &query{querySpec: querySpec{path: path, vers: vers}, arg: arg}
383-
if vers == "patch" {
384-
if *getM {
385-
for _, m := range modload.BuildList() {
386-
if m.Path == path {
387-
q.prevM = m
388-
break
389-
}
390-
}
391-
queries = append(queries, q)
392-
} else {
393-
// We need to know the module containing path before asking for
394-
// a specific version. Wait until we load packages later.
346+
// The argument is a package path.
347+
if pkgs := modload.TargetPackages(path); len(pkgs) != 0 {
348+
// The path is in the main module. Nothing to query.
349+
if vers != "" && vers != "latest" && vers != "patch" {
350+
base.Errorf("go get %s: can't request explicit version of path in main module", arg)
395351
}
352+
continue
353+
}
354+
355+
if vers == "patch" {
356+
// We need to know the previous version of the module to find
357+
// the new version, but we don't know what module provides this
358+
// package yet. Wait until we load packages later.
359+
// TODO(golang.org/issue/30634): @latest should also depend on
360+
// the current version to prevent downgrading from newer pseudoversions.
396361
} else {
397362
// The requested version of path doesn't depend on the existing version,
398-
// so don't bother resolving it.
399-
queries = append(queries, q)
363+
// so query the module before loading the package. This may let us
364+
// load the package only once at the correct version.
365+
queries = append(queries, &query{querySpec: querySpec{path: path, vers: vers}, arg: arg})
400366
}
401367
}
402368
}
@@ -430,7 +396,7 @@ func runGet(cmd *base.Command, args []string) {
430396
modOnly[q.m.Path] = q
431397
continue
432398
}
433-
if !*getM && q.path == q.m.Path {
399+
if q.path == q.m.Path {
434400
wg.Add(1)
435401
go func(q *query) {
436402
if hasPkg, err := modload.ModuleHasRootPackage(q.m); err != nil {
@@ -477,17 +443,13 @@ func runGet(cmd *base.Command, args []string) {
477443
// Don't load packages if pkgPatterns is empty. Both
478444
// modload.ImportPathsQuiet and ModulePackages convert an empty list
479445
// of patterns to []string{"."}, which is not what we want.
480-
if *getM {
481-
matches = modload.ModulePackages(pkgPatterns)
482-
} else {
483-
matches = modload.ImportPathsQuiet(pkgPatterns)
484-
}
446+
matches = modload.ImportPathsQuiet(pkgPatterns)
485447
seenPkgs = make(map[string]bool)
486448
install = make([]string, 0, len(pkgPatterns))
487449
for i, match := range matches {
488450
arg := pkgGets[i]
489451

490-
if !*getM && len(match.Pkgs) == 0 {
452+
if len(match.Pkgs) == 0 {
491453
// If the pattern did not match any packages, look up a new module.
492454
// If the pattern doesn't match anything on the last iteration,
493455
// we'll print a warning after the outer loop.
@@ -516,12 +478,8 @@ func runGet(cmd *base.Command, args []string) {
516478
allStd = false
517479
addQuery(&query{querySpec: querySpec{path: m.Path, vers: arg.vers, forceModulePath: true, prevM: m}, arg: arg.raw})
518480
}
519-
if allStd {
520-
if *getM {
521-
base.Errorf("go get %s: cannot use pattern %q with -m", arg.raw, arg.raw)
522-
} else if arg.path != arg.raw {
523-
base.Errorf("go get %s: cannot use pattern %q with explicit version", arg.raw, arg.raw)
524-
}
481+
if allStd && arg.path != arg.raw {
482+
base.Errorf("go get %s: cannot use pattern %q with explicit version", arg.raw, arg.raw)
525483
}
526484
}
527485
}
@@ -552,9 +510,7 @@ func runGet(cmd *base.Command, args []string) {
552510
}
553511
prevBuildList = buildList
554512
}
555-
if !*getM {
556-
search.WarnUnmatched(matches) // don't warn on every iteration
557-
}
513+
search.WarnUnmatched(matches) // don't warn on every iteration
558514

559515
// Handle downgrades.
560516
var down []module.Version
@@ -645,12 +601,14 @@ func runGet(cmd *base.Command, args []string) {
645601
modload.AllowWriteGoMod()
646602
modload.WriteGoMod()
647603

648-
// If -m or -d was specified, we're done after the module work. We've
649-
// already downloaded modules by loading packages above. If neither flag
650-
// we specified, we need build and install the packages.
651-
// Note that 'go get -u' without any arguments results in len(install) == 1:
652-
// search.CleanImportPaths returns "." for empty args.
653-
if *getM || *getD || len(install) == 0 {
604+
// If -d was specified, we're done after the module work.
605+
// We've already downloaded modules by loading packages above.
606+
// Otherwise, we need to build and install the packages matched
607+
// by command line arguments.
608+
// Note that 'go get -u' without any arguments results in
609+
// len(install) == 1 if there's a package in the current directory.
610+
// search.CleanPatterns returns "." for empty args.
611+
if *getD || len(install) == 0 {
654612
return
655613
}
656614
work.BuildInit()
@@ -726,7 +684,7 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
726684
}
727685
}
728686

729-
if forceModulePath || *getM || !strings.Contains(path, "...") {
687+
if forceModulePath || !strings.Contains(path, "...") {
730688
if path == modload.Target.Path {
731689
if vers != "latest" {
732690
return module.Version{}, fmt.Errorf("can't get a specific version of the main module")
@@ -740,7 +698,7 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
740698
}
741699

742700
// If the query fails, and the path must be a real module, report the query error.
743-
if forceModulePath || *getM {
701+
if forceModulePath {
744702
return module.Version{}, err
745703
}
746704
}

src/cmd/go/internal/modload/load.go

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import (
3333

3434
// buildList is the list of modules to use for building packages.
3535
// It is initialized by calling ImportPaths, ImportFromFiles,
36-
// ModulePackages, LoadALL, or LoadBuildList, each of which uses
37-
// loaded.load.
36+
// LoadALL, or LoadBuildList, each of which uses loaded.load.
3837
//
3938
// Ideally, exactly ONE of those functions would be called,
4039
// and exactly once. Most of the time, that's true.
@@ -170,81 +169,6 @@ func ImportPathsQuiet(patterns []string) []*search.Match {
170169
}
171170
}
172171

173-
return loadPatterns(patterns, true, updateMatches)
174-
}
175-
176-
// ModulePackages returns packages provided by each module in patterns.
177-
// patterns may contain module paths, patterns matching module paths,
178-
// "all" (interpreted as package pattern "all"), and "." (interpreted
179-
// as the main module). Additional modules (including modules providing
180-
// dependencies) may be added to the build list or upgraded.
181-
func ModulePackages(patterns []string) []*search.Match {
182-
updateMatches := func(matches []*search.Match, iterating bool) {
183-
for _, m := range matches {
184-
switch {
185-
case search.IsRelativePath(m.Pattern) || filepath.IsAbs(m.Pattern):
186-
if m.Pattern != "." {
187-
base.Errorf("go: path %s is not a module", m.Pattern)
188-
continue
189-
}
190-
m.Pkgs = matchPackages("...", loaded.tags, false, []module.Version{Target})
191-
192-
case strings.Contains(m.Pattern, "..."):
193-
match := search.MatchPattern(m.Pattern)
194-
var matched []module.Version
195-
for _, mod := range buildList {
196-
if match(mod.Path) || str.HasPathPrefix(m.Pattern, mod.Path) {
197-
matched = append(matched, mod)
198-
}
199-
}
200-
m.Pkgs = matchPackages(m.Pattern, loaded.tags, false, matched)
201-
202-
case m.Pattern == "all":
203-
loaded.testAll = true
204-
if iterating {
205-
// Enumerate the packages in the main module.
206-
// We'll load the dependencies as we find them.
207-
m.Pkgs = matchPackages("...", loaded.tags, false, []module.Version{Target})
208-
} else {
209-
// Starting with the packages in the main module,
210-
// enumerate the full list of "all".
211-
m.Pkgs = loaded.computePatternAll(m.Pkgs)
212-
}
213-
214-
default:
215-
found := false
216-
for _, mod := range buildList {
217-
if mod.Path == m.Pattern {
218-
found = true
219-
m.Pkgs = matchPackages("...", loaded.tags, false, []module.Version{mod})
220-
break
221-
}
222-
}
223-
if !found {
224-
base.Errorf("go %s: module not in build list", m.Pattern)
225-
}
226-
}
227-
}
228-
}
229-
return loadPatterns(patterns, false, updateMatches)
230-
}
231-
232-
// loadPatterns returns a set of packages matching the args (patterns),
233-
// adding modules to the build list as needed to satisfy new imports.
234-
//
235-
// useTags indicates whether to use the default build constraints to
236-
// filter source files. If useTags is false, only "ignore" and malformed
237-
// build tag requirements are considered false.
238-
//
239-
// The interpretation of patterns is determined by updateMatches, which will be
240-
// called repeatedly until the build list is finalized. updateMatches should
241-
// should store a list of matching packages in each search.Match when it is
242-
// called. The iterating parameter is true if the build list has not been
243-
// finalized yet.
244-
//
245-
// If errors are encountered, loadPatterns will print them and exit.
246-
// On success, loadPatterns will update the build list and write go.mod.
247-
func loadPatterns(patterns []string, useTags bool, updateMatches func(matches []*search.Match, iterating bool)) []*search.Match {
248172
InitMod()
249173

250174
var matches []*search.Match
@@ -256,9 +180,6 @@ func loadPatterns(patterns []string, useTags bool, updateMatches func(matches []
256180
}
257181

258182
loaded = newLoader()
259-
if !useTags {
260-
loaded.tags = anyTags
261-
}
262183
loaded.load(func() []string {
263184
var roots []string
264185
updateMatches(matches, true)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
env GO111MODULE=on
22
[short] skip
33

4-
go get -m rsc.io/fortune/v2
4+
go get -d rsc.io/fortune/v2
55

66
# The default executable name shouldn't be v2$exe
77
go build rsc.io/fortune/v2

0 commit comments

Comments
 (0)