Skip to content

Commit

Permalink
improve stdlib path rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Oct 16, 2019
1 parent ab65312 commit 4c98ae0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
20 changes: 15 additions & 5 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ end
default_methodloc(method::Method) = method.file, method.line
const methodloc_callback = Ref{Function}(default_methodloc)

# This function does the method location updating
function updated_methodloc(m)
file, line = invokelatest(methodloc_callback[], m)
if file !== nothing && isdefined(@__MODULE__, :Sys)
# BUILD_STDLIB_PATH gets defined in sysinfo.jl
file = replace(String(file), normpath(Sys.BUILD_STDLIB_PATH) => normpath(Sys.STDLIB))
end
return Symbol(file), line
end

functionloc(m::Core.MethodInstance) = functionloc(m.def)

"""
Expand All @@ -130,7 +140,7 @@ functionloc(m::Core.MethodInstance) = functionloc(m.def)
Returns a tuple `(filename,line)` giving the location of a `Method` definition.
"""
function functionloc(m::Method)
file, ln = invokelatest(methodloc_callback[], m)
file, ln = updated_methodloc(m)
if ln <= 0
error("could not determine location of method definition")
end
Expand Down Expand Up @@ -196,7 +206,7 @@ function show(io::IO, m::Method)
print(io, " in ", m.module)
if line > 0
try
file, line = invokelatest(methodloc_callback[], m)
file, line = updated_methodloc(m)
catch
end
print(io, " at ", file, ":", line)
Expand Down Expand Up @@ -249,7 +259,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
show(io, meth)
file, line = meth.file, meth.line
try
file, line = invokelatest(methodloc_callback[], meth)
file, line = updated_methodloc(m)
catch
end
push!(LAST_SHOWN_LINE_INFOS, (string(file), line))
Expand Down Expand Up @@ -362,7 +372,7 @@ function show(io::IO, ::MIME"text/html", m::Method)
print(io, " in ", m.module)
if line > 0
try
file, line = invokelatest(methodloc_callback[], m)
file, line = updated_methodloc(m)
catch
end
u = url(m)
Expand Down Expand Up @@ -400,7 +410,7 @@ function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
show(io, m)
file, line = m.file, m.line
try
file, line = invokelatest(methodloc_callback[], m)
file, line = updated_methodloc(m)
catch
end
push!(LAST_SHOWN_LINE_INFOS, (string(file), line))
Expand Down
3 changes: 3 additions & 0 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ A string containing the full path to the directory containing the `julia` execut
A string containing the full path to the directory containing the `stdlib` packages.
"""
STDLIB = "$BINDIR/../share/julia/stdlib/v$(VERSION.major).$(VERSION.minor)" # for bootstrap
# In case STDLIB change after julia is built, the variable below can be used
# to update cached method locations to updated ones.
const BUILD_STDLIB_PATH = STDLIB

# helper to avoid triggering precompile warnings

Expand Down
18 changes: 4 additions & 14 deletions stdlib/InteractiveUtils/src/editless.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ function edit(path::AbstractString, line::Integer=0)
nothing
end

# Workaround for https://github.com/JuliaLang/julia/issues/26314
const BUILDBOT_STDLIB_PATH = dirname(abspath(joinpath(functionloc(eval)[1]), "..", "..", ".."))
function functionloc_stdlib_workaround(args...)
loc, line = functionloc(args...)
if loc !== nothing
loc = replace(loc, BUILDBOT_STDLIB_PATH => Sys.STDLIB)
end
return loc, line
end

"""
edit(function, [types])
edit(module)
Expand All @@ -108,8 +98,8 @@ method to edit. For modules, open the main source file. The module needs to be l
The editor can be changed by setting `JULIA_EDITOR`, `VISUAL` or `EDITOR` as an environment
variable.
"""
edit(f) = edit(functionloc_stdlib_workaround(f)...)
edit(f, @nospecialize t) = edit(functionloc_stdlib_workaround(f,t)...)
edit(f) = edit(functionloc(f)...)
edit(f, @nospecialize t) = edit(functionloc(f,t)...)
edit(file, line::Integer) = error("could not find source file for function")
edit(m::Module) = edit(pathof(m))

Expand Down Expand Up @@ -144,6 +134,6 @@ less(file::AbstractString) = less(file, 1)
Show the definition of a function using the default pager, optionally specifying a tuple of
types to indicate which method to see.
"""
less(f) = less(functionloc_stdlib_workaround(f)...)
less(f, @nospecialize t) = less(functionloc_stdlib_workaround(f,t)...)
less(f) = less(functionloc(f)...)
less(f, @nospecialize t) = less(functionloc(f,t)...)
less(file, line::Integer) = error("could not find source file for function")
4 changes: 4 additions & 0 deletions stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ if Sys.iswindows() || Sys.isapple()
@test clipboard() == str
end
end

# buildbot path updating
file, ln = functionloc(versioninfo, Tuple{})
@test isfile(file)

0 comments on commit 4c98ae0

Please sign in to comment.