1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 "cmd/internal/buildid"
18 fmt
.Fprintf(os
.Stderr
, "usage: go tool buildid [-w] file\n")
23 var wflag
= flag
.Bool("w", false, "write build ID")
26 log
.SetPrefix("buildid: ")
35 id
, err
:= buildid
.ReadFile(file
)
40 fmt
.Printf("%s\n", id
)
44 f
, err
:= os
.Open(file
)
48 matches
, hash
, err
:= buildid
.FindAndHash(f
, id
, 0)
55 if i
:= strings
.LastIndex(id
, "."); i
>= 0 {
58 if len(tail
) != len(hash
)*2 {
59 log
.Fatalf("%s: cannot find %d-byte hash in id %s", file
, len(hash
), id
)
61 newID
:= id
[:len(id
)-len(tail
)] + fmt
.Sprintf("%x", hash
)
63 f
, err
= os
.OpenFile(file
, os
.O_WRONLY
, 0)
67 if err
:= buildid
.Rewrite(f
, matches
, newID
); err
!= nil {
70 if err
:= f
.Close(); err
!= nil {