From cac3c533268828669ab029600bc99f19b95e6317 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 15 Mar 2019 10:43:49 +0100 Subject: [PATCH 1/2] add functionality for working around Julia issue #26314 --- Project.toml | 1 + README.md | 10 ++++++++++ src/CodeTracking.jl | 3 ++- src/utils.jl | 20 ++++++++++++++++++++ test/runtests.jl | 3 +++ 5 files changed, 36 insertions(+), 1 deletion(-) 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 a21fc46..9c29a1a 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 @@ -38,7 +39,7 @@ function whereis(method::Method) lin = get(method_info, method.sig, nothing) 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 0badd71..f6ee274 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -50,4 +50,7 @@ include("script.jl") eval(ex) m = first(methods(replfunc)) @test whereis(m) == ("REPL[1]", 1) + + m = first(methods(Test.eval)) + @test occursin(Sys.STDLIB, whereis(m)[1]) end From 0ac1c73697095203af24197144da061ac2d9c13e Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 15 Mar 2019 05:35:44 -0500 Subject: [PATCH 2/2] fix --- test/runtests.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 9dda456..5828cc9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -50,12 +50,10 @@ include("script.jl") eval(ex) m = first(methods(replfunc)) @test whereis(m) == ("REPL[1]", 1) - - - m = first(methods(Test.eval)) - @test occursin(Sys.STDLIB, whereis(m)[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