Skip to content

Commit

Permalink
fix paths of symbols in stdlibs
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jul 24, 2020
1 parent f20db3c commit eb92735
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
13 changes: 7 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
47 changes: 37 additions & 10 deletions src/symbols.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LibGit2
using LibGit2, InteractiveUtils

mutable struct Server
storedir::String
Expand Down Expand Up @@ -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}}()
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)]

0 comments on commit eb92735

Please sign in to comment.