diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index 2cda26e0d0..876589d6c5 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -542,6 +542,11 @@ func dapCmd(cmd *cobra.Command, args []string) { os.Exit(status) } +// gopdlv: add `goTool` +func goTool(cmd *cobra.Command) string { + return "gop" // TODO +} + func buildBinary(cmd *cobra.Command, args []string, isTest bool) (string, bool) { outputFlag := cmd.Flag("output").Value.String() var debugname string @@ -561,9 +566,9 @@ func buildBinary(cmd *cobra.Command, args []string, isTest bool) (string, bool) } if isTest { - err = gobuild.GoTestBuild(debugname, args, buildFlags) + err = gobuild.GoTestBuild(goTool(cmd), debugname, args, buildFlags) } else { - err = gobuild.GoBuild(debugname, args, buildFlags) + err = gobuild.GoBuild(goTool(cmd), debugname, args, buildFlags) } if err != nil { if outputFlag == "" { diff --git a/pkg/gobuild/gobuild.go b/pkg/gobuild/gobuild.go index e5f90d610a..1c776d9eed 100644 --- a/pkg/gobuild/gobuild.go +++ b/pkg/gobuild/gobuild.go @@ -34,36 +34,40 @@ func Remove(path string) { // GoBuild builds non-test files in 'pkgs' with the specified 'buildflags' // and writes the output at 'debugname'. -func GoBuild(debugname string, pkgs []string, buildflags string) error { +// gopdlv: add `goTool` param +func GoBuild(goTool, debugname string, pkgs []string, buildflags string) error { args := goBuildArgs(debugname, pkgs, buildflags, false) - return gocommandRun("build", args...) + return gocommandRun(goTool, "build", args...) } // GoBuildCombinedOutput builds non-test files in 'pkgs' with the specified 'buildflags' // and writes the output at 'debugname'. -func GoBuildCombinedOutput(debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) { +// gopdlv: add `goTool` param +func GoBuildCombinedOutput(goTool, debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) { args, err := goBuildArgs2(debugname, pkgs, buildflags, false) if err != nil { return "", nil, err } - return gocommandCombinedOutput("build", args...) + return gocommandCombinedOutput(goTool, "build", args...) } // GoTestBuild builds test files 'pkgs' with the specified 'buildflags' // and writes the output at 'debugname'. -func GoTestBuild(debugname string, pkgs []string, buildflags string) error { +// gopdlv: add `goTool` param +func GoTestBuild(goTool, debugname string, pkgs []string, buildflags string) error { args := goBuildArgs(debugname, pkgs, buildflags, true) - return gocommandRun("test", args...) + return gocommandRun(goTool, "test", args...) } // GoTestBuildCombinedOutput builds test files 'pkgs' with the specified 'buildflags' // and writes the output at 'debugname'. -func GoTestBuildCombinedOutput(debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) { +// gopdlv: add `goTool` param +func GoTestBuildCombinedOutput(goTool, debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) { args, err := goBuildArgs2(debugname, pkgs, buildflags, true) if err != nil { return "", nil, err } - return gocommandCombinedOutput("test", args...) + return gocommandCombinedOutput(goTool, "test", args...) } func goBuildArgs(debugname string, pkgs []string, buildflags string, isTest bool) []string { @@ -111,25 +115,27 @@ func goBuildArgs2(debugname string, pkgs []string, buildflags interface{}, isTes return append(args, pkgs...), nil } -func gocommandRun(command string, args ...string) error { - _, goBuild := gocommandExecCmd(command, args...) +// gopdlv: add `goTool` param +func gocommandRun(goTool, command string, args ...string) error { + _, goBuild := gocommandExecCmd(goTool, command, args...) goBuild.Stderr = os.Stdout goBuild.Stdout = os.Stderr return goBuild.Run() } -func gocommandCombinedOutput(command string, args ...string) (string, []byte, error) { - buildCmd, goBuild := gocommandExecCmd(command, args...) +// gopdlv: add `goTool` param +func gocommandCombinedOutput(goTool, command string, args ...string) (string, []byte, error) { + buildCmd, goBuild := gocommandExecCmd(goTool, command, args...) out, err := goBuild.CombinedOutput() return buildCmd, out, err } -func gocommandExecCmd(command string, args ...string) (string, *exec.Cmd) { +func gocommandExecCmd(goTool, command string, args ...string) (string, *exec.Cmd) { allargs := []string{command} allargs = append(allargs, args...) - // gopdlv: Go+ + // gopdlv: add `goTool` param // goBuild := exec.Command("go", allargs...) // return strings.Join(append([]string{"go"}, allargs...), " "), goBuild - goBuild := exec.Command("gop", allargs...) - return strings.Join(append([]string{"gop"}, allargs...), " "), goBuild + goBuild := exec.Command(goTool, allargs...) + return strings.Join(append([]string{goTool}, allargs...), " "), goBuild } diff --git a/service/dap/server.go b/service/dap/server.go index 9846763454..ff8e69d418 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -989,9 +989,9 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) { switch args.Mode { case "debug": - cmd, out, err = gobuild.GoBuildCombinedOutput(args.Output, []string{args.Program}, args.BuildFlags.value) + cmd, out, err = gobuild.GoBuildCombinedOutput(args.goTool(), args.Output, []string{args.Program}, args.BuildFlags.value) case "test": - cmd, out, err = gobuild.GoTestBuildCombinedOutput(args.Output, []string{args.Program}, args.BuildFlags.value) + cmd, out, err = gobuild.GoTestBuildCombinedOutput(args.goTool(), args.Output, []string{args.Program}, args.BuildFlags.value) } args.DlvCwd, _ = filepath.Abs(args.DlvCwd) s.config.log.Debugf("building from %q: [%s]", args.DlvCwd, cmd) diff --git a/service/dap/types.go b/service/dap/types.go index 1ab685f965..4ae8c71a5c 100644 --- a/service/dap/types.go +++ b/service/dap/types.go @@ -74,6 +74,10 @@ type LaunchConfig struct { // Default is "debug". Mode string `json:"mode,omitempty"` + // goxdlv: add `goTool` + // Tool is the command to build/test packages. Default is `gop` (not `go`). + Tool string `json:"tool,omitempty"` + // Path to the program folder (or any go file within that folder) // when in `debug` or `test` mode, and to the pre-built binary file // to debug in `exec` mode. @@ -160,6 +164,13 @@ type LaunchConfig struct { LaunchAttachCommonConfig } +func (p *LaunchConfig) goTool() string { + if p.Tool == "" { + return "gop" + } + return p.Tool +} + // LaunchAttachCommonConfig is the attributes common in both launch/attach requests. type LaunchAttachCommonConfig struct { // Automatically stop program after launch or attach. diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 229c032adb..c5025d6c45 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -136,6 +136,10 @@ type Config struct { // TTY for that process. TTY string + // goxdlv: add `goTool` + // Tool is the command to build/test packages. Default is `gop` (not `go`). + Tool string + // Packages contains the packages that we are debugging. Packages []string @@ -160,6 +164,13 @@ type Config struct { RrOnProcessPid int } +func (p *Config) goTool() string { + if p.Tool == "" { + return "gop" + } + return p.Tool +} + // New creates a new Debugger. ProcessArgs specify the commandline arguments for the // new process. func New(config *Config, processArgs []string) (*Debugger, error) { @@ -515,12 +526,12 @@ func (d *Debugger) Restart(rerecord bool, pos string, resetArgs bool, newArgs [] if rebuild { switch d.config.ExecuteKind { case ExecutingGeneratedFile: - err = gobuild.GoBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags) + err = gobuild.GoBuild(d.config.goTool(), d.processArgs[0], d.config.Packages, d.config.BuildFlags) if err != nil { return nil, fmt.Errorf("could not rebuild process: %s", err) } case ExecutingGeneratedTest: - err = gobuild.GoTestBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags) + err = gobuild.GoTestBuild(d.config.goTool(), d.processArgs[0], d.config.Packages, d.config.BuildFlags) if err != nil { return nil, fmt.Errorf("could not rebuild process: %s", err) } diff --git a/service/debugger/debugger_test.go b/service/debugger/debugger_test.go index c493ff9804..6ee891fdae 100644 --- a/service/debugger/debugger_test.go +++ b/service/debugger/debugger_test.go @@ -13,13 +13,17 @@ import ( "github.com/go-delve/delve/service/api" ) +const ( + goTool = "go" // gopdlv: add `goTool` +) + func TestDebugger_LaunchNoMain(t *testing.T) { fixturesDir := protest.FindFixturesDir() nomaindir := filepath.Join(fixturesDir, "nomaindir") debugname := "debug" exepath := filepath.Join(nomaindir, debugname) defer os.Remove(exepath) - if err := gobuild.GoBuild(debugname, []string{nomaindir}, fmt.Sprintf("-o %s", exepath)); err != nil { + if err := gobuild.GoBuild(goTool, debugname, []string{nomaindir}, fmt.Sprintf("-o %s", exepath)); err != nil { t.Fatalf("go build error %v", err) } @@ -51,7 +55,7 @@ func TestDebugger_LaunchInvalidFormat(t *testing.T) { } t.Setenv("GOOS", switchOS[runtime.GOOS]) exepath := filepath.Join(buildtestdir, debugname) - if err := gobuild.GoBuild(debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil { + if err := gobuild.GoBuild(goTool, debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil { t.Fatalf("go build error %v", err) } defer os.Remove(exepath) @@ -81,7 +85,7 @@ func TestDebugger_LaunchCurrentDir(t *testing.T) { t.Fatalf("error removing executable %v", err) } }() - if err := gobuild.GoBuild(debugname, []string{testDir}, fmt.Sprintf("-o %s", exepath)); err != nil { + if err := gobuild.GoBuild(goTool, debugname, []string{testDir}, fmt.Sprintf("-o %s", exepath)); err != nil { t.Fatalf("go build error %v", err) } diff --git a/service/debugger/debugger_unix_test.go b/service/debugger/debugger_unix_test.go index df31e160d8..709143f2ea 100644 --- a/service/debugger/debugger_unix_test.go +++ b/service/debugger/debugger_unix_test.go @@ -37,7 +37,7 @@ func TestDebugger_LaunchNoExecutablePerm(t *testing.T) { t.Setenv("GOOS", switchOS[runtime.GOOS]) exepath := filepath.Join(buildtestdir, debugname) defer os.Remove(exepath) - if err := gobuild.GoBuild(debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil { + if err := gobuild.GoBuild(goTool, debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil { t.Fatalf("go build error %v", err) } if err := os.Chmod(exepath, 0644); err != nil { @@ -74,7 +74,7 @@ func TestDebugger_LaunchWithTTY(t *testing.T) { buildtestdir := filepath.Join(fixturesDir, "buildtest") debugname := "debugtty" exepath := filepath.Join(buildtestdir, debugname) - if err := gobuild.GoBuild(debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil { + if err := gobuild.GoBuild(goTool, debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil { t.Fatalf("go build error %v", err) } defer os.Remove(exepath)