Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ function track(mod::Module, file::AbstractString; mode=:sigs, kwargs...)
id = Base.moduleroot(mod) == Main ? PkgId(mod, string(mod)) : PkgId(mod) # see #689 for `Main`
if haskey(pkgdatas, id)
pkgdata = pkgdatas[id]
relfile = relpath(abspath(file), pkgdata)
relfile = relpath(abspath_no_normalize(file), pkgdata)
hasfile(pkgdata, relfile) && return nothing
# Use any "fixes" provided by relpath
file = joinpath(basedir(pkgdata), relfile)
Expand All @@ -939,7 +939,7 @@ function track(mod::Module, file::AbstractString; mode=:sigs, kwargs...)
nameof(mod) === :Plots || Base.depwarn("Revise@2.4 or higher automatically handles `include` statements in `@require` expressions.\nPlease do not call `Revise.track` from such blocks.", :track)
return nothing
end
file = abspath(file)
file = abspath_no_normalize(file)
end
# Set up tracking
mod_exs_sigs = parse_source(file, mod; mode)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ function includet(mod::Module, file::AbstractString)
invokelatest(showerror, stderr, err; blame_revise=false)
println(stderr, "\nin expression starting at ", err.loc)
else
throw(err)
rethrow()
end
end
return nothing
Expand Down
6 changes: 3 additions & 3 deletions src/pkgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function has_writable_paths(pkgdata::PkgData)
end

function watch_includes(mod::Module, fn::AbstractString)
@lock included_files_lock push!(included_files, (mod, normpath(abspath(fn))))
@lock included_files_lock push!(included_files, (mod, abspath_no_normalize(fn)))
end

## Working with Pkg and code-loading
Expand Down Expand Up @@ -423,7 +423,7 @@ function watch_manifest(mfile::String)
for (id, pkgdir) in pkgdirs
if haskey(pkgdatas, id)
pkgdata = pkgdatas[id]
if pkgdir != basedir(pkgdata)
if !samefile(pkgdir, basedir(pkgdata))
## The package directory has changed
@debug "Pkg" _group="pathswitch" oldpath=basedir(pkgdata) newpath=pkgdir
push!(pathreplacements, basedir(pkgdata)=>pkgdir)
Expand All @@ -434,7 +434,7 @@ function watch_manifest(mfile::String)
# Update the paths in the watchlist
for (oldpath, newpath) in pathreplacements
for (_, pkgdata) in pkgdatas
if basedir(pkgdata) == oldpath
if samefile(basedir(pkgdata), oldpath)
switch_basepath(pkgdata, newpath)
end
end
Expand Down
12 changes: 6 additions & 6 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ detected during tracking are applied immediately. Optionally, if `revise_throw`
`true`, `revise()` will throw if any exceptions are encountered while revising.
"""
function track(mod::Module; modified_files=revision_queue, revise_throw::Bool=!isinteractive())
id = Base.moduleroot(mod) == Core.Compiler ?
PkgId(mod, "Core.Compiler") :
PkgId(mod)
id = pkgidid_for_mod(mod)
modname = nameof(mod)
ret = _track(id, modname; modified_files=modified_files)
revise(; throw=revise_throw) # force revision so following calls in the same block work
return ret
end

pkgidid_for_mod(mod) = id = Base.moduleroot(mod) == Core.Compiler ? PkgId(mod, "Core.Compiler") : PkgId(mod)

const vstring = "v$(VERSION.major).$(VERSION.minor)"

function inpath(path::AbstractString, dirs::Vector{String})
Expand Down Expand Up @@ -94,8 +94,8 @@ function _track(id::PkgId, modname::Symbol; modified_files=revision_queue)
# Save the result (unnecessary if already in pkgdatas, but doesn't hurt either)
@lock pkgdatas_lock pkgdatas[id] = pkgdata
elseif modname === :Compiler
compilerdir = normpath(joinpath(juliadir, "Compiler", "src"))
compilerdir_pre_112 = normpath(joinpath(juliadir, "base", "compiler"))
compilerdir = joinpath(juliadir, "Compiler", "src")
compilerdir_pre_112 = joinpath(juliadir, "base", "compiler")
isdir(compilerdir) || (compilerdir = compilerdir_pre_112)
pkgdata = get(pkgdatas, id, nothing)
if pkgdata === nothing
Expand Down Expand Up @@ -140,7 +140,7 @@ function track_subdir_from_git!(pkgdata::PkgData, subdir::AbstractString; commit
if repo == nothing
throw(GitRepoException(subdir))
end
prefix = string(relpath(subdir, repo_path), "/") # git-relative path of this subdir
prefix = string(relpath(realpath(subdir), realpath(repo_path)), "/") # git-relative path of this subdir
tree = git_tree(repo, commit)
files = Iterators.filter(file->startswith(file, prefix) && endswith(file, ".jl"), keys(tree))
ccall((:giterr_clear, :libgit2), Cvoid, ()) # necessary to avoid errors like "the global/xdg file 'attributes' doesn't exist: No such file or directory"
Expand Down
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ PkgData(id::PkgId, path) = PkgData(PkgFiles(id, path), FileInfo[], PkgId[])
PkgData(id::PkgId, ::Nothing) = PkgData(id, "")
function PkgData(id::PkgId)
bp = basepath(id)
if !isempty(bp)
bp = normpath(bp)
if !isempty(bp) && !isabspath(bp)
bp = abspath(bp)
end
PkgData(id, bp)
end
Expand Down
35 changes: 23 additions & 12 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
relpath_safe(path::AbstractString, startpath::AbstractString) = isempty(startpath) ? path : relpath(path, startpath)
function relpath_safe(path::AbstractString, startpath::AbstractString)
isempty(startpath) && return path
if ispath(path)
path = relpath(realpath(path), realpath(startpath))
!isabspath(path) && return path
end
return relpath(path, startpath)
end

function Base.relpath(filename::AbstractString, pkgdata::PkgData)
if isabspath(filename)
# `Base.locate_package`, which is how `pkgdata` gets initialized, might strip pieces of the path.
# For example, on Travis macOS the paths returned by `abspath`
# can be preceded by "/private" which is not present in the value returned by `Base.locate_package`.
idx = findfirst(basedir(pkgdata), filename)
if idx !== nothing
idx = first(idx)
if idx > 1
filename = filename[idx:end]
end
filename = relpath_safe(filename, basedir(pkgdata))
end
filename = relpath_safe(filename, basedir(pkgdata))
elseif startswith(filename, "compiler")
# Core.Compiler's pkgid includes "compiler/" in the path
filename = relpath(filename, "compiler")
Expand All @@ -33,6 +30,20 @@ function unique_dirs(iter)
return udirs
end

function abspath_no_normalize(a)
if !isabspath(a)
cwd = pwd()
a_drive, a_nodrive = splitdrive(a)
if a_drive != "" && lowercase(splitdrive(cwd)[1]) != lowercase(a_drive)
cwd = a_drive * path_separator
a = joinpath(cwd, a_nodrive)
else
a = joinpath(cwd, a)
end
end
return a
end

function file_exists(filename::AbstractString)
filename = normpath(filename)
isfile(filename) && return true
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@ const issue639report = []
# CodeTracking methods
m3 = first(methods(eval(fn3)))
m3file = joinpath(dn, "subdir", "file3.jl")
@test whereis(m3) == (m3file, 1)
w = whereis(m3)
@test samefile(w[1], m3file)
@test w[2] == 1
@test signatures_at(m3file, 1) == [Revise.SigInfo(nothing, m3.sig)]
@test signatures_at(eval(Symbol(modname)), joinpath("src", "subdir", "file3.jl"), 1) == [Revise.SigInfo(nothing, m3.sig)]

Expand Down Expand Up @@ -2990,7 +2992,7 @@ const issue639report = []
if repo != nothing && isfile(joinpath(path, "VERSION")) && isdir(joinpath(path, "base"))
# Tracking Core.Compiler
Revise.track(Core.Compiler)
id = Base.PkgId(Core.Compiler)
id = Revise.pkgidid_for_mod(Core.Compiler)
pkgdata = Revise.pkgdatas[id]
@test any(k->endswith(k, "optimize.jl"), Revise.srcfiles(pkgdata))
m = first(methods(Core.Compiler.typeinf_code))
Expand Down
Loading