1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:46:58 -07:00

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: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2019-10-02 10:51:09 -04:00
parent c1e46af62f
commit 6145a80608
11 changed files with 29 additions and 23 deletions

View File

@ -58,6 +58,13 @@ TODO
graphic characters and spaces.
</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>
<p>

View File

@ -102,7 +102,7 @@ func init() {
// mentioned explicitly in the docs but they
// are part of the build flags.
work.AddBuildFlags(CmdClean)
work.AddBuildFlags(CmdClean, work.DefaultBuildFlags)
}
func runClean(cmd *base.Command, args []string) {

View File

@ -149,7 +149,7 @@ var (
)
func init() {
work.AddBuildFlags(CmdGenerate)
work.AddBuildFlags(CmdGenerate, work.DefaultBuildFlags)
CmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
}

View File

@ -108,7 +108,7 @@ var (
)
func init() {
work.AddBuildFlags(CmdGet)
work.AddBuildFlags(CmdGet, work.OmitModFlag)
CmdGet.Run = runGet // break init loop
CmdGet.Flag.BoolVar(&Insecure, "insecure", Insecure, "")
}

View File

@ -287,7 +287,7 @@ For more about modules, see 'go help modules'.
func init() {
CmdList.Run = runList // break init cycle
work.AddBuildFlags(CmdList)
work.AddBuildFlags(CmdList, work.DefaultBuildFlags)
}
var (

View File

@ -7,7 +7,6 @@ package modget
import (
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/get"
"cmd/go/internal/imports"
"cmd/go/internal/load"
@ -199,7 +198,7 @@ func (v *upgradeFlag) Set(s string) error {
func (v *upgradeFlag) String() string { return "" }
func init() {
work.AddBuildFlags(CmdGet)
work.AddBuildFlags(CmdGet, work.OmitModFlag)
CmdGet.Run = runGet // break init loop
CmdGet.Flag.BoolVar(&get.Insecure, "insecure", get.Insecure, "")
CmdGet.Flag.Var(&getU, "u", "")
@ -256,11 +255,6 @@ type query struct {
}
func runGet(cmd *base.Command, args []string) {
// -mod=readonly has no effect on "go get".
if cfg.BuildMod == "readonly" {
cfg.BuildMod = ""
}
switch getU {
case "", "upgrade", "patch":
// ok
@ -278,10 +272,6 @@ func runGet(cmd *base.Command, args []string) {
}
modload.LoadTests = *getT
if cfg.BuildMod == "vendor" {
base.Fatalf("go get: disabled by -mod=%s", cfg.BuildMod)
}
buildList := modload.LoadBuildList()
buildList = buildList[:len(buildList):len(buildList)] // copy on append
versionByPath := make(map[string]string)

View File

@ -49,7 +49,7 @@ See also: go build.
func init() {
CmdRun.Run = runRun // break init loop
work.AddBuildFlags(CmdRun)
work.AddBuildFlags(CmdRun, work.DefaultBuildFlags)
CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
}

View File

@ -65,7 +65,7 @@ var testFlagDefn = []*cmdflag.Defn{
func init() {
cmdflag.AddKnownFlags("test", testFlagDefn)
var cmd base.Command
work.AddBuildFlags(&cmd)
work.AddBuildFlags(&cmd, work.DefaultBuildFlags)
cmd.Flag.VisitAll(func(f *flag.Flag) {
if f.Name == "v" {
// test overrides the build -v flag

View File

@ -114,7 +114,7 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) {
// Add build flags to vetFlagDefn.
var cmd base.Command
work.AddBuildFlags(&cmd)
work.AddBuildFlags(&cmd, work.DefaultBuildFlags)
// This flag declaration is a placeholder:
// -vettool is actually parsed by the init function above.
cmd.Flag.StringVar(new(string), "vettool", "", "path to vet tool binary")

View File

@ -167,8 +167,8 @@ func init() {
CmdInstall.Flag.BoolVar(&cfg.BuildI, "i", false, "")
AddBuildFlags(CmdBuild)
AddBuildFlags(CmdInstall)
AddBuildFlags(CmdBuild, DefaultBuildFlags)
AddBuildFlags(CmdInstall, DefaultBuildFlags)
}
// Note that flags consulted by other parts of the code
@ -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,
// 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.BuildN, "n", false, "")
cmd.Flag.IntVar(&cfg.BuildP, "p", cfg.BuildP, "")
@ -230,7 +237,9 @@ func AddBuildFlags(cmd *base.Command) {
cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
cmd.Flag.Var(&load.BuildGcflags, "gcflags", "")
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.Var(&load.BuildLdflags, "ldflags", "")
cmd.Flag.BoolVar(&cfg.BuildLinkshared, "linkshared", false, "")

View File

@ -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
stderr 'module lookup disabled by -mod=vendor'
! go get -mod=vendor -u
stderr 'go get: disabled by -mod=vendor'
stderr 'flag provided but not defined: -mod'
-- go.mod --
module x