Skip to content

Commit e73e5d8

Browse files
rscgopherbot
authored andcommitted
cmd/go: introduce WriteOpts argument for WriteGoMod
This CL is a no-op, just adding the new options and plumbing it through. 'go get' will use this option to let commitRequirements know whether toolchain was mentioned explicitly on the command line. For #57001. Change-Id: Iee7145f3335e899704df3e98fb840f1aa4063b0c Reviewed-on: https://go-review.googlesource.com/c/go/+/499555 Run-TryBot: Russ Cox <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 51114a3 commit e73e5d8

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
187187
// TODO(#45551): In the future, report an error if go.mod or go.sum need to
188188
// be updated after loading the build list. This may require setting
189189
// the mode to "mod" or "readonly" depending on haveExplicitArgs.
190-
if err := modload.WriteGoMod(ctx); err != nil {
190+
if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil {
191191
base.Fatalf("go: %v", err)
192192
}
193193
}
@@ -266,7 +266,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
266266
// Don't save sums for 'go mod download' without arguments unless we're in
267267
// workspace mode; see comment above.
268268
if haveExplicitArgs || modload.WorkFilePath() != "" {
269-
if err := modload.WriteGoMod(ctx); err != nil {
269+
if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil {
270270
base.Errorf("go: %v", err)
271271
}
272272
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
379379
// Everything succeeded. Update go.mod.
380380
oldReqs := reqsFromGoMod(modload.ModFile())
381381

382-
if err := modload.WriteGoMod(ctx); err != nil {
382+
if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil {
383383
if tooNew, ok := err.(*gover.TooNewError); ok {
384384
// This can happen for 'go get go@newversion'
385385
// when all the required modules are old enough

src/cmd/go/internal/modload/init.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ func CreateModFile(ctx context.Context, modPath string) {
940940
base.Fatalf("go: %v", err)
941941
}
942942
requirements = rs
943-
if err := commitRequirements(ctx); err != nil {
943+
if err := commitRequirements(ctx, WriteOpts{}); err != nil {
944944
base.Fatalf("go: %v", err)
945945
}
946946

@@ -1515,10 +1515,14 @@ func findImportComment(file string) string {
15151515
return path
15161516
}
15171517

1518+
// WriteOpts control the behavior of WriteGoMod.
1519+
type WriteOpts struct {
1520+
}
1521+
15181522
// WriteGoMod writes the current build list back to go.mod.
1519-
func WriteGoMod(ctx context.Context) error {
1523+
func WriteGoMod(ctx context.Context, opts WriteOpts) error {
15201524
requirements = LoadModFile(ctx)
1521-
return commitRequirements(ctx)
1525+
return commitRequirements(ctx, opts)
15221526
}
15231527

15241528
// commitRequirements ensures go.mod and go.sum are up to date with the current
@@ -1530,7 +1534,7 @@ func WriteGoMod(ctx context.Context) error {
15301534
// go.mod or go.sum are out of date in a semantically significant way.
15311535
//
15321536
// In workspace mode, commitRequirements only writes changes to go.work.sum.
1533-
func commitRequirements(ctx context.Context) (err error) {
1537+
func commitRequirements(ctx context.Context, opts WriteOpts) (err error) {
15341538
if inWorkspaceMode() {
15351539
// go.mod files aren't updated in workspace mode, but we still want to
15361540
// update the go.work.sum file.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func ListModules(ctx context.Context, args []string, mode ListMode, reuseFile st
111111
if err == nil {
112112
requirements = rs
113113
if !ExplicitWriteGoMod {
114-
err = commitRequirements(ctx)
114+
err = commitRequirements(ctx, WriteOpts{})
115115
}
116116
}
117117
return mods, err

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
450450
sort.Strings(loadedPackages)
451451

452452
if !ExplicitWriteGoMod && opts.ResolveMissingImports {
453-
if err := commitRequirements(ctx); err != nil {
453+
if err := commitRequirements(ctx, WriteOpts{}); err != nil {
454454
base.Fatalf("go: %v", err)
455455
}
456456
}
@@ -733,7 +733,7 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
733733
requirements = loaded.requirements
734734

735735
if !ExplicitWriteGoMod {
736-
if err := commitRequirements(ctx); err != nil {
736+
if err := commitRequirements(ctx, WriteOpts{}); err != nil {
737737
base.Fatalf("go: %v", err)
738738
}
739739
}

src/cmd/go/internal/workcmd/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func runSync(ctx context.Context, cmd *base.Command, args []string) {
122122
SilenceMissingStdImports: true,
123123
SilencePackageErrors: true,
124124
}, "all")
125-
modload.WriteGoMod(ctx)
125+
modload.WriteGoMod(ctx, modload.WriteOpts{})
126126
}
127127

128128
wf, err := modload.ReadWorkFile(workFilePath)

0 commit comments

Comments
 (0)