]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: introduce WriteOpts argument for WriteGoMod
authorRuss Cox <rsc@golang.org>
Wed, 31 May 2023 13:57:03 +0000 (09:57 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 31 May 2023 15:21:16 +0000 (15:21 +0000)
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 <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/modcmd/download.go
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/list.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/workcmd/sync.go

index 9189240fa2ba5386a4569a62ab409a1b2c3e40ca..26ef1998de9e0d959e3ebd2392032d79604bee75 100644 (file)
@@ -187,7 +187,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
                // TODO(#45551): In the future, report an error if go.mod or go.sum need to
                // be updated after loading the build list. This may require setting
                // the mode to "mod" or "readonly" depending on haveExplicitArgs.
-               if err := modload.WriteGoMod(ctx); err != nil {
+               if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil {
                        base.Fatalf("go: %v", err)
                }
        }
@@ -266,7 +266,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
        // Don't save sums for 'go mod download' without arguments unless we're in
        // workspace mode; see comment above.
        if haveExplicitArgs || modload.WorkFilePath() != "" {
-               if err := modload.WriteGoMod(ctx); err != nil {
+               if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil {
                        base.Errorf("go: %v", err)
                }
        }
index eaa2b7d5dbb24bbcc44d0d2754ca03cca6aed0e6..ca5f0dc7630b5f4154547fde97a3359d1f9bf7d5 100644 (file)
@@ -379,7 +379,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
        // Everything succeeded. Update go.mod.
        oldReqs := reqsFromGoMod(modload.ModFile())
 
-       if err := modload.WriteGoMod(ctx); err != nil {
+       if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil {
                if tooNew, ok := err.(*gover.TooNewError); ok {
                        // This can happen for 'go get go@newversion'
                        // when all the required modules are old enough
index 1a2a516e728f40e70500524b51a2ad93c6876777..efdd339998d3dcbcd1177776a59f21c87161b1fc 100644 (file)
@@ -940,7 +940,7 @@ func CreateModFile(ctx context.Context, modPath string) {
                base.Fatalf("go: %v", err)
        }
        requirements = rs
-       if err := commitRequirements(ctx); err != nil {
+       if err := commitRequirements(ctx, WriteOpts{}); err != nil {
                base.Fatalf("go: %v", err)
        }
 
@@ -1515,10 +1515,14 @@ func findImportComment(file string) string {
        return path
 }
 
+// WriteOpts control the behavior of WriteGoMod.
+type WriteOpts struct {
+}
+
 // WriteGoMod writes the current build list back to go.mod.
-func WriteGoMod(ctx context.Context) error {
+func WriteGoMod(ctx context.Context, opts WriteOpts) error {
        requirements = LoadModFile(ctx)
-       return commitRequirements(ctx)
+       return commitRequirements(ctx, opts)
 }
 
 // commitRequirements ensures go.mod and go.sum are up to date with the current
@@ -1530,7 +1534,7 @@ func WriteGoMod(ctx context.Context) error {
 // go.mod or go.sum are out of date in a semantically significant way.
 //
 // In workspace mode, commitRequirements only writes changes to go.work.sum.
-func commitRequirements(ctx context.Context) (err error) {
+func commitRequirements(ctx context.Context, opts WriteOpts) (err error) {
        if inWorkspaceMode() {
                // go.mod files aren't updated in workspace mode, but we still want to
                // update the go.work.sum file.
index a1c2908eedb44f41486cdcc019faeb35ac97e7e0..1f210b831ea15c71d32176d46b2b79d20ea75aa0 100644 (file)
@@ -111,7 +111,7 @@ func ListModules(ctx context.Context, args []string, mode ListMode, reuseFile st
        if err == nil {
                requirements = rs
                if !ExplicitWriteGoMod {
-                       err = commitRequirements(ctx)
+                       err = commitRequirements(ctx, WriteOpts{})
                }
        }
        return mods, err
index 6c888116fec73b6ea2de30141f94538545ef1790..b4cf736d75ec69d118e429dbc9778bea96cfc320 100644 (file)
@@ -450,7 +450,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
        sort.Strings(loadedPackages)
 
        if !ExplicitWriteGoMod && opts.ResolveMissingImports {
-               if err := commitRequirements(ctx); err != nil {
+               if err := commitRequirements(ctx, WriteOpts{}); err != nil {
                        base.Fatalf("go: %v", err)
                }
        }
@@ -733,7 +733,7 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
        requirements = loaded.requirements
 
        if !ExplicitWriteGoMod {
-               if err := commitRequirements(ctx); err != nil {
+               if err := commitRequirements(ctx, WriteOpts{}); err != nil {
                        base.Fatalf("go: %v", err)
                }
        }
index eca6325442bdf12c559e13ce0ccbcd45d8c6c865..1ecc3a8339573253bd7d064f17623d7899ade374 100644 (file)
@@ -122,7 +122,7 @@ func runSync(ctx context.Context, cmd *base.Command, args []string) {
                        SilenceMissingStdImports: true,
                        SilencePackageErrors:     true,
                }, "all")
-               modload.WriteGoMod(ctx)
+               modload.WriteGoMod(ctx, modload.WriteOpts{})
        }
 
        wf, err := modload.ReadWorkFile(workFilePath)