Skip to content

Commit

Permalink
Add fallback for stale cachefiles. Fixes #371. (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Nov 9, 2019
1 parent d7a7c13 commit a8f4660
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
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

0 comments on commit a8f4660

Please sign in to comment.