Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Tim Holy <tim.holy@gmail.com>"]
version = "0.3.1"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[extras]
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ julia> signatures_at("/home/tim/.julia/packages/ColorTypes/BsAWO/src/traits.jl",
Tuple{typeof(red),AbstractRGB}
```

CodeTracking also helps correcting for [Julia issue #26314](https://github.com/JuliaLang/julia/issues/26314):

```
julia> @which uuid1()
uuid1() in UUIDs at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\UUIDs\src\UUIDs.jl:50

julia> CodeTracking.whereis(@which uuid1())
("C:\\Users\\SomeOne\\AppData\\Local\\Julia-1.1.0\\share\\julia\\stdlib\\v1.1\\UUIDs\\src\\UUIDs.jl", 50)
```

## A few details

CodeTracking won't do anything *useful* unless the user is also running Revise,
Expand Down
3 changes: 2 additions & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module CodeTracking
using Base: PkgId
using Core: LineInfoNode
using UUIDs
using InteractiveUtils

export whereis, definition, pkgfiles, signatures_at

Expand Down Expand Up @@ -41,7 +42,7 @@ function whereis(method::Method)
end
end
if lin === nothing
file, line = String(method.file), method.line
file, line = maybe_fixup_stdlib_path(String(method.file)), method.line
else
file, line = fileline(lin[1])
end
Expand Down
20 changes: 20 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ function basepath(id::PkgId)
loc === nothing && return ""
return dirname(dirname(loc))
end

const BUILDBOT_STDLIB_PATH = dirname(abspath(joinpath(String((@which uuid1()).file), "..", "..", "..")))
replace_buildbot_stdlibpath(str::String) = replace(str, BUILDBOT_STDLIB_PATH => Sys.STDLIB)
"""
path = maybe_fixup_stdlib_path(path::String)

Return `path` corrected for julia issue [#26314](https://github.com/JuliaLang/julia/issues/26314) if applicable.
Otherwise, return the input `path` unchanged.

Due to the issue mentioned above, location info for methods defined one of Julia's standard libraries
are, for non source Julia builds, given as absolute paths on the worker that built the `julia` executable.
This function corrects such a path to instead refer to the local path on the users drive.
"""
function maybe_fixup_stdlib_path(path)
if !isfile(path)
maybe_stdlib_path = replace_buildbot_stdlibpath(path)
isfile(maybe_stdlib_path) && return maybe_stdlib_path
end
return path
end
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ include("script.jl")
eval(ex)
m = first(methods(replfunc))
@test whereis(m) == ("REPL[1]", 1)

# Test with broken lookup
CodeTracking.method_lookup_callback[] = m -> error("oops")
@test whereis(m) == ("REPL[1]", 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code from the merge below needs to be moved above my addition?


m = first(methods(Test.eval))
@test occursin(Sys.STDLIB, whereis(m)[1])
end