From eb92735b6cbfb90033815cfaa9770a4c8cab37bb Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 25 Jul 2020 03:43:36 +0900 Subject: [PATCH] fix paths of symbols in stdlibs --- Project.toml | 13 +++++++------ src/symbols.jl | 47 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index 37e5ace8..06175fd8 100644 --- a/Project.toml +++ b/Project.toml @@ -3,20 +3,21 @@ uuid = "cf896787-08d5-524d-9de7-132aaa0cb996" version = "5.1.1-DEV" [deps] -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" +Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" -Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] julia = "1" +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + [targets] test = ["Test"] diff --git a/src/symbols.jl b/src/symbols.jl index ded3cb3b..02237887 100644 --- a/src/symbols.jl +++ b/src/symbols.jl @@ -1,4 +1,4 @@ -using LibGit2 +using LibGit2, InteractiveUtils mutable struct Server storedir::String @@ -95,16 +95,43 @@ struct GenericStore <: SymStore exported::Bool end +# adapted from https://github.com/timholy/CodeTracking.jl/blob/afc73a957f5034cc7f02e084a91283c47882f92b/src/utils.jl#L87-L122 -function clean_method_path(m::Method) - path = String(m.file) - if !isabspath(path) - path = Base.find_source_file(path) - if path === nothing - path = "" +""" + path = maybe_fix_path(path) + +Return a normalized, absolute path for a source file `path`. +""" +function maybe_fix_path(file) + if !isabspath(file) + # This may be a Base or Core method + newfile = Base.find_source_file(file) + if isa(newfile, AbstractString) + file = normpath(newfile) end end - return normpath(path) + return maybe_fixup_stdlib_path(file) +end + +safe_isfile(x) = try isfile(x); catch; false end +const BUILDBOT_STDLIB_PATH = dirname(abspath(joinpath(String((@which versioninfo()).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 !safe_isfile(path) + maybe_stdlib_path = replace_buildbot_stdlibpath(path) + safe_isfile(maybe_stdlib_path) && return maybe_stdlib_path + end + return path end const _global_method_cache = IdDict{Any,Vector{Any}}() @@ -138,7 +165,8 @@ function cache_methods(@nospecialize(f), name, env) ind_of_method_w_kws = Int[] # stores the index of methods with kws. i = 1 for m in methods0 - MS = MethodStore(m[3].name, nameof(m[3].module), clean_method_path(m[3]), m[3].line, [], Symbol[], FakeTypeName(Any)) + file = maybe_fix_path(String(m[3].file)) + MS = MethodStore(m[3].name, nameof(m[3].module), file, m[3].line, [], Symbol[], FakeTypeName(Any)) # Get signature sig = Base.unwrap_unionall(m[1]) argnames = getargnames(m[3]) @@ -551,4 +579,3 @@ end get_all_modules() = let allms = Base.IdSet{Module}(); apply_to_everything(x->if x isa Module push!(allms, x) end); allms end get_used_modules(M, allms = get_all_modules()) = [m for m in allms if usedby(M, m)] -