diff --git a/base/methodshow.jl b/base/methodshow.jl index 4c919281153fa4..c32d1983354d1e 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -118,6 +118,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) => Sys.STDLIB) + end + return Symbol(file), line +end + functionloc(m::Core.MethodInstance) = functionloc(m.def) """ @@ -126,7 +136,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 @@ -194,7 +204,7 @@ function show(io::IO, m::Method; kwtype::Union{DataType, Nothing}=nothing) 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) @@ -248,7 +258,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru show(io, meth; kwtype=kwtype) 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)) @@ -363,7 +373,7 @@ function show(io::IO, ::MIME"text/html", m::Method; kwtype::Union{DataType, Noth 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) @@ -402,7 +412,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)) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 1cbe3a994bcd81..de71754842eaa9 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -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 diff --git a/stdlib/InteractiveUtils/src/editless.jl b/stdlib/InteractiveUtils/src/editless.jl index eac7576050a793..fc164b7f5ed9a4 100644 --- a/stdlib/InteractiveUtils/src/editless.jl +++ b/stdlib/InteractiveUtils/src/editless.jl @@ -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) @@ -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)) @@ -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") diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 3e522ce24a54ee..afe63cd0d59493 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -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)