2019-05-03 12:31:03 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build go1.12
|
|
|
|
|
2019-05-29 17:58:27 -06:00
|
|
|
package debug
|
2019-05-03 12:31:03 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"runtime/debug"
|
|
|
|
)
|
|
|
|
|
2019-05-29 17:58:27 -06:00
|
|
|
func printBuildInfo(w io.Writer, verbose bool, mode PrintMode) {
|
2019-05-03 12:31:03 -06:00
|
|
|
if info, ok := debug.ReadBuildInfo(); ok {
|
2019-06-07 13:55:45 -06:00
|
|
|
fmt.Fprintf(w, "%v %v\n", info.Path, Version)
|
2019-05-29 17:58:27 -06:00
|
|
|
printModuleInfo(w, &info.Main, mode)
|
2019-05-03 12:31:03 -06:00
|
|
|
if verbose {
|
|
|
|
for _, dep := range info.Deps {
|
2019-05-29 17:58:27 -06:00
|
|
|
printModuleInfo(w, dep, mode)
|
2019-05-03 12:31:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-06-07 13:55:45 -06:00
|
|
|
fmt.Fprintf(w, "version %s, built in $GOPATH mode", Version)
|
2019-05-03 12:31:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 17:58:27 -06:00
|
|
|
func printModuleInfo(w io.Writer, m *debug.Module, mode PrintMode) {
|
2019-05-03 12:31:03 -06:00
|
|
|
fmt.Fprintf(w, " %s@%s", m.Path, m.Version)
|
|
|
|
if m.Sum != "" {
|
|
|
|
fmt.Fprintf(w, " %s", m.Sum)
|
|
|
|
}
|
|
|
|
if m.Replace != nil {
|
|
|
|
fmt.Fprintf(w, " => %v", m.Replace.Path)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(w, "\n")
|
|
|
|
}
|