diff --git a/Project.toml b/Project.toml index 879f80c..d29501b 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Tim Holy "] version = "0.3.1" [deps] +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [extras] diff --git a/README.md b/README.md index 65b7175..77148ca 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index 8b76555..07997b0 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -3,6 +3,7 @@ module CodeTracking using Base: PkgId using Core: LineInfoNode using UUIDs +using InteractiveUtils export whereis, definition, pkgfiles, signatures_at @@ -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 diff --git a/src/utils.jl b/src/utils.jl index 79c5369..1e836ad 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 6c575c3..5828cc9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) + + m = first(methods(Test.eval)) + @test occursin(Sys.STDLIB, whereis(m)[1]) end