From 4784307a7923821ba8c7f2a8941f92e08769830b Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 9 Nov 2019 02:21:19 -0600 Subject: [PATCH] Add fallback for stale cachefiles. Fixes #371. --- src/pkgs.jl | 29 ++++++++++++++++++++--------- test/runtests.jl | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/pkgs.jl b/src/pkgs.jl index 431437ba..5c5d8ebe 100644 --- a/src/pkgs.jl +++ b/src/pkgs.jl @@ -59,17 +59,28 @@ 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 = 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 end - return nothing, nothing end """ diff --git a/test/runtests.jl b/test/runtests.jl index 65a422a2..c7b6d836 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")