mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 23:17:27 +01:00
internal/debug: use go/build's Context to get the source directory
This commit is contained in:
parent
0ce1f2292e
commit
aae3e739f8
@ -15,11 +15,7 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"go/build"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -43,22 +39,13 @@ const (
|
|||||||
// FirstCaller returns the file and line number of the first caller outside of Ebitengine.
|
// FirstCaller returns the file and line number of the first caller outside of Ebitengine.
|
||||||
func FirstCaller() (file string, line int, callerType CallerType) {
|
func FirstCaller() (file string, line int, callerType CallerType) {
|
||||||
ebitengineFileDirOnce.Do(func() {
|
ebitengineFileDirOnce.Do(func() {
|
||||||
var stderr bytes.Buffer
|
pkg, err := build.Default.Import("github.com/hajimehoshi/ebiten/v2", "", build.FindOnly)
|
||||||
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2")
|
|
||||||
cmd.Stderr = &stderr
|
|
||||||
out, err := cmd.Output()
|
|
||||||
if errors.Is(err, exec.ErrNotFound) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "debug: go list -f {{.Dir}} failed: %v\n", err)
|
|
||||||
fmt.Fprintf(os.Stderr, "%s\n", stderr.String())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ebitengineFileDir = filepath.ToSlash(strings.TrimSpace(string(out)))
|
ebitengineFileDir = filepath.ToSlash(pkg.Dir)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Go command is not found.
|
|
||||||
if ebitengineFileDir == "" {
|
if ebitengineFileDir == "" {
|
||||||
return "", 0, CallerTypeNone
|
return "", 0, CallerTypeNone
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user