mirror of
https://github.com/golang/go.git
synced 2025-05-18 13:54:40 +00:00
cmd/go: add BuildID to list -json -export
That is, the following two pieces of shell code are now equivalent: $ go tool buildid $(go list -export -f {{.Export}} strings) v_0VqA6yzwuMg2dn4u57/PXcIR2Pb8Mi9yRdcdkwe $ go list -export -f {{.BuildID}} strings v_0VqA6yzwuMg2dn4u57/PXcIR2Pb8Mi9yRdcdkwe This does not expose any information that wasn't available before, but makes this workflow simpler and faster. In the first example, we have to execute two programs, and 'go tool buildid' has to re-open the export data file to read the build ID. With the new mechanism, 'go list -export' already has the build ID ready, so we can simply print it out. Moreover, when listing lots of related packages like './...', we can now obtain all their build IDs at once. Fixes #37281. Change-Id: I8e2f65a08391b3df1a628c6e06e708b8c8cb7865 Reviewed-on: https://go-review.googlesource.com/c/go/+/263542 Trust: Daniel Martí <mvdan@mvdan.cc> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
0709e58bee
commit
0bf507efe9
@ -796,6 +796,7 @@
|
|||||||
// BinaryOnly bool // binary-only package (no longer supported)
|
// BinaryOnly bool // binary-only package (no longer supported)
|
||||||
// ForTest string // package is only for use in named test
|
// ForTest string // package is only for use in named test
|
||||||
// Export string // file containing export data (when using -export)
|
// Export string // file containing export data (when using -export)
|
||||||
|
// BuildID string // build ID of the export data (when using -export)
|
||||||
// Module *Module // info about package's containing module, if any (can be nil)
|
// Module *Module // info about package's containing module, if any (can be nil)
|
||||||
// Match []string // command-line patterns matching this package
|
// Match []string // command-line patterns matching this package
|
||||||
// DepOnly bool // package is only a dependency, not explicitly listed
|
// DepOnly bool // package is only a dependency, not explicitly listed
|
||||||
|
@ -1237,6 +1237,18 @@ func TestGoListExport(t *testing.T) {
|
|||||||
if _, err := os.Stat(file); err != nil {
|
if _, err := os.Stat(file); err != nil {
|
||||||
t.Fatalf("cannot find .Export result %s: %v", file, err)
|
t.Fatalf("cannot find .Export result %s: %v", file, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tg.run("list", "-export", "-f", "{{.BuildID}}", "strings")
|
||||||
|
buildID := strings.TrimSpace(tg.stdout.String())
|
||||||
|
if buildID == "" {
|
||||||
|
t.Fatalf(".BuildID with -export was empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
tg.run("tool", "buildid", file)
|
||||||
|
toolBuildID := strings.TrimSpace(tg.stdout.String())
|
||||||
|
if buildID != toolBuildID {
|
||||||
|
t.Fatalf(".BuildID with -export %q disagrees with 'go tool buildid' %q", buildID, toolBuildID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.
|
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.
|
||||||
|
@ -66,6 +66,7 @@ to -f '{{.ImportPath}}'. The struct being passed to the template is:
|
|||||||
BinaryOnly bool // binary-only package (no longer supported)
|
BinaryOnly bool // binary-only package (no longer supported)
|
||||||
ForTest string // package is only for use in named test
|
ForTest string // package is only for use in named test
|
||||||
Export string // file containing export data (when using -export)
|
Export string // file containing export data (when using -export)
|
||||||
|
BuildID string // build ID of the export data (when using -export)
|
||||||
Module *Module // info about package's containing module, if any (can be nil)
|
Module *Module // info about package's containing module, if any (can be nil)
|
||||||
Match []string // command-line patterns matching this package
|
Match []string // command-line patterns matching this package
|
||||||
DepOnly bool // package is only a dependency, not explicitly listed
|
DepOnly bool // package is only a dependency, not explicitly listed
|
||||||
|
@ -60,6 +60,7 @@ type PackagePublic struct {
|
|||||||
ConflictDir string `json:",omitempty"` // Dir is hidden by this other directory
|
ConflictDir string `json:",omitempty"` // Dir is hidden by this other directory
|
||||||
ForTest string `json:",omitempty"` // package is only for use in named test
|
ForTest string `json:",omitempty"` // package is only for use in named test
|
||||||
Export string `json:",omitempty"` // file containing export data (set by go list -export)
|
Export string `json:",omitempty"` // file containing export data (set by go list -export)
|
||||||
|
BuildID string `json:",omitempty"` // build ID of the export data (set by go list -export)
|
||||||
Module *modinfo.ModulePublic `json:",omitempty"` // info about package's module, if any
|
Module *modinfo.ModulePublic `json:",omitempty"` // info about package's module, if any
|
||||||
Match []string `json:",omitempty"` // command-line patterns matching this package
|
Match []string `json:",omitempty"` // command-line patterns matching this package
|
||||||
Goroot bool `json:",omitempty"` // is this package found in the Go root?
|
Goroot bool `json:",omitempty"` // is this package found in the Go root?
|
||||||
|
@ -713,6 +713,7 @@ func (b *Builder) updateBuildID(a *Action, target string, rewrite bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
a.Package.Export = c.OutputFile(outputID)
|
a.Package.Export = c.OutputFile(outputID)
|
||||||
|
a.Package.BuildID = a.buildID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,6 +433,7 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) {
|
|||||||
need &^= needBuild
|
need &^= needBuild
|
||||||
if b.NeedExport {
|
if b.NeedExport {
|
||||||
p.Export = a.built
|
p.Export = a.built
|
||||||
|
p.BuildID = a.buildID
|
||||||
}
|
}
|
||||||
if need&needCompiledGoFiles != 0 {
|
if need&needCompiledGoFiles != 0 {
|
||||||
if err := b.loadCachedSrcFiles(a); err == nil {
|
if err := b.loadCachedSrcFiles(a); err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user