mirror of
https://github.com/golang/go
synced 2024-11-18 15:14:44 -07:00
7db4ac6d26
Change-Id: Ie8232bf857b8a277abb789e3788a6b6e12048731 Reviewed-on: https://go-review.googlesource.com/c/tools/+/181938 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
39 lines
867 B
Go
39 lines
867 B
Go
// 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
|
|
|
|
package debug
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"runtime/debug"
|
|
)
|
|
|
|
func printBuildInfo(w io.Writer, verbose bool, mode PrintMode) {
|
|
if info, ok := debug.ReadBuildInfo(); ok {
|
|
fmt.Fprintf(w, "%v %v\n", info.Path, Version)
|
|
printModuleInfo(w, &info.Main, mode)
|
|
if verbose {
|
|
for _, dep := range info.Deps {
|
|
printModuleInfo(w, dep, mode)
|
|
}
|
|
}
|
|
} else {
|
|
fmt.Fprintf(w, "version %s, built in $GOPATH mode\n", Version)
|
|
}
|
|
}
|
|
|
|
func printModuleInfo(w io.Writer, m *debug.Module, mode PrintMode) {
|
|
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")
|
|
}
|