cmd/stacks: show build info tuple using go command syntax
Also provide a hint to help reproduce and disassemble the
executable.
diff --git a/cmd/stacks/stacks.go b/cmd/stacks/stacks.go
index b2f261c..4567e15 100644
--- a/cmd/stacks/stacks.go
+++ b/cmd/stacks/stacks.go
@@ -316,11 +316,15 @@
}
func (info Info) String() string {
- s := fmt.Sprintf("%s@%s %s %s/%s",
- info.Program, info.ProgramVersion,
- info.GoVersion, info.GOOS, info.GOARCH)
+ // Emit the info tuple in a convenient form for reproducing the build.
+ s := fmt.Sprintf(
+ "GOOS=%s GOARCH=%s GOTOOLCHAIN=%s go install %s@%s",
+ info.GOOS,
+ info.GOARCH,
+ info.GoVersion,
+ info.Program, info.ProgramVersion)
if info.GoplsClient != "" {
- s += " " + info.GoplsClient
+ s += " gopls.client=" + info.GoplsClient
}
return s
}
@@ -830,7 +834,7 @@
}
// Parse the stack and get the symbol names out.
- for _, frame := range strings.Split(stack, "\n") {
+ for frame := range strings.SplitSeq(stack, "\n") {
if url := frameURL(pclntab, info, frame); url != "" {
fmt.Fprintf(body, "- [`%s`](%s)\n", frame, url)
} else {
@@ -845,6 +849,12 @@
fmt.Fprintf(body, "%s (%d)\n", info, count)
}
fmt.Fprintf(body, "```\n\n")
+
+ // Give hints for disassembling the right executable.
+ // Beware that go install behaves differently for cross-compiles;
+ // the command below was chosen to work for simple and cross builds.
+ fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
+ fmt.Fprintf(body, "To disassemble: `go tool objdump exe | less`\n\n")
}
// frameURL returns the CodeSearch URL for the stack frame, if known.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
```suggestion
fmt.Fprintf(body, "To reproducibly build: `(GOPATH=$(mktemp -d); GOOS=...etc... go install module@version && find $GOPATH/bin -type f)`\n")
```
Using GOPATH is slightly more clear, IMO, but this is still really ugly. There's got to be a better way...
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
```suggestion
fmt.Fprintf(body, "To reproducibly build: `(GOPATH=$(mktemp -d); GOOS=...etc... go install module@version && find $GOPATH/bin -type f)`\n")
```Using GOPATH is slightly more clear, IMO, but this is still really ugly. There's got to be a better way...
My alternative proposal:
```
WORK=$(mktemp -d); go -C ${WORK?} mod init build && go -C ${WORK?} get golang.org/x/tools/go...@v0.20.0 && go -C ${WORK?} build -o ${PWD?}/exe golang.org/x/tools/gopls && rm -r ${WORK?}
```
This has the advantage of putting the binary in the current directory instead of just printing the path.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
program
fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
Michael Pratt```suggestion
fmt.Fprintf(body, "To reproducibly build: `(GOPATH=$(mktemp -d); GOOS=...etc... go install module@version && find $GOPATH/bin -type f)`\n")
```Using GOPATH is slightly more clear, IMO, but this is still really ugly. There's got to be a better way...
My alternative proposal:
```
WORK=$(mktemp -d); go -C ${WORK?} mod init build && go -C ${WORK?} get golang.org/x/tools/go...@v0.20.0 && go -C ${WORK?} build -o ${PWD?}/exe golang.org/x/tools/gopls && rm -r ${WORK?}
```This has the advantage of putting the binary in the current directory instead of just printing the path.
How about `find $HOME/go/bin -type f -exec cp -f {} exe \;`? ;-)
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +2 |
fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
Michael Pratt```suggestion
fmt.Fprintf(body, "To reproducibly build: `(GOPATH=$(mktemp -d); GOOS=...etc... go install module@version && find $GOPATH/bin -type f)`\n")
```Using GOPATH is slightly more clear, IMO, but this is still really ugly. There's got to be a better way...
Alan DonovanMy alternative proposal:
```
WORK=$(mktemp -d); go -C ${WORK?} mod init build && go -C ${WORK?} get golang.org/x/tools/go...@v0.20.0 && go -C ${WORK?} build -o ${PWD?}/exe golang.org/x/tools/gopls && rm -r ${WORK?}
```This has the advantage of putting the binary in the current directory instead of just printing the path.
How about `find $HOME/go/bin -type f -exec cp -f {} exe \;`? ;-)
They all make me sad (including my suggestion), so you may pick whichever you like. 😊
I do think it would be nice to fill in GOOS, GOARCH, etc in this hint, as we do in info.String, so it is copyable.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Auto-Submit | +0 |
fmt.Fprintf(body, "To reproducibly build: `(HOME=$(mktemp -d); GOOS=...etc... go install module@version && find $HOME/go/bin -type f)`\n")
Michael Pratt```suggestion
fmt.Fprintf(body, "To reproducibly build: `(GOPATH=$(mktemp -d); GOOS=...etc... go install module@version && find $GOPATH/bin -type f)`\n")
```Using GOPATH is slightly more clear, IMO, but this is still really ugly. There's got to be a better way...
Alan DonovanMy alternative proposal:
```
WORK=$(mktemp -d); go -C ${WORK?} mod init build && go -C ${WORK?} get golang.org/x/tools/go...@v0.20.0 && go -C ${WORK?} build -o ${PWD?}/exe golang.org/x/tools/gopls && rm -r ${WORK?}
```This has the advantage of putting the binary in the current directory instead of just printing the path.
Michael PrattHow about `find $HOME/go/bin -type f -exec cp -f {} exe \;`? ;-)
They all make me sad (including my suggestion), so you may pick whichever you like. 😊
I do think it would be nice to fill in GOOS, GOARCH, etc in this hint, as we do in info.String, so it is copyable.
They all make me sad (including my suggestion), so you may pick whichever you like. 😊
I agree.
I do think it would be nice to fill in GOOS, GOARCH, etc in this hint, as we do in info.String, so it is copyable.
The problem is that the GOOS=... information is actually a table (it's the key in a histogram of counts), and I don't want to print this ugly command for every row of the table. If the command were as simple as `GOOS=... go install pkg@version` then it would be a no-brainer.
I suppose I could just show a runnable command for the first entry in the table.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |