[go] cmd/go: set go.work path using GOWORK, and remove -workfile flag

703 views
Skip to first unread message

Michael Matloob (Gerrit)

unread,
Feb 15, 2022, 2:29:22 PM2/15/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Michael Matloob has uploaded this change for review.

View Change

cmd/go: set go.work path using GOWORK, and remove -workfile flag

This change removes the -workfile flag and allows the go.work file path
to be set using GOWORK (which was previously read-only). This removes
the potential discrepancy and confusion between the flag and environment
variable.

GOWORK will still return the actual path of the go.work file found if it
is set to '' or 'auto'.

For #45713
Fixes #51171

Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
---
M doc/go1.18.html
M src/cmd/go/alldocs.go
M src/cmd/go/internal/base/flag.go
M src/cmd/go/internal/cfg/cfg.go
M src/cmd/go/internal/help/helpdoc.go
M src/cmd/go/internal/list/list.go
M src/cmd/go/internal/modcmd/download.go
M src/cmd/go/internal/modcmd/graph.go
M src/cmd/go/internal/modcmd/verify.go
M src/cmd/go/internal/modcmd/why.go
M src/cmd/go/internal/modload/init.go
M src/cmd/go/internal/run/run.go
M src/cmd/go/internal/test/testflag.go
M src/cmd/go/internal/work/build.go
M src/cmd/go/internal/workcmd/edit.go
M src/cmd/go/internal/workcmd/init.go
M src/cmd/go/internal/workcmd/sync.go
M src/cmd/go/internal/workcmd/use.go
M src/cmd/go/testdata/script/work.txt
M src/cmd/go/testdata/script/work_edit.txt
A src/cmd/go/testdata/script/work_gowork.txt
A src/cmd/go/testdata/script/work_init_gowork.txt
D src/cmd/go/testdata/script/work_init_workfile.txt
M src/cmd/go/testdata/script/work_nowork.txt
D src/cmd/go/testdata/script/work_workfile.txt
M src/internal/cfg/cfg.go
26 files changed, 105 insertions(+), 99 deletions(-)

diff --git a/doc/go1.18.html b/doc/go1.18.html
index 243df2b..c75bfe9 100644
--- a/doc/go1.18.html
+++ b/doc/go1.18.html
@@ -345,8 +345,8 @@
<p><!-- https://golang.org/issue/45713 -->
The <code>go</code> command now supports a "Workspace" mode. If a
<code>go.work</code> file is found in the working directory or a
- parent directory, or one is specified using the <code>-workfile</code>
- flag, it will put the <code>go</code> command into workspace mode.
+ parent directory, or one is specified using the <code>GOWORK</code>
+ environment variable, it will put the <code>go</code> command into workspace mode.
In workspace mode, the <code>go.work</code> file will be used to
determine the set of main modules used as the roots for module
resolution, instead of using the normally-found <code>go.mod</code>
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 13a3f00..63e7900 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -177,14 +177,6 @@
// directory, but it is not accessed. When -modfile is specified, an
// alternate go.sum file is also used: its path is derived from the
// -modfile flag by trimming the ".mod" extension and appending ".sum".
-// -workfile file
-// in module aware mode, use the given go.work file as a workspace file.
-// By default or when -workfile is "auto", the go command searches for a
-// file named go.work in the current directory and then containing directories
-// until one is found. If a valid go.work file is found, the modules
-// specified will collectively be used as the main modules. If -workfile
-// is "off", or a go.work file is not found in "auto" mode, workspace
-// mode is disabled.
// -overlay file
// read a JSON config file that provides an overlay for build operations.
// The file is a JSON struct with a single field, named 'Replace', that
@@ -2075,6 +2067,14 @@
// GOVCS
// Lists version control commands that may be used with matching servers.
// See 'go help vcs'.
+// GOWORK
+// In module aware mode, use the given go.work file as a workspace file.
+// By default or when GOWORK is "auto", the go command searches for a
+// file named go.work in the current directory and then containing directories
+// until one is found. If a valid go.work file is found, the modules
+// specified will collectively be used as the main modules. If GOWORK
+// is "off", or a go.work file is not found in "auto" mode, workspace
+// mode is disabled.
//
// Environment variables for use with cgo:
//
diff --git a/src/cmd/go/internal/base/flag.go b/src/cmd/go/internal/base/flag.go
index 2c72c7e..120420a 100644
--- a/src/cmd/go/internal/base/flag.go
+++ b/src/cmd/go/internal/base/flag.go
@@ -62,13 +62,6 @@
flags.Var(explicitStringFlag{value: &cfg.BuildMod, explicit: &cfg.BuildModExplicit}, "mod", "")
}

-// AddWorkfileFlag adds the workfile flag to the flag set. It enables workspace
-// mode for commands that support it by resetting the cfg.WorkFile variable
-// to "" (equivalent to auto) rather than off.
-func AddWorkfileFlag(flags *flag.FlagSet) {
- flags.Var(explicitStringFlag{value: &cfg.WorkFile, explicit: &cfg.WorkFileExplicit}, "workfile", "")
-}
-
// AddModCommonFlags adds the module-related flags common to build commands
// and 'go mod' subcommands.
func AddModCommonFlags(flags *flag.FlagSet) {
diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index 7f68d7b..deab3dd 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -49,10 +49,8 @@
BuildWork bool // -work flag
BuildX bool // -x flag

- ModCacheRW bool // -modcacherw flag
- ModFile string // -modfile flag
- WorkFile string // -workfile flag
- WorkFileExplicit bool // whether -workfile was set explicitly
+ ModCacheRW bool // -modcacherw flag
+ ModFile string // -modfile flag

CmdName string // "build", "install", "list", "mod tidy", etc.

diff --git a/src/cmd/go/internal/help/helpdoc.go b/src/cmd/go/internal/help/helpdoc.go
index d1eaad1..28ddaac 100644
--- a/src/cmd/go/internal/help/helpdoc.go
+++ b/src/cmd/go/internal/help/helpdoc.go
@@ -545,6 +545,14 @@
GOVCS
Lists version control commands that may be used with matching servers.
See 'go help vcs'.
+ GOWORK
+ In module aware mode, use the given go.work file as a workspace file.
+ By default or when GOWORK is "auto", the go command searches for a
+ file named go.work in the current directory and then containing directories
+ until one is found. If a valid go.work file is found, the modules
+ specified will collectively be used as the main modules. If GOWORK
+ is "off", or a go.work file is not found in "auto" mode, workspace
+ mode is disabled.

Environment variables for use with cgo:

diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index d9a7078..8be9211 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -316,7 +316,6 @@
func init() {
CmdList.Run = runList // break init cycle
work.AddBuildFlags(CmdList, work.DefaultBuildFlags)
- base.AddWorkfileFlag(&CmdList.Flag)
}

var (
diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go
index 6b8a010..5bc6cbc 100644
--- a/src/cmd/go/internal/modcmd/download.go
+++ b/src/cmd/go/internal/modcmd/download.go
@@ -70,7 +70,6 @@
// TODO(jayconrod): https://golang.org/issue/35849 Apply -x to other 'go mod' commands.
cmdDownload.Flag.BoolVar(&cfg.BuildX, "x", false, "")
base.AddModCommonFlags(&cmdDownload.Flag)
- base.AddWorkfileFlag(&cmdDownload.Flag)
}

type moduleJSON struct {
diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go
index 9b6aa1f..9568c65 100644
--- a/src/cmd/go/internal/modcmd/graph.go
+++ b/src/cmd/go/internal/modcmd/graph.go
@@ -42,7 +42,6 @@
func init() {
cmdGraph.Flag.Var(&graphGo, "go", "")
base.AddModCommonFlags(&cmdGraph.Flag)
- base.AddWorkfileFlag(&cmdGraph.Flag)
}

func runGraph(ctx context.Context, cmd *base.Command, args []string) {
diff --git a/src/cmd/go/internal/modcmd/verify.go b/src/cmd/go/internal/modcmd/verify.go
index 3f0c005..459bf5d 100644
--- a/src/cmd/go/internal/modcmd/verify.go
+++ b/src/cmd/go/internal/modcmd/verify.go
@@ -39,7 +39,6 @@

func init() {
base.AddModCommonFlags(&cmdVerify.Flag)
- base.AddWorkfileFlag(&cmdVerify.Flag)
}

func runVerify(ctx context.Context, cmd *base.Command, args []string) {
diff --git a/src/cmd/go/internal/modcmd/why.go b/src/cmd/go/internal/modcmd/why.go
index d8355cc..2d3f1eb 100644
--- a/src/cmd/go/internal/modcmd/why.go
+++ b/src/cmd/go/internal/modcmd/why.go
@@ -59,7 +59,6 @@
func init() {
cmdWhy.Run = runWhy // break init cycle
base.AddModCommonFlags(&cmdWhy.Flag)
- base.AddWorkfileFlag(&cmdWhy.Flag)
}

func runWhy(ctx context.Context, cmd *base.Command, args []string) {
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index e5de101..d8b9a32 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -288,16 +288,16 @@
// operate in workspace mode. It should not be called by other commands,
// for example 'go mod tidy', that don't operate in workspace mode.
func InitWorkfile() {
- switch cfg.WorkFile {
+ switch gowork := cfg.Getenv("GOWORK"); gowork {
case "off":
workFilePath = ""
case "", "auto":
workFilePath = findWorkspaceFile(base.Cwd())
default:
- if !filepath.IsAbs(cfg.WorkFile) {
- base.Fatalf("the path provided to -workfile must be an absolute path")
+ if !filepath.IsAbs(gowork) {
+ base.Fatalf("the path provided to GOWORK must be an absolute path")
}
- workFilePath = cfg.WorkFile
+ workFilePath = gowork
}
}

@@ -1095,7 +1095,7 @@
if inWorkspaceMode() && cfg.BuildMod != "readonly" {
base.Fatalf("go: -mod may only be set to readonly when in workspace mode, but it is set to %q"+
"\n\tRemove the -mod flag to use the default readonly value,"+
- "\n\tor set -workfile=off to disable workspace mode.", cfg.BuildMod)
+ "\n\tor set GOWORK=off to disable workspace mode.", cfg.BuildMod)
}
// Don't override an explicit '-mod=' argument.
return
diff --git a/src/cmd/go/internal/run/run.go b/src/cmd/go/internal/run/run.go
index c4b70b6..00a3e4b 100644
--- a/src/cmd/go/internal/run/run.go
+++ b/src/cmd/go/internal/run/run.go
@@ -65,7 +65,6 @@
CmdRun.Run = runRun // break init loop

work.AddBuildFlags(CmdRun, work.DefaultBuildFlags)
- base.AddWorkfileFlag(&CmdRun.Flag)
CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
}

diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go
index b9d1ec9..c046cac 100644
--- a/src/cmd/go/internal/test/testflag.go
+++ b/src/cmd/go/internal/test/testflag.go
@@ -28,7 +28,6 @@

func init() {
work.AddBuildFlags(CmdTest, work.OmitVFlag)
- base.AddWorkfileFlag(&CmdTest.Flag)

cf := CmdTest.Flag
cf.BoolVar(&testC, "c", false, "")
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 1c278d3..0b5848a 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -130,14 +130,6 @@
directory, but it is not accessed. When -modfile is specified, an
alternate go.sum file is also used: its path is derived from the
-modfile flag by trimming the ".mod" extension and appending ".sum".
- -workfile file
- in module aware mode, use the given go.work file as a workspace file.
- By default or when -workfile is "auto", the go command searches for a
- file named go.work in the current directory and then containing directories
- until one is found. If a valid go.work file is found, the modules
- specified will collectively be used as the main modules. If -workfile
- is "off", or a go.work file is not found in "auto" mode, workspace
- mode is disabled.
-overlay file
read a JSON config file that provides an overlay for build operations.
The file is a JSON struct with a single field, named 'Replace', that
@@ -217,7 +209,6 @@

AddBuildFlags(CmdBuild, DefaultBuildFlags)
AddBuildFlags(CmdInstall, DefaultBuildFlags)
- base.AddWorkfileFlag(&CmdBuild.Flag)
}

// Note that flags consulted by other parts of the code
diff --git a/src/cmd/go/internal/workcmd/edit.go b/src/cmd/go/internal/workcmd/edit.go
index e7b1b13..05f4f3d 100644
--- a/src/cmd/go/internal/workcmd/edit.go
+++ b/src/cmd/go/internal/workcmd/edit.go
@@ -110,8 +110,6 @@
cmdEdit.Flag.Var(flagFunc(flagEditworkDropUse), "dropuse", "")
cmdEdit.Flag.Var(flagFunc(flagEditworkReplace), "replace", "")
cmdEdit.Flag.Var(flagFunc(flagEditworkDropReplace), "dropreplace", "")
-
- base.AddWorkfileFlag(&cmdEdit.Flag)
}

func runEditwork(ctx context.Context, cmd *base.Command, args []string) {
@@ -137,7 +135,7 @@
}

if gowork == "" {
- base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using -workfile flag)")
+ base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}

anyFlags :=
diff --git a/src/cmd/go/internal/workcmd/init.go b/src/cmd/go/internal/workcmd/init.go
index aa31263..63bee6e 100644
--- a/src/cmd/go/internal/workcmd/init.go
+++ b/src/cmd/go/internal/workcmd/init.go
@@ -33,7 +33,6 @@

func init() {
base.AddModCommonFlags(&cmdInit.Flag)
- base.AddWorkfileFlag(&cmdInit.Flag)
}

func runInit(ctx context.Context, cmd *base.Command, args []string) {
@@ -41,11 +40,6 @@

modload.ForceUseModules = true

- // TODO(matloob): support using the -workfile path
- // To do that properly, we'll have to make the module directories
- // make dirs relative to workFile path before adding the paths to
- // the directory entries
-
workFile := modload.WorkFilePath()
if workFile == "" {
workFile = filepath.Join(base.Cwd(), "go.work")
diff --git a/src/cmd/go/internal/workcmd/sync.go b/src/cmd/go/internal/workcmd/sync.go
index 948fc5d..b0f61c5 100644
--- a/src/cmd/go/internal/workcmd/sync.go
+++ b/src/cmd/go/internal/workcmd/sync.go
@@ -39,14 +39,13 @@

func init() {
base.AddModCommonFlags(&cmdSync.Flag)
- base.AddWorkfileFlag(&cmdSync.Flag)
}

func runSync(ctx context.Context, cmd *base.Command, args []string) {
modload.ForceUseModules = true
modload.InitWorkfile()
if modload.WorkFilePath() == "" {
- base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using -workfile flag)")
+ base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}

workGraph := modload.LoadModGraph(ctx, "")
diff --git a/src/cmd/go/internal/workcmd/use.go b/src/cmd/go/internal/workcmd/use.go
index 3d003b7..1ee2d4e 100644
--- a/src/cmd/go/internal/workcmd/use.go
+++ b/src/cmd/go/internal/workcmd/use.go
@@ -42,7 +42,6 @@
cmdUse.Run = runUse // break init cycle

base.AddModCommonFlags(&cmdUse.Flag)
- base.AddWorkfileFlag(&cmdUse.Flag)
}

func runUse(ctx context.Context, cmd *base.Command, args []string) {
@@ -53,7 +52,7 @@
gowork = modload.WorkFilePath()

if gowork == "" {
- base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using -workfile flag)")
+ base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}
workFile, err := modload.ReadWorkFile(gowork)
if err != nil {
diff --git a/src/cmd/go/testdata/script/work.txt b/src/cmd/go/testdata/script/work.txt
index cbb3746..a10bf5a 100644
--- a/src/cmd/go/testdata/script/work.txt
+++ b/src/cmd/go/testdata/script/work.txt
@@ -32,7 +32,9 @@
go list -mod=readonly all
! go list -mod=mod all
stderr '^go: -mod may only be set to readonly when in workspace mode'
-go list -mod=mod -workfile=off all
+env GOWORK=off
+go list -mod=mod all
+env GOWORK=

# Test that duplicates in the use list return an error
cp go.work go.work.backup
@@ -53,7 +55,9 @@
# This exercises the code that determines which module command-line-arguments
# belongs to.
go list ./b/main.go
-go build -n -workfile=off -o foo foo.go
+env GOWORK=off
+go build -n -o foo foo.go
+env GOWORK=
go build -n -o foo foo.go

-- go.work.dup --
diff --git a/src/cmd/go/testdata/script/work_edit.txt b/src/cmd/go/testdata/script/work_edit.txt
index fd04bbd..71959ca 100644
--- a/src/cmd/go/testdata/script/work_edit.txt
+++ b/src/cmd/go/testdata/script/work_edit.txt
@@ -30,7 +30,8 @@
go work edit -json -go 1.19 -use b -dropuse c -replace 'x...@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x...@v1.3.0
cmp stdout go.work.want_json

-go work edit -print -fmt -workfile $GOPATH/src/unformatted
+env GOWORK=$GOPATH/src/unformatted
+go work edit -print -fmt
cmp stdout formatted

-- m/go.mod --
diff --git a/src/cmd/go/testdata/script/work_gowork.txt b/src/cmd/go/testdata/script/work_gowork.txt
new file mode 100644
index 0000000..1cfbf0c
--- /dev/null
+++ b/src/cmd/go/testdata/script/work_gowork.txt
@@ -0,0 +1,24 @@
+env GOWORK=stop.work
+! go list a # require absolute path
+! stderr panic
+env GOWORK=doesnotexist
+! go list a
+! stderr panic
+
+env GOWORK=$GOPATH/src/stop.work
+go list -n a
+go build -n a
+go test -n a
+
+-- stop.work --
+go 1.18
+
+use ./a
+-- a/a.go --
+package a
+-- a/a_test.go --
+package a
+-- a/go.mod --
+module a
+
+go 1.18
\ No newline at end of file
diff --git a/src/cmd/go/testdata/script/work_init_gowork.txt b/src/cmd/go/testdata/script/work_init_gowork.txt
new file mode 100644
index 0000000..55ac99b
--- /dev/null
+++ b/src/cmd/go/testdata/script/work_init_gowork.txt
@@ -0,0 +1,19 @@
+# Test that the GOWORK environment variable flag is used by go work init.
+
+! exists go.work
+go work init
+exists go.work
+
+env GOWORK=$GOPATH/src/foo/foo.work
+! exists foo/foo.work
+go work init
+exists foo/foo.work
+
+env GOWORK=
+cd foo/bar
+! go work init
+stderr 'already exists'
+
+# Create directories to make go.work files in.
+-- foo/dummy.txt --
+-- foo/bar/dummy.txt --
diff --git a/src/cmd/go/testdata/script/work_init_workfile.txt b/src/cmd/go/testdata/script/work_init_workfile.txt
deleted file mode 100644
index e6f5671..0000000
--- a/src/cmd/go/testdata/script/work_init_workfile.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-# Test that the workfile flag is used by go work init.
-
-go work init
-exists go.work
-
-go work init -workfile=$GOPATH/src/foo/foo.work
-exists foo/foo.work
-
-cd foo/bar
-! go work init
-stderr 'already exists'
-
-# Create directories to make go.work files in.
--- foo/dummy.txt --
--- foo/bar/dummy.txt --
diff --git a/src/cmd/go/testdata/script/work_nowork.txt b/src/cmd/go/testdata/script/work_nowork.txt
index b0320cb..b4c9b1d 100644
--- a/src/cmd/go/testdata/script/work_nowork.txt
+++ b/src/cmd/go/testdata/script/work_nowork.txt
@@ -1,17 +1,17 @@
! go work use
-stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using GOWORK environment variable\)$'

! go work use .
-stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using GOWORK environment variable\)$'

! go work edit
-stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using GOWORK environment variable\)$'

! go work edit -go=1.18
-stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using GOWORK environment variable\)$'

! go work sync
-stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using GOWORK environment variable\)$'

-- go.mod --
module example
diff --git a/src/cmd/go/testdata/script/work_workfile.txt b/src/cmd/go/testdata/script/work_workfile.txt
deleted file mode 100644
index b629181..0000000
--- a/src/cmd/go/testdata/script/work_workfile.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-! go list -workfile=stop.work a # require absolute path
-! stderr panic
-! go list -workfile=doesnotexist a
-! stderr panic
-
-go list -n -workfile=$GOPATH/src/stop.work a
-go build -n -workfile=$GOPATH/src/stop.work a
-go test -n -workfile=$GOPATH/src/stop.work a
-
--- stop.work --
-go 1.18
-
-use ./a
--- a/a.go --
-package a
--- a/a_test.go --
-package a
--- a/go.mod --
-module a
-
-go 1.18
\ No newline at end of file
diff --git a/src/internal/cfg/cfg.go b/src/internal/cfg/cfg.go
index 4cb3fbd..78664d7 100644
--- a/src/internal/cfg/cfg.go
+++ b/src/internal/cfg/cfg.go
@@ -62,6 +62,7 @@
GOTOOLDIR
GOVCS
GOWASM
+ GOWORK
GO_EXTLINK_ENABLED
PKG_CONFIG
`

To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
Gerrit-Change-Number: 385995
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Matloob <mat...@golang.org>
Gerrit-MessageType: newchange

Michael Matloob (Gerrit)

unread,
Feb 15, 2022, 2:29:58 PM2/15/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Patch set 1:Run-TryBot +1Trust +1

View Change

1 comment:

  • Patchset:

    • Patch Set #1:

      TRY=linux-386-longtest, linux-amd64-longtest, windows-amd64-longtest

To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
Gerrit-Change-Number: 385995
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Tue, 15 Feb 2022 19:29:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Bryan Mills (Gerrit)

unread,
Feb 15, 2022, 3:22:56 PM2/15/22
to Michael Matloob, goph...@pubsubhelper.golang.org, Bryan Mills, Gopher Robot, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Patch set 1:Code-Review +2

View Change

1 comment:

    • GOWORK will still return the actual path of the go.work file found if it
      is set to '' or 'auto'.

    • What happens if `GOWORK` is explicitly set to `off`?

      (If `go env GOWORK` reports the empty string, that could lead to some confusing interactions — maybe `go env GOWORK` should print `off` when `GOWORK=off` is set explicitly?)

To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
Gerrit-Change-Number: 385995
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Tue, 15 Feb 2022 20:22:51 +0000

Michael Matloob (Gerrit)

unread,
Feb 15, 2022, 5:41:39 PM2/15/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Michael Matloob uploaded patch set #2 to this change.

View Change

cmd/go: set go.work path using GOWORK, and remove -workfile flag

This change removes the -workfile flag and allows the go.work file path
to be set using GOWORK (which was previously read-only). This removes
the potential discrepancy and confusion between the flag and environment
variable.

GOWORK will still return the actual path of the go.work file found if it
is set to '' or 'auto'. GOWORK will return 'off' if it is set to 'off'.


For #45713
Fixes #51171

Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
---
M doc/go1.18.html
M src/cmd/go/alldocs.go
M src/cmd/go/internal/base/flag.go
M src/cmd/go/internal/cfg/cfg.go
M src/cmd/go/internal/envcmd/env.go

M src/cmd/go/internal/help/helpdoc.go
M src/cmd/go/internal/list/list.go
M src/cmd/go/internal/modcmd/download.go
M src/cmd/go/internal/modcmd/graph.go
M src/cmd/go/internal/modcmd/verify.go
M src/cmd/go/internal/modcmd/why.go
M src/cmd/go/internal/modload/init.go
M src/cmd/go/internal/run/run.go
M src/cmd/go/internal/test/testflag.go
M src/cmd/go/internal/work/build.go
M src/cmd/go/internal/workcmd/edit.go
M src/cmd/go/internal/workcmd/init.go
M src/cmd/go/internal/workcmd/sync.go
M src/cmd/go/internal/workcmd/use.go
M src/cmd/go/testdata/script/work.txt
M src/cmd/go/testdata/script/work_edit.txt
M src/cmd/go/testdata/script/work_env.txt

A src/cmd/go/testdata/script/work_gowork.txt
A src/cmd/go/testdata/script/work_init_gowork.txt
D src/cmd/go/testdata/script/work_init_workfile.txt
M src/cmd/go/testdata/script/work_nowork.txt
D src/cmd/go/testdata/script/work_workfile.txt
M src/internal/cfg/cfg.go
28 files changed, 113 insertions(+), 99 deletions(-)

To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
Gerrit-Change-Number: 385995
Gerrit-PatchSet: 2
Gerrit-Owner: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-MessageType: newpatchset

Michael Matloob (Gerrit)

unread,
Feb 15, 2022, 5:42:08 PM2/15/22
to goph...@pubsubhelper.golang.org, Bryan Mills, Gopher Robot, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

View Change

1 comment:

  • Commit Message:

    • GOWORK will still return the actual path of the go.work file found if it


    • is set to '' or 'auto'.

    • What happens if `GOWORK` is explicitly set to `off`? […]

      I added a special case to return 'off'.

To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
Gerrit-Change-Number: 385995
Gerrit-PatchSet: 2
Gerrit-Owner: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Comment-Date: Tue, 15 Feb 2022 22:42:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Bryan Mills <bcm...@google.com>
Gerrit-MessageType: comment

Bryan Mills (Gerrit)

unread,
Feb 15, 2022, 6:00:57 PM2/15/22
to Michael Matloob, goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Patch set 2:Code-Review +2

View Change

    To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
    Gerrit-Change-Number: 385995
    Gerrit-PatchSet: 2
    Gerrit-Owner: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Attention: Michael Matloob <mat...@golang.org>
    Gerrit-Comment-Date: Tue, 15 Feb 2022 23:00:53 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Michael Matloob (Gerrit)

    unread,
    Feb 16, 2022, 10:58:51 AM2/16/22
    to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, Bryan Mills, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

    Michael Matloob submitted this change.

    View Change


    Approvals: Bryan Mills: Looks good to me, approved Michael Matloob: Trusted; Run TryBots Gopher Robot: TryBots succeeded
    cmd/go: set go.work path using GOWORK, and remove -workfile flag

    This change removes the -workfile flag and allows the go.work file path
    to be set using GOWORK (which was previously read-only). This removes
    the potential discrepancy and confusion between the flag and environment
    variable.

    GOWORK will still return the actual path of the go.work file found if it
    is set to '' or 'auto'. GOWORK will return 'off' if it is set to 'off'.

    For #45713
    Fixes #51171

    Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
    Reviewed-on: https://go-review.googlesource.com/c/go/+/385995
    Trust: Michael Matloob <mat...@golang.org>
    Run-TryBot: Michael Matloob <mat...@golang.org>
    TryBot-Result: Gopher Robot <go...@golang.org>
    Reviewed-by: Bryan Mills <bcm...@google.com>
    28 files changed, 118 insertions(+), 99 deletions(-)

    diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go
    index e56dd82..c1adf8c 100644
    --- a/src/cmd/go/internal/envcmd/env.go
    +++ b/src/cmd/go/internal/envcmd/env.go
    @@ -154,6 +154,10 @@
    }
    modload.InitWorkfile()
    gowork := modload.WorkFilePath()
    + // As a special case, if a user set off explicitly, report that in GOWORK.
    + if cfg.Getenv("GOWORK") == "off" {
    + gowork = "off"
    + }
    return []cfg.EnvVar{
    {Name: "GOMOD", Value: gomod},
    {Name: "GOWORK", Value: gowork},
    index 523be8c..a070666 100644

    --- a/src/cmd/go/internal/modload/init.go
    +++ b/src/cmd/go/internal/modload/init.go
    @@ -288,16 +288,16 @@
    // operate in workspace mode. It should not be called by other commands,
    // for example 'go mod tidy', that don't operate in workspace mode.
    func InitWorkfile() {
    - switch cfg.WorkFile {
    + switch gowork := cfg.Getenv("GOWORK"); gowork {
    case "off":
    workFilePath = ""
    case "", "auto":
    workFilePath = findWorkspaceFile(base.Cwd())
    default:
    - if !filepath.IsAbs(cfg.WorkFile) {
    - base.Fatalf("the path provided to -workfile must be an absolute path")
    + if !filepath.IsAbs(gowork) {
    + base.Fatalf("the path provided to GOWORK must be an absolute path")
    }
    - workFilePath = cfg.WorkFile
    + workFilePath = gowork
    }
    }

    @@ -1109,7 +1109,7 @@
    diff --git a/src/cmd/go/testdata/script/work_env.txt b/src/cmd/go/testdata/script/work_env.txt
    index ec3d3be..511bb4e 100644
    --- a/src/cmd/go/testdata/script/work_env.txt
    +++ b/src/cmd/go/testdata/script/work_env.txt
    @@ -13,6 +13,10 @@
    go env GOWORK
    stdout 'go.work'

    +env GOWORK='off'
    +go env GOWORK
    +stdout 'off'
    +
    ! go env -w GOWORK=off
    stderr '^go: GOWORK cannot be modified$'

    To view, visit change 385995. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3
    Gerrit-Change-Number: 385995
    Gerrit-PatchSet: 3
    Gerrit-Owner: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-MessageType: merged
    Reply all
    Reply to author
    Forward
    0 new messages