aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/modfile.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-03-15 12:40:34 -0400
committerBryan C. Mills <bcmills@google.com>2021-03-17 21:24:05 +0000
commit7e00049b5545cac8705d6df1e337c5ddc70e65e4 (patch)
treef0ae39ba49ac7c649d14412d1949dd9fdf516de8 /src/cmd/go/internal/modload/modfile.go
parent4313c2886160613ca62742d0f46665cf8954213c (diff)
downloadgo-7e00049b5545cac8705d6df1e337c5ddc70e65e4.tar.gz
go-7e00049b5545cac8705d6df1e337c5ddc70e65e4.zip
cmd/go: only add a 'go' directive to the main module when the go.mod file will be written
Then, write the 'go.mod' file with that version before further processing. That way, if the command errors out due to a change in behavior, the reason for the change in behavior will be visible in the file diffs. If the 'go.mod' file cannot be written (due to -mod=readonly or -mod=vendor), assume Go 1.11 instead of the current Go release. (cmd/go has added 'go' directives automatically, including in 'go mod init', since Go 1.12.) For #44976 Change-Id: If9d4af557366f134f40ce4c5638688ba3bab8380 Reviewed-on: https://go-review.googlesource.com/c/go/+/302051 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/modfile.go')
-rw-r--r--src/cmd/go/internal/modload/modfile.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/modfile.go b/src/cmd/go/internal/modload/modfile.go
index c6667d0bf7..2afa831583 100644
--- a/src/cmd/go/internal/modload/modfile.go
+++ b/src/cmd/go/internal/modload/modfile.go
@@ -257,10 +257,13 @@ func indexModFile(data []byte, modFile *modfile.File, needsFix bool) *modFileInd
}
i.goVersionV = ""
- if modFile.Go != nil {
+ if modFile.Go == nil {
+ rawGoVersion.Store(Target, "")
+ } else {
// We're going to use the semver package to compare Go versions, so go ahead
// and add the "v" prefix it expects once instead of every time.
i.goVersionV = "v" + modFile.Go.Version
+ rawGoVersion.Store(Target, modFile.Go.Version)
}
i.require = make(map[module.Version]requireMeta, len(modFile.Require))