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>
// 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)
}
}
// 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)
}
}
// 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
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)
}
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
// 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.
if err == nil {
requirements = rs
if !ExplicitWriteGoMod {
- err = commitRequirements(ctx)
+ err = commitRequirements(ctx, WriteOpts{})
}
}
return mods, err
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)
}
}
requirements = loaded.requirements
if !ExplicitWriteGoMod {
- if err := commitRequirements(ctx); err != nil {
+ if err := commitRequirements(ctx, WriteOpts{}); err != nil {
base.Fatalf("go: %v", err)
}
}
SilenceMissingStdImports: true,
SilencePackageErrors: true,
}, "all")
- modload.WriteGoMod(ctx)
+ modload.WriteGoMod(ctx, modload.WriteOpts{})
}
wf, err := modload.ReadWorkFile(workFilePath)