Skip to content

Commit 8bd5da3

Browse files
committed
improve stdlib path rewriting
1 parent 75474fa commit 8bd5da3

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

base/methodshow.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ end
118118
default_methodloc(method::Method) = method.file, method.line
119119
const methodloc_callback = Ref{Function}(default_methodloc)
120120

121+
# This function does the method location updating
122+
function updated_methodloc(m)
123+
file, line = invokelatest(methodloc_callback[], m)
124+
if file !== nothing && isdefined(@__MODULE__, :Sys)
125+
# BUILD_STDLIB_PATH gets defined in sysinfo.jl
126+
file = replace(String(file), Sys.BUILD_STDLIB_PATH => Sys.STDLIB)
127+
end
128+
return Symbol(file), line
129+
end
130+
121131
functionloc(m::Core.MethodInstance) = functionloc(m.def)
122132

123133
"""
@@ -126,7 +136,7 @@ functionloc(m::Core.MethodInstance) = functionloc(m.def)
126136
Returns a tuple `(filename,line)` giving the location of a `Method` definition.
127137
"""
128138
function functionloc(m::Method)
129-
file, ln = invokelatest(methodloc_callback[], m)
139+
file, ln = updated_methodloc(m)
130140
if ln <= 0
131141
error("could not determine location of method definition")
132142
end
@@ -194,7 +204,7 @@ function show(io::IO, m::Method; kwtype::Union{DataType, Nothing}=nothing)
194204
print(io, " in ", m.module)
195205
if line > 0
196206
try
197-
file, line = invokelatest(methodloc_callback[], m)
207+
file, line = updated_methodloc(m)
198208
catch
199209
end
200210
print(io, " at ", file, ":", line)
@@ -248,7 +258,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
248258
show(io, meth; kwtype=kwtype)
249259
file, line = meth.file, meth.line
250260
try
251-
file, line = invokelatest(methodloc_callback[], meth)
261+
file, line = updated_methodloc(m)
252262
catch
253263
end
254264
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
363373
print(io, " in ", m.module)
364374
if line > 0
365375
try
366-
file, line = invokelatest(methodloc_callback[], m)
376+
file, line = updated_methodloc(m)
367377
catch
368378
end
369379
u = url(m)
@@ -402,7 +412,7 @@ function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
402412
show(io, m)
403413
file, line = m.file, m.line
404414
try
405-
file, line = invokelatest(methodloc_callback[], m)
415+
file, line = updated_methodloc(m)
406416
catch
407417
end
408418
push!(LAST_SHOWN_LINE_INFOS, (string(file), line))

base/sysinfo.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ A string containing the full path to the directory containing the `julia` execut
4949
A string containing the full path to the directory containing the `stdlib` packages.
5050
"""
5151
STDLIB = "$BINDIR/../share/julia/stdlib/v$(VERSION.major).$(VERSION.minor)" # for bootstrap
52+
# In case STDLIB change after julia is built, the variable below can be used
53+
# to update cached method locations to updated ones.
54+
const BUILD_STDLIB_PATH = abspath(STDLIB)
5255

5356
# helper to avoid triggering precompile warnings
5457

stdlib/InteractiveUtils/src/editless.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,6 @@ function edit(path::AbstractString, line::Integer=0)
8484
nothing
8585
end
8686

87-
# Workaround for https://github.com/JuliaLang/julia/issues/26314
88-
const BUILDBOT_STDLIB_PATH = dirname(abspath(joinpath(functionloc(eval)[1]), "..", "..", ".."))
89-
function functionloc_stdlib_workaround(args...)
90-
loc, line = functionloc(args...)
91-
if loc !== nothing
92-
loc = replace(loc, BUILDBOT_STDLIB_PATH => Sys.STDLIB)
93-
end
94-
return loc, line
95-
end
96-
9787
"""
9888
edit(function, [types])
9989
edit(module)
@@ -108,8 +98,8 @@ method to edit. For modules, open the main source file. The module needs to be l
10898
The editor can be changed by setting `JULIA_EDITOR`, `VISUAL` or `EDITOR` as an environment
10999
variable.
110100
"""
111-
edit(f) = edit(functionloc_stdlib_workaround(f)...)
112-
edit(f, @nospecialize t) = edit(functionloc_stdlib_workaround(f,t)...)
101+
edit(f) = edit(functionloc(f)...)
102+
edit(f, @nospecialize t) = edit(functionloc(f,t)...)
113103
edit(file, line::Integer) = error("could not find source file for function")
114104
edit(m::Module) = edit(pathof(m))
115105

@@ -144,6 +134,6 @@ less(file::AbstractString) = less(file, 1)
144134
Show the definition of a function using the default pager, optionally specifying a tuple of
145135
types to indicate which method to see.
146136
"""
147-
less(f) = less(functionloc_stdlib_workaround(f)...)
148-
less(f, @nospecialize t) = less(functionloc_stdlib_workaround(f,t)...)
137+
less(f) = less(functionloc(f)...)
138+
less(f, @nospecialize t) = less(functionloc(f,t)...)
149139
less(file, line::Integer) = error("could not find source file for function")

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,7 @@ if Sys.iswindows() || Sys.isapple()
389389
@test clipboard() == str
390390
end
391391
end
392+
393+
# buildbot path updating
394+
file, ln = functionloc(versioninfo, Tuple{})
395+
@test isfile(file)

0 commit comments

Comments
 (0)