未验证 提交 579b17ce 编写于 作者: A Aaron Sky 提交者: GitHub

proc/gdbserial: Use the active xcode-select path instead of a hardcoded Xcode path (#2229)

* Use the active xcode-select path instead of a hardcoded Xcode path

* Refactored exec.Command to invoke Output instead of running with a custom buffer for stdout

Addresses review comment by @derekparker
上级 db930498
......@@ -70,6 +70,7 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
......@@ -93,10 +94,32 @@ const (
const heartbeatInterval = 10 * time.Second
// Relative to $(xcode-select --print-path)/../
// xcode-select typically returns the path to the Developer directory, which is a sibling to SharedFrameworks.
var debugserverXcodeRelativeExecutablePath = "SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver"
var debugserverExecutablePaths = []string{
"debugserver",
"/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver",
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver",
// Function returns the active developer directory provided by xcode-select to compute a debugserver path.
func() string {
if _, err := exec.LookPath("xcode-select"); err != nil {
return ""
}
stdout, err := exec.Command("xcode-select", "--print-path").Output()
if err != nil {
return ""
}
xcodePath := strings.TrimSpace(string(stdout))
if xcodePath == "" {
return ""
}
// xcode-select prints the path to the active Developer directory, which is typically a sibling to SharedFrameworks.
return filepath.Join(xcodePath, "..", debugserverXcodeRelativeExecutablePath)
}(),
}
// ErrDirChange is returned when trying to change execution direction
......@@ -308,6 +331,9 @@ func unusedPort() string {
// found in the system path ($PATH), the Xcode bundle or the standalone CLT location.
func getDebugServerAbsolutePath() string {
for _, debugServerPath := range debugserverExecutablePaths {
if debugServerPath == "" {
continue
}
if _, err := exec.LookPath(debugServerPath); err == nil {
return debugServerPath
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册