Skip to content

Commit 5f8fdb7

Browse files
committed
cmd/go: move functions to methods
[git-generate] cd src/cmd/go/internal/modload rf ' mv InitWorkfile State.InitWorkfile mv FindGoWork State.FindGoWork mv WillBeEnabled State.WillBeEnabled mv Enabled State.Enabled mv inWorkspaceMode State.inWorkspaceMode mv HasModRoot State.HasModRoot mv MustHaveModRoot State.MustHaveModRoot mv ModFilePath State.ModFilePath ' Change-Id: I207113868af037c9c0049f4207c3d3b4c19468bb Reviewed-on: https://go-review.googlesource.com/c/go/+/716602 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 0a95856 commit 5f8fdb7

File tree

35 files changed

+112
-112
lines changed

35 files changed

+112
-112
lines changed

src/cmd/go/internal/clean/clean.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func init() {
121121

122122
func runClean(ctx context.Context, cmd *base.Command, args []string) {
123123
moduleLoaderState := modload.NewState()
124-
modload.InitWorkfile(moduleLoaderState)
124+
moduleLoaderState.InitWorkfile()
125125
if len(args) > 0 {
126126
cacheFlag := ""
127127
switch {
@@ -143,7 +143,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
143143
// either the flags and arguments explicitly imply a package,
144144
// or no other target (such as a cache) was requested to be cleaned.
145145
cleanPkg := len(args) > 0 || cleanI || cleanR
146-
if (!modload.Enabled(moduleLoaderState) || modload.HasModRoot(moduleLoaderState)) &&
146+
if (!moduleLoaderState.Enabled() || moduleLoaderState.HasModRoot()) &&
147147
!cleanCache && !cleanModcache && !cleanTestcache && !cleanFuzzcache {
148148
cleanPkg = true
149149
}

src/cmd/go/internal/envcmd/env.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ func findEnv(env []cfg.EnvVar, name string) string {
192192
func ExtraEnvVars(loaderstate *modload.State) []cfg.EnvVar {
193193
gomod := ""
194194
modload.Init(loaderstate)
195-
if modload.HasModRoot(loaderstate) {
196-
gomod = modload.ModFilePath(loaderstate)
197-
} else if modload.Enabled(loaderstate) {
195+
if loaderstate.HasModRoot() {
196+
gomod = loaderstate.ModFilePath()
197+
} else if loaderstate.Enabled() {
198198
gomod = os.DevNull
199199
}
200-
modload.InitWorkfile(loaderstate)
200+
loaderstate.InitWorkfile()
201201
gowork := modload.WorkFilePath(loaderstate)
202202
// As a special case, if a user set off explicitly, report that in GOWORK.
203203
if cfg.Getenv("GOWORK") == "off" {

src/cmd/go/internal/fmtcmd/fmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
6161
baseGofmtArgLen := gofmtArgLen
6262

6363
for _, pkg := range load.PackagesAndErrors(moduleLoaderState, ctx, load.PackageOpts{}, args) {
64-
if modload.Enabled(moduleLoaderState) && pkg.Module != nil && !pkg.Module.Main {
64+
if moduleLoaderState.Enabled() && pkg.Module != nil && !pkg.Module.Main {
6565
if !printed {
6666
fmt.Fprintf(os.Stderr, "go: not formatting packages in dependency modules\n")
6767
printed = true

src/cmd/go/internal/generate/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func init() {
183183

184184
func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
185185
moduleLoaderState := modload.NewState()
186-
modload.InitWorkfile(moduleLoaderState)
186+
moduleLoaderState.InitWorkfile()
187187

188188
if generateRunFlag != "" {
189189
var err error
@@ -206,7 +206,7 @@ func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
206206
printed := false
207207
pkgOpts := load.PackageOpts{IgnoreImports: true}
208208
for _, pkg := range load.PackagesAndErrors(moduleLoaderState, ctx, pkgOpts, args) {
209-
if modload.Enabled(moduleLoaderState) && pkg.Module != nil && !pkg.Module.Main {
209+
if moduleLoaderState.Enabled() && pkg.Module != nil && !pkg.Module.Main {
210210
if !printed {
211211
fmt.Fprintf(os.Stderr, "go: not generating in packages in dependency modules\n")
212212
printed = true

src/cmd/go/internal/list/list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ var nl = []byte{'\n'}
420420

421421
func runList(ctx context.Context, cmd *base.Command, args []string) {
422422
moduleLoaderState := modload.NewState()
423-
modload.InitWorkfile(moduleLoaderState)
423+
moduleLoaderState.InitWorkfile()
424424

425425
if *listFmt != "" && listJson {
426426
base.Fatalf("go list -f cannot be used with -json")
427427
}
428428
if *listReuse != "" && !*listM {
429429
base.Fatalf("go list -reuse cannot be used without -m")
430430
}
431-
if *listReuse != "" && modload.HasModRoot(moduleLoaderState) {
431+
if *listReuse != "" && moduleLoaderState.HasModRoot() {
432432
base.Fatalf("go list -reuse cannot be used inside a module")
433433
}
434434

@@ -502,7 +502,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
502502
if cfg.BuildMod == "vendor" {
503503
base.Fatalf("go list -retracted cannot be used when vendoring is enabled")
504504
}
505-
if !modload.Enabled(moduleLoaderState) {
505+
if !moduleLoaderState.Enabled() {
506506
base.Fatalf("go list -retracted can only be used in module-aware mode")
507507
}
508508
}
@@ -526,7 +526,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
526526
base.Fatalf("go list -test cannot be used with -m")
527527
}
528528

529-
if modload.Init(moduleLoaderState); !modload.Enabled(moduleLoaderState) {
529+
if modload.Init(moduleLoaderState); !moduleLoaderState.Enabled() {
530530
base.Fatalf("go: list -m cannot be used with GO111MODULE=off")
531531
}
532532

src/cmd/go/internal/load/search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func MatchPackage(pattern, cwd string) func(*modload.State, *Package) bool {
5757
default:
5858
return func(s *modload.State, p *Package) bool {
5959
switch {
60-
case pattern == "tool" && modload.Enabled(s):
60+
case pattern == "tool" && s.Enabled():
6161
return s.MainModules.Tools()[p.ImportPath]
62-
case pattern == "work" && modload.Enabled(s):
62+
case pattern == "work" && s.Enabled():
6363
return p.Module != nil && s.MainModules.Contains(p.Module.Path)
6464
default:
6565
matchPath := pkgpattern.MatchPattern(pattern)

src/cmd/go/internal/modcmd/download.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ type ModuleJSON struct {
110110

111111
func runDownload(ctx context.Context, cmd *base.Command, args []string) {
112112
moduleLoaderState := modload.NewState()
113-
modload.InitWorkfile(moduleLoaderState)
113+
moduleLoaderState.InitWorkfile()
114114

115115
// Check whether modules are enabled and whether we're in a module.
116116
moduleLoaderState.ForceUseModules = true
117117
modload.ExplicitWriteGoMod = true
118118
haveExplicitArgs := len(args) > 0
119119

120-
if modload.HasModRoot(moduleLoaderState) || modload.WorkFilePath(moduleLoaderState) != "" {
120+
if moduleLoaderState.HasModRoot() || modload.WorkFilePath(moduleLoaderState) != "" {
121121
modload.LoadModFile(moduleLoaderState, ctx) // to fill MainModules
122122

123123
if haveExplicitArgs {
@@ -170,15 +170,15 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
170170
}
171171

172172
if len(args) == 0 {
173-
if modload.HasModRoot(moduleLoaderState) {
173+
if moduleLoaderState.HasModRoot() {
174174
os.Stderr.WriteString("go: no module dependencies to download\n")
175175
} else {
176176
base.Errorf("go: no modules specified (see 'go help mod download')")
177177
}
178178
base.Exit()
179179
}
180180

181-
if *downloadReuse != "" && modload.HasModRoot(moduleLoaderState) {
181+
if *downloadReuse != "" && moduleLoaderState.HasModRoot() {
182182
base.Fatalf("go mod download -reuse cannot be used inside a module")
183183
}
184184

src/cmd/go/internal/modcmd/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
233233
if len(args) == 1 {
234234
gomod = args[0]
235235
} else {
236-
gomod = modload.ModFilePath(moduleLoaderState)
236+
gomod = moduleLoaderState.ModFilePath()
237237
}
238238

239239
if *editModule != "" {

src/cmd/go/internal/modcmd/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353

5454
func runGraph(ctx context.Context, cmd *base.Command, args []string) {
5555
moduleLoaderState := modload.NewState()
56-
modload.InitWorkfile(moduleLoaderState)
56+
moduleLoaderState.InitWorkfile()
5757

5858
if len(args) > 0 {
5959
base.Fatalf("go: 'go mod graph' accepts no arguments")

src/cmd/go/internal/modcmd/vendor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func init() {
6767

6868
func runVendor(ctx context.Context, cmd *base.Command, args []string) {
6969
moduleLoaderState := modload.NewState()
70-
modload.InitWorkfile(moduleLoaderState)
70+
moduleLoaderState.InitWorkfile()
7171
if modload.WorkFilePath(moduleLoaderState) != "" {
7272
base.Fatalf("go: 'go mod vendor' cannot be run in workspace mode. Run 'go work vendor' to vendor the workspace or set 'GOWORK=off' to exit workspace mode.")
7373
}
@@ -118,7 +118,7 @@ func RunVendor(loaderstate *modload.State, ctx context.Context, vendorE bool, ve
118118
includeGoVersions := false
119119
isExplicit := map[module.Version]bool{}
120120
gv := loaderstate.MainModules.GoVersion(loaderstate)
121-
if gover.Compare(gv, "1.14") >= 0 && (modload.FindGoWork(loaderstate, base.Cwd()) != "" || modload.ModFile(loaderstate).Go != nil) {
121+
if gover.Compare(gv, "1.14") >= 0 && (loaderstate.FindGoWork(base.Cwd()) != "" || modload.ModFile(loaderstate).Go != nil) {
122122
// If the Go version is at least 1.14, annotate all explicit 'require' and
123123
// 'replace' targets found in the go.mod file so that we can perform a
124124
// stronger consistency check when -mod=vendor is set.

0 commit comments

Comments
 (0)