Skip to content

Commit f3963c3

Browse files
KristofferCtimholy
authored andcommitted
add functionality for working around Julia issue #26314: wrong path for stdlib methods (#16)
1 parent 8002646 commit f3963c3

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ authors = ["Tim Holy <[email protected]>"]
44
version = "0.3.1"
55

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

910
[extras]

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ julia> signatures_at("/home/tim/.julia/packages/ColorTypes/BsAWO/src/traits.jl",
6565
Tuple{typeof(red),AbstractRGB}
6666
```
6767

68+
CodeTracking also helps correcting for [Julia issue #26314](https://github.com/JuliaLang/julia/issues/26314):
69+
70+
```
71+
julia> @which uuid1()
72+
uuid1() in UUIDs at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\UUIDs\src\UUIDs.jl:50
73+
74+
julia> CodeTracking.whereis(@which uuid1())
75+
("C:\\Users\\SomeOne\\AppData\\Local\\Julia-1.1.0\\share\\julia\\stdlib\\v1.1\\UUIDs\\src\\UUIDs.jl", 50)
76+
```
77+
6878
## A few details
6979

7080
CodeTracking won't do anything *useful* unless the user is also running Revise,

src/CodeTracking.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module CodeTracking
33
using Base: PkgId
44
using Core: LineInfoNode
55
using UUIDs
6+
using InteractiveUtils
67

78
export whereis, definition, pkgfiles, signatures_at
89

@@ -41,7 +42,7 @@ function whereis(method::Method)
4142
end
4243
end
4344
if lin === nothing
44-
file, line = String(method.file), method.line
45+
file, line = maybe_fixup_stdlib_path(String(method.file)), method.line
4546
else
4647
file, line = fileline(lin[1])
4748
end

src/utils.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,23 @@ function basepath(id::PkgId)
4545
loc === nothing && return ""
4646
return dirname(dirname(loc))
4747
end
48+
49+
const BUILDBOT_STDLIB_PATH = dirname(abspath(joinpath(String((@which uuid1()).file), "..", "..", "..")))
50+
replace_buildbot_stdlibpath(str::String) = replace(str, BUILDBOT_STDLIB_PATH => Sys.STDLIB)
51+
"""
52+
path = maybe_fixup_stdlib_path(path::String)
53+
54+
Return `path` corrected for julia issue [#26314](https://github.com/JuliaLang/julia/issues/26314) if applicable.
55+
Otherwise, return the input `path` unchanged.
56+
57+
Due to the issue mentioned above, location info for methods defined one of Julia's standard libraries
58+
are, for non source Julia builds, given as absolute paths on the worker that built the `julia` executable.
59+
This function corrects such a path to instead refer to the local path on the users drive.
60+
"""
61+
function maybe_fixup_stdlib_path(path)
62+
if !isfile(path)
63+
maybe_stdlib_path = replace_buildbot_stdlibpath(path)
64+
isfile(maybe_stdlib_path) && return maybe_stdlib_path
65+
end
66+
return path
67+
end

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ include("script.jl")
5050
eval(ex)
5151
m = first(methods(replfunc))
5252
@test whereis(m) == ("REPL[1]", 1)
53-
5453
# Test with broken lookup
5554
CodeTracking.method_lookup_callback[] = m -> error("oops")
5655
@test whereis(m) == ("REPL[1]", 1)
56+
57+
m = first(methods(Test.eval))
58+
@test occursin(Sys.STDLIB, whereis(m)[1])
5759
end

0 commit comments

Comments
 (0)