-
-
Notifications
You must be signed in to change notification settings - Fork 147
avoid using go/build to trim prefix #139
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,7 @@ package raven | |
|
|
||
| import ( | ||
| "bytes" | ||
| "go/build" | ||
| "io/ioutil" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "sync" | ||
|
|
@@ -199,25 +197,15 @@ func fileContext(filename string, line, context int) ([][]byte, int) { | |
| return lines[start:end], idx | ||
| } | ||
|
|
||
| var trimPaths []string | ||
|
|
||
| // Try to trim the GOROOT or GOPATH prefix off of a filename | ||
| // trimPath tries to trim the GOROOT or GOPATH prefix off of a filename. | ||
| // | ||
| // We don't use `go/build` here as it will look at the _current_ values, | ||
| // so instead we just assume the last `/src/`. | ||
| func trimPath(filename string) string { | ||
| for _, prefix := range trimPaths { | ||
| if trimmed := strings.TrimPrefix(filename, prefix); len(trimmed) < len(filename) { | ||
| return trimmed | ||
| } | ||
| } | ||
| return filename | ||
| } | ||
|
|
||
| func init() { | ||
| // Collect all source directories, and make sure they | ||
| // end in a trailing "separator" | ||
| for _, prefix := range build.Default.SrcDirs() { | ||
| if prefix[len(prefix)-1] != filepath.Separator { | ||
| prefix += string(filepath.Separator) | ||
| } | ||
| trimPaths = append(trimPaths, prefix) | ||
| const src = "/src/" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Welp, what if you're running a binary cross-compiled on Linux for Windows? My point is that I think neither the current behavior nor your proposed alternative is correct. Perhaps we need to look for both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. In fact, we're completely speculating on this behaviour at the moment. We probably need to experiment (or find the code) to find out how source locations are encoded into Go binaries. See golang/go#19784, for instance, which implies some confusion in this area. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that said, even if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. @mattrobenolt? |
||
| prefix := strings.LastIndex(filename, src) | ||
| if prefix == -1 { | ||
| return filename | ||
| } | ||
| return filename[prefix+len(src):] | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is now irrelevant, right? Since we don't look at these values at all.