-
Notifications
You must be signed in to change notification settings - Fork 813
Description
From the code, I see the buildFlags
are passed when running go build
vscode-go/src/debugAdapter/goDebug.ts
Lines 496 to 498 in 0dee1a8
if (launchArgs.buildFlags) { | |
build.push(launchArgs.buildFlags); | |
} |
However, this flag seems to be lost somewhere. I am not sure who's stripping off this. (node.js? go? something in between?)
How to reproduce:
$ cat main.go
package main
var V = "Bye"
func main() {
println(V)
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"buildFlags": "-ldflags='-X main.V=Hello'",
}
]
}
With F5
(run by delve) the program will print 'Hello' as expected.
With Ctrl+F5
(built with go build
and then run) the program will print 'Bye'.
If I use "buildFlags": "-ldflags=-X main.V=Hello"
, Ctrl+F5
works as expected, but that breaks F5
and prevents passing additional flags. (Q. Why is the launch arg's buildFlags is string
, not string[]
???)
Maybe related - see the following: if I pass quoted "-ldflags=\"-X main.V=Hello\"
, this flag is lost somewhere and not used in go
link step at all. Maybe this could be a mistake on my side, but silently dropping the flag is pretty annoying.
$ node -e 'require("child_process").execFile("go", ["build", "-o=hello", "-x", "-v", "-ldflags=\"-X main.V=Hello\"", "main.go"], (err, stdout, stderr) => { console.log(err, stdout, stderr) })'
null WORK=/var/folders/bw/6r6k9d113sv1_vvzk_1kfxbm001py5/T/go-build434685295
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile command-line-arguments=/Users/hakim/Library/Caches/go-build/2a/2af9cb66592368ea7dfeada2ab9ca250d9790d35f4bfdfae36f98fced2a18d69-d
packagefile runtime=/usr/local/go/pkg/darwin_amd64/runtime.a
...
mkdir -p $WORK/b001/exe/
cd .
/usr/local/go/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=h5dkj0otzSBVSupackWn/dh-q1CTeFGroUuR0JE04/7nT150mh-SjHVBoGjykk/h5dkj0otzSBVSupackWn -extld=clang /Users/hakim/Library/Caches/go-build/2a/2af9cb66592368ea7dfeada2ab9ca250d9790d35f4bfdfae36f98fced2a18d69-d
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/a.out # internal
mv $WORK/b001/exe/a.out hello
rm -r $WORK/b001/
cc @suzmue