aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/debug
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-02-25 14:58:30 +0000
committerBryan C. Mills <bcmills@google.com>2020-02-25 15:43:19 +0000
commit987e4e892325ea91a15a34f7a858ab007fea39c4 (patch)
treeb5b607d959ac8745d18b5a02ec76b2e58e6a7e90 /src/runtime/debug
parentb2696fde403a5b059936ac6dd22b6ec9a899e084 (diff)
downloadgo-987e4e892325ea91a15a34f7a858ab007fea39c4.tar.xz
Revert "Revert "cmd/go/internal/modload: record the replacement for the module containing package main in BuildInfo""
This reverts CL 220722. Reason for revert: rolling forward with fix. Fixes #37392 Change-Id: Iba8b0c645267777fbb7019976292d691a10b906a Reviewed-on: https://go-review.googlesource.com/c/go/+/220898 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/debug')
-rw-r--r--src/runtime/debug/mod.go51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/runtime/debug/mod.go b/src/runtime/debug/mod.go
index 837cd689a0..0381bdcc53 100644
--- a/src/runtime/debug/mod.go
+++ b/src/runtime/debug/mod.go
@@ -47,9 +47,27 @@ func readBuildInfo(data string) (*BuildInfo, bool) {
repLine = "=>\t"
)
- info := &BuildInfo{}
+ readEntryFirstLine := func(elem []string) (Module, bool) {
+ if len(elem) != 2 && len(elem) != 3 {
+ return Module{}, false
+ }
+ sum := ""
+ if len(elem) == 3 {
+ sum = elem[2]
+ }
+ return Module{
+ Path: elem[0],
+ Version: elem[1],
+ Sum: sum,
+ }, true
+ }
- var line string
+ var (
+ info = &BuildInfo{}
+ last *Module
+ line string
+ ok bool
+ )
// Reverse of cmd/go/internal/modload.PackageBuildInfo
for len(data) > 0 {
i := strings.IndexByte(data, '\n')
@@ -63,42 +81,33 @@ func readBuildInfo(data string) (*BuildInfo, bool) {
info.Path = elem
case strings.HasPrefix(line, modLine):
elem := strings.Split(line[len(modLine):], "\t")
- if len(elem) != 3 {
+ last = &info.Main
+ *last, ok = readEntryFirstLine(elem)
+ if !ok {
return nil, false
}
- info.Main = Module{
- Path: elem[0],
- Version: elem[1],
- Sum: elem[2],
- }
case strings.HasPrefix(line, depLine):
elem := strings.Split(line[len(depLine):], "\t")
- if len(elem) != 2 && len(elem) != 3 {
+ last = new(Module)
+ info.Deps = append(info.Deps, last)
+ *last, ok = readEntryFirstLine(elem)
+ if !ok {
return nil, false
}
- sum := ""
- if len(elem) == 3 {
- sum = elem[2]
- }
- info.Deps = append(info.Deps, &Module{
- Path: elem[0],
- Version: elem[1],
- Sum: sum,
- })
case strings.HasPrefix(line, repLine):
elem := strings.Split(line[len(repLine):], "\t")
if len(elem) != 3 {
return nil, false
}
- last := len(info.Deps) - 1
- if last < 0 {
+ if last == nil {
return nil, false
}
- info.Deps[last].Replace = &Module{
+ last.Replace = &Module{
Path: elem[0],
Version: elem[1],
Sum: elem[2],
}
+ last = nil
}
}
return info, true