package debug
import (
)
func () string
func () ( *BuildInfo, bool) {
return readBuildInfo(modinfo())
}
type BuildInfo struct {
Path string
Main Module
Deps []*Module
}
type Module struct {
Path string
Version string
Sum string
Replace *Module
}
func ( string) (*BuildInfo, bool) {
if len() < 32 {
return nil, false
}
= [16 : len()-16]
const (
= "path\t"
= "mod\t"
= "dep\t"
= "=>\t"
)
:= func( []string) (Module, bool) {
if len() != 2 && len() != 3 {
return Module{}, false
}
:= ""
if len() == 3 {
= [2]
}
return Module{
Path: [0],
Version: [1],
Sum: ,
}, true
}
var (
= &BuildInfo{}
*Module
string
bool
)
for len() > 0 {
:= strings.IndexByte(, '\n')
if < 0 {
break
}
, = [:], [+1:]
switch {
case strings.HasPrefix(, ):
:= [len():]
.Path =
case strings.HasPrefix(, ):
:= strings.Split([len():], "\t")
= &.Main
*, = ()
if ! {
return nil, false
}
case strings.HasPrefix(, ):
:= strings.Split([len():], "\t")
= new(Module)
.Deps = append(.Deps, )
*, = ()
if ! {
return nil, false
}
case strings.HasPrefix(, ):
:= strings.Split([len():], "\t")
if len() != 3 {
return nil, false
}
if == nil {
return nil, false
}
.Replace = &Module{
Path: [0],
Version: [1],
Sum: [2],
}
= nil
}
}
return , true
}