service/dap: clarify treatment of relative output path (#2402)
* Add logging and comments to clarify relative output path treatement * Use absolute output path in one of the unittests Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
parent
3c1b94276a
commit
c44252b6fe
@ -436,8 +436,9 @@ func (s *Server) onInitializeRequest(request *dap.InitializeRequest) {
|
|||||||
s.send(response)
|
s.send(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output path for the compiled binary in debug or test modes.
|
// Default output file pathname for the compiled binary in debug or test modes,
|
||||||
const debugBinary string = "./__debug_bin"
|
// relative to the current working directory of the server.
|
||||||
|
const defaultDebugBinary string = "./__debug_bin"
|
||||||
|
|
||||||
func cleanExeName(name string) string {
|
func cleanExeName(name string) string {
|
||||||
if runtime.GOOS == "windows" && filepath.Ext(name) != ".exe" {
|
if runtime.GOOS == "windows" && filepath.Ext(name) != ".exe" {
|
||||||
@ -471,9 +472,9 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) {
|
|||||||
if mode == "debug" || mode == "test" {
|
if mode == "debug" || mode == "test" {
|
||||||
output, ok := request.Arguments["output"].(string)
|
output, ok := request.Arguments["output"].(string)
|
||||||
if !ok || output == "" {
|
if !ok || output == "" {
|
||||||
output = cleanExeName(debugBinary)
|
output = cleanExeName(defaultDebugBinary)
|
||||||
}
|
}
|
||||||
debugname, err := filepath.Abs(output)
|
debugbinary, err := filepath.Abs(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.sendInternalErrorResponse(request.Seq, err.Error())
|
s.sendInternalErrorResponse(request.Seq, err.Error())
|
||||||
return
|
return
|
||||||
@ -491,11 +492,12 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.log.Debugf("building binary at %s", debugbinary)
|
||||||
switch mode {
|
switch mode {
|
||||||
case "debug":
|
case "debug":
|
||||||
err = gobuild.GoBuild(debugname, []string{program}, buildFlags)
|
err = gobuild.GoBuild(debugbinary, []string{program}, buildFlags)
|
||||||
case "test":
|
case "test":
|
||||||
err = gobuild.GoTestBuild(debugname, []string{program}, buildFlags)
|
err = gobuild.GoTestBuild(debugbinary, []string{program}, buildFlags)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.sendErrorResponse(request.Request,
|
s.sendErrorResponse(request.Request,
|
||||||
@ -503,8 +505,8 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) {
|
|||||||
fmt.Sprintf("Build error: %s", err.Error()))
|
fmt.Sprintf("Build error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
program = debugname
|
program = debugbinary
|
||||||
s.binaryToRemove = debugname
|
s.binaryToRemove = debugbinary
|
||||||
}
|
}
|
||||||
|
|
||||||
s.setLaunchAttachArgs(request)
|
s.setLaunchAttachArgs(request)
|
||||||
|
|||||||
@ -2315,8 +2315,9 @@ func TestLaunchDebugRequest(t *testing.T) {
|
|||||||
// We reuse the harness that builds, but ignore the built binary,
|
// We reuse the harness that builds, but ignore the built binary,
|
||||||
// only relying on the source to be built in response to LaunchRequest.
|
// only relying on the source to be built in response to LaunchRequest.
|
||||||
runDebugSession(t, client, "launch", func() {
|
runDebugSession(t, client, "launch", func() {
|
||||||
|
wd, _ := os.Getwd()
|
||||||
client.LaunchRequestWithArgs(map[string]interface{}{
|
client.LaunchRequestWithArgs(map[string]interface{}{
|
||||||
"mode": "debug", "program": fixture.Source, "output": "__mydir"})
|
"mode": "debug", "program": fixture.Source, "output": filepath.Join(wd, "__mybin")})
|
||||||
}, fixture.Source)
|
}, fixture.Source)
|
||||||
})
|
})
|
||||||
// Wait for the test to finish to capture all stderr
|
// Wait for the test to finish to capture all stderr
|
||||||
@ -2346,14 +2347,14 @@ func TestLaunchRequestDefaults(t *testing.T) {
|
|||||||
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
||||||
runDebugSession(t, client, "launch", func() {
|
runDebugSession(t, client, "launch", func() {
|
||||||
client.LaunchRequestWithArgs(map[string]interface{}{
|
client.LaunchRequestWithArgs(map[string]interface{}{
|
||||||
"mode": "" /*"debug" by default*/, "program": fixture.Source, "output": "__mydir"})
|
"mode": "" /*"debug" by default*/, "program": fixture.Source, "output": "__mybin"})
|
||||||
}, fixture.Source)
|
}, fixture.Source)
|
||||||
})
|
})
|
||||||
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
||||||
runDebugSession(t, client, "launch", func() {
|
runDebugSession(t, client, "launch", func() {
|
||||||
// Use the default output directory.
|
// Use the default output directory.
|
||||||
client.LaunchRequestWithArgs(map[string]interface{}{
|
client.LaunchRequestWithArgs(map[string]interface{}{
|
||||||
/*"mode":"debug" by default*/ "program": fixture.Source, "output": "__mydir"})
|
/*"mode":"debug" by default*/ "program": fixture.Source, "output": "__mybin"})
|
||||||
}, fixture.Source)
|
}, fixture.Source)
|
||||||
})
|
})
|
||||||
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
||||||
@ -2373,7 +2374,7 @@ func TestLaunchRequestDefaultsNoDebug(t *testing.T) {
|
|||||||
"noDebug": true,
|
"noDebug": true,
|
||||||
"mode": "", /*"debug" by default*/
|
"mode": "", /*"debug" by default*/
|
||||||
"program": fixture.Source,
|
"program": fixture.Source,
|
||||||
"output": cleanExeName("__mydir")})
|
"output": cleanExeName("__mybin")})
|
||||||
}, fixture.Source)
|
}, fixture.Source)
|
||||||
})
|
})
|
||||||
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
||||||
@ -2383,7 +2384,7 @@ func TestLaunchRequestDefaultsNoDebug(t *testing.T) {
|
|||||||
"noDebug": true,
|
"noDebug": true,
|
||||||
/*"mode":"debug" by default*/
|
/*"mode":"debug" by default*/
|
||||||
"program": fixture.Source,
|
"program": fixture.Source,
|
||||||
"output": cleanExeName("__mydir")})
|
"output": cleanExeName("__mybin")})
|
||||||
}, fixture.Source)
|
}, fixture.Source)
|
||||||
})
|
})
|
||||||
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
||||||
@ -2445,7 +2446,7 @@ func TestLaunchRequestWithBuildFlags(t *testing.T) {
|
|||||||
// We reuse the harness that builds, but ignore the built binary,
|
// We reuse the harness that builds, but ignore the built binary,
|
||||||
// only relying on the source to be built in response to LaunchRequest.
|
// only relying on the source to be built in response to LaunchRequest.
|
||||||
client.LaunchRequestWithArgs(map[string]interface{}{
|
client.LaunchRequestWithArgs(map[string]interface{}{
|
||||||
"mode": "debug", "program": fixture.Source, "output": "__mydir",
|
"mode": "debug", "program": fixture.Source, "output": "__mybin",
|
||||||
"buildFlags": "-ldflags '-X main.Hello=World'"})
|
"buildFlags": "-ldflags '-X main.Hello=World'"})
|
||||||
}, fixture.Source)
|
}, fixture.Source)
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user