Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback for stale cachefiles #385

Merged
merged 1 commit into from
Nov 9, 2019
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
33 changes: 24 additions & 9 deletions src/pkgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,32 @@ function pkg_fileinfo(id::PkgId)
# Try to find the matching cache file
paths = Base.find_all_in_cache_path(id)
sourcepath = Base.locate_package(id)
for path in paths
Base.stale_cachefile(sourcepath, path) === true && continue
provides, includes_requires = parse_cache_header(path)
mods_files_mtimes, _ = includes_requires
for (pkgid, buildid) in provides
if pkgid.uuid === uuid && pkgid.name == name
return path, mods_files_mtimes
end
if length(paths) > 1
fpaths = filter(path->Base.stale_cachefile(sourcepath, path) !== true, paths)
if isempty(fpaths)
# Work-around for #371 (broken dependency prevents tracking):
# find the most recent cache file. Presumably this is the one built
# to load the package.
sort!(paths; by=path->mtime(path), rev=true)
deleteat!(paths, 2:length(paths))
else
paths = fpaths
end
end
isempty(paths) && return nothing, nothing
@assert length(paths) == 1
path = first(paths)
provides, includes_requires = try
parse_cache_header(path)
catch
return nothing, nothing
end
mods_files_mtimes, _ = includes_requires
for (pkgid, buildid) in provides
if pkgid.uuid === uuid && pkgid.name == name
return path, mods_files_mtimes
end
end
return nothing, nothing
end

"""
Expand Down
35 changes: 35 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,41 @@ end
push!(to_remove, depot)
end

@testset "Broken dependencies (issue #371)" begin
testdir = newtestdir()
srcdir = joinpath(testdir, "DepPkg371", "src")
filepath = joinpath(srcdir, "DepPkg371.jl")
cd(testdir) do
Pkg.generate("DepPkg371")
open(filepath, "w") do io
println(io, """
module DepPkg371
using OrderedCollections # undeclared dependency
greet() = "Hello world!"
end
""")
end
end
sleep(mtimedelay)
@info "A warning about not having OrderedCollection in dependencies is expected"
@eval using DepPkg371
@test DepPkg371.greet() == "Hello world!"
sleep(mtimedelay)
open(filepath, "w") do io
println(io, """
module DepPkg371
using OrderedCollections # undeclared dependency
greet() = "Hello again!"
end
""")
end
yry()
@test DepPkg371.greet() == "Hello again!"

rm_precompile("DepPkg371")
pop!(LOAD_PATH)
end

@testset "entr" begin
if !Sys.isapple() # these tests are very flaky on OSX
srcfile = joinpath(tempdir(), randtmp()*".jl")
Expand Down