Commit 6145a806 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go: remove the -mod flag from 'go get'

'GOFLAGS=-mod=vendor' currently causes 'go get' to always fail unless
the '-mod' flag is explicitly overwritten. Moreover, as of CL 198319
we plan to set -mod=vendor by default if a vendor directory is
present, so all users with vendor directories will be affected — not
just those who set 'GOFLAGS' explicitly.

Similarly, an explicit '-mod=readonly' argument to 'go get' is
currently ignored as a special case, but the fact that it is ignored
(rather than rejected) can be very surprising.

Rather than adding more special cases, we should remove the '-mod'
flag from 'go get' entirely.

Fixes #30345
Fixes #32502
Updates #33848

Change-Id: Iecd3233ca3ef580ca3a66bd5e6ee8d86d4cbd8a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/198438
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent c1e46af6
...@@ -58,6 +58,13 @@ TODO ...@@ -58,6 +58,13 @@ TODO
graphic characters and spaces. graphic characters and spaces.
</p> </p>
<p><!-- golang.org/issue/32502, golang.org/issue/30345 -->
The <code>go</code> <code>get</code> subcommand no longer accepts
the <code>-mod</code> flag. Previously, the flag's setting either
<a href="https://golang.org/issue/30345">was ignored</a> or
<a href="https://golang.org/issue/32502">caused the build to fail</a>.
</p>
<h2 id="runtime">Runtime</h2> <h2 id="runtime">Runtime</h2>
<p> <p>
......
...@@ -102,7 +102,7 @@ func init() { ...@@ -102,7 +102,7 @@ func init() {
// mentioned explicitly in the docs but they // mentioned explicitly in the docs but they
// are part of the build flags. // are part of the build flags.
work.AddBuildFlags(CmdClean) work.AddBuildFlags(CmdClean, work.DefaultBuildFlags)
} }
func runClean(cmd *base.Command, args []string) { func runClean(cmd *base.Command, args []string) {
......
...@@ -149,7 +149,7 @@ var ( ...@@ -149,7 +149,7 @@ var (
) )
func init() { func init() {
work.AddBuildFlags(CmdGenerate) work.AddBuildFlags(CmdGenerate, work.DefaultBuildFlags)
CmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "") CmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
} }
......
...@@ -108,7 +108,7 @@ var ( ...@@ -108,7 +108,7 @@ var (
) )
func init() { func init() {
work.AddBuildFlags(CmdGet) work.AddBuildFlags(CmdGet, work.OmitModFlag)
CmdGet.Run = runGet // break init loop CmdGet.Run = runGet // break init loop
CmdGet.Flag.BoolVar(&Insecure, "insecure", Insecure, "") CmdGet.Flag.BoolVar(&Insecure, "insecure", Insecure, "")
} }
......
...@@ -287,7 +287,7 @@ For more about modules, see 'go help modules'. ...@@ -287,7 +287,7 @@ For more about modules, see 'go help modules'.
func init() { func init() {
CmdList.Run = runList // break init cycle CmdList.Run = runList // break init cycle
work.AddBuildFlags(CmdList) work.AddBuildFlags(CmdList, work.DefaultBuildFlags)
} }
var ( var (
......
...@@ -7,7 +7,6 @@ package modget ...@@ -7,7 +7,6 @@ package modget
import ( import (
"cmd/go/internal/base" "cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/get" "cmd/go/internal/get"
"cmd/go/internal/imports" "cmd/go/internal/imports"
"cmd/go/internal/load" "cmd/go/internal/load"
...@@ -199,7 +198,7 @@ func (v *upgradeFlag) Set(s string) error { ...@@ -199,7 +198,7 @@ func (v *upgradeFlag) Set(s string) error {
func (v *upgradeFlag) String() string { return "" } func (v *upgradeFlag) String() string { return "" }
func init() { func init() {
work.AddBuildFlags(CmdGet) work.AddBuildFlags(CmdGet, work.OmitModFlag)
CmdGet.Run = runGet // break init loop CmdGet.Run = runGet // break init loop
CmdGet.Flag.BoolVar(&get.Insecure, "insecure", get.Insecure, "") CmdGet.Flag.BoolVar(&get.Insecure, "insecure", get.Insecure, "")
CmdGet.Flag.Var(&getU, "u", "") CmdGet.Flag.Var(&getU, "u", "")
...@@ -256,11 +255,6 @@ type query struct { ...@@ -256,11 +255,6 @@ type query struct {
} }
func runGet(cmd *base.Command, args []string) { func runGet(cmd *base.Command, args []string) {
// -mod=readonly has no effect on "go get".
if cfg.BuildMod == "readonly" {
cfg.BuildMod = ""
}
switch getU { switch getU {
case "", "upgrade", "patch": case "", "upgrade", "patch":
// ok // ok
...@@ -278,10 +272,6 @@ func runGet(cmd *base.Command, args []string) { ...@@ -278,10 +272,6 @@ func runGet(cmd *base.Command, args []string) {
} }
modload.LoadTests = *getT modload.LoadTests = *getT
if cfg.BuildMod == "vendor" {
base.Fatalf("go get: disabled by -mod=%s", cfg.BuildMod)
}
buildList := modload.LoadBuildList() buildList := modload.LoadBuildList()
buildList = buildList[:len(buildList):len(buildList)] // copy on append buildList = buildList[:len(buildList):len(buildList)] // copy on append
versionByPath := make(map[string]string) versionByPath := make(map[string]string)
......
...@@ -49,7 +49,7 @@ See also: go build. ...@@ -49,7 +49,7 @@ See also: go build.
func init() { func init() {
CmdRun.Run = runRun // break init loop CmdRun.Run = runRun // break init loop
work.AddBuildFlags(CmdRun) work.AddBuildFlags(CmdRun, work.DefaultBuildFlags)
CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "") CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
} }
......
...@@ -65,7 +65,7 @@ var testFlagDefn = []*cmdflag.Defn{ ...@@ -65,7 +65,7 @@ var testFlagDefn = []*cmdflag.Defn{
func init() { func init() {
cmdflag.AddKnownFlags("test", testFlagDefn) cmdflag.AddKnownFlags("test", testFlagDefn)
var cmd base.Command var cmd base.Command
work.AddBuildFlags(&cmd) work.AddBuildFlags(&cmd, work.DefaultBuildFlags)
cmd.Flag.VisitAll(func(f *flag.Flag) { cmd.Flag.VisitAll(func(f *flag.Flag) {
if f.Name == "v" { if f.Name == "v" {
// test overrides the build -v flag // test overrides the build -v flag
......
...@@ -114,7 +114,7 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) { ...@@ -114,7 +114,7 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) {
// Add build flags to vetFlagDefn. // Add build flags to vetFlagDefn.
var cmd base.Command var cmd base.Command
work.AddBuildFlags(&cmd) work.AddBuildFlags(&cmd, work.DefaultBuildFlags)
// This flag declaration is a placeholder: // This flag declaration is a placeholder:
// -vettool is actually parsed by the init function above. // -vettool is actually parsed by the init function above.
cmd.Flag.StringVar(new(string), "vettool", "", "path to vet tool binary") cmd.Flag.StringVar(new(string), "vettool", "", "path to vet tool binary")
......
...@@ -167,8 +167,8 @@ func init() { ...@@ -167,8 +167,8 @@ func init() {
CmdInstall.Flag.BoolVar(&cfg.BuildI, "i", false, "") CmdInstall.Flag.BoolVar(&cfg.BuildI, "i", false, "")
AddBuildFlags(CmdBuild) AddBuildFlags(CmdBuild, DefaultBuildFlags)
AddBuildFlags(CmdInstall) AddBuildFlags(CmdInstall, DefaultBuildFlags)
} }
// Note that flags consulted by other parts of the code // Note that flags consulted by other parts of the code
...@@ -216,9 +216,16 @@ func init() { ...@@ -216,9 +216,16 @@ func init() {
} }
} }
type BuildFlagMask int
const (
DefaultBuildFlags BuildFlagMask = 0
OmitModFlag BuildFlagMask = 1 << iota
)
// addBuildFlags adds the flags common to the build, clean, get, // addBuildFlags adds the flags common to the build, clean, get,
// install, list, run, and test commands. // install, list, run, and test commands.
func AddBuildFlags(cmd *base.Command) { func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
cmd.Flag.BoolVar(&cfg.BuildA, "a", false, "") cmd.Flag.BoolVar(&cfg.BuildA, "a", false, "")
cmd.Flag.BoolVar(&cfg.BuildN, "n", false, "") cmd.Flag.BoolVar(&cfg.BuildN, "n", false, "")
cmd.Flag.IntVar(&cfg.BuildP, "p", cfg.BuildP, "") cmd.Flag.IntVar(&cfg.BuildP, "p", cfg.BuildP, "")
...@@ -230,7 +237,9 @@ func AddBuildFlags(cmd *base.Command) { ...@@ -230,7 +237,9 @@ func AddBuildFlags(cmd *base.Command) {
cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "") cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
cmd.Flag.Var(&load.BuildGcflags, "gcflags", "") cmd.Flag.Var(&load.BuildGcflags, "gcflags", "")
cmd.Flag.Var(&load.BuildGccgoflags, "gccgoflags", "") cmd.Flag.Var(&load.BuildGccgoflags, "gccgoflags", "")
cmd.Flag.StringVar(&cfg.BuildMod, "mod", "", "") if mask&OmitModFlag == 0 {
cmd.Flag.StringVar(&cfg.BuildMod, "mod", "", "")
}
cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "") cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "")
cmd.Flag.Var(&load.BuildLdflags, "ldflags", "") cmd.Flag.Var(&load.BuildLdflags, "ldflags", "")
cmd.Flag.BoolVar(&cfg.BuildLinkshared, "linkshared", false, "") cmd.Flag.BoolVar(&cfg.BuildLinkshared, "linkshared", false, "")
......
...@@ -13,7 +13,7 @@ stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text$' ...@@ -13,7 +13,7 @@ stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text$'
! go list -mod=vendor -m rsc.io/quote@latest ! go list -mod=vendor -m rsc.io/quote@latest
stderr 'module lookup disabled by -mod=vendor' stderr 'module lookup disabled by -mod=vendor'
! go get -mod=vendor -u ! go get -mod=vendor -u
stderr 'go get: disabled by -mod=vendor' stderr 'flag provided but not defined: -mod'
-- go.mod -- -- go.mod --
module x module x
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment