Skip to content

Commit

Permalink
fix STDLIBS_BY_VERSION on non-latest version of Julia
Browse files Browse the repository at this point in the history
(cherry picked from commit fd1820e)
  • Loading branch information
KristofferC committed Apr 6, 2021
1 parent f0fb19d commit ed19f82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
24 changes: 14 additions & 10 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ function stdlibs()
end
is_stdlib(uuid::UUID) = uuid in keys(stdlibs())

# Find the entry in `STDLIBS_BY_VERSION`
# that corresponds to the requested version, and use that.
function get_last_stdlibs(julia_version::VersionNumber)
last_stdlibs = Dict{UUID,String}()
for (version, stdlibs) in STDLIBS_BY_VERSION
if VersionNumber(julia_version.major, julia_version.minor, julia_version.patch) < version
break
end
last_stdlibs = stdlibs
end
return last_stdlibs
end

# Allow asking if something is an stdlib for a particular version of Julia
function is_stdlib(uuid::UUID, julia_version::Union{VersionNumber, Nothing})
# Only use the cache if we are asking for stdlibs in a custom Julia version
Expand All @@ -381,16 +394,7 @@ function is_stdlib(uuid::UUID, julia_version::Union{VersionNumber, Nothing})
return false
end

# If we are given an actual version, find the entry in `STDLIBS_BY_VERSION`
# that corresponds to the requested version, and use that.
last_stdlibs = Dict{UUID,String}()
for (version, stdlibs) in STDLIBS_BY_VERSION
if VersionNumber(julia_version.major, julia_version.minor, julia_version.patch) < version
break
end
last_stdlibs = stdlibs
end

last_stdlibs = get_last_stdlibs(julia_version)
# Note that if the user asks for something like `julia_version = 0.7.0`, we'll
# fall through with an empty `last_stdlibs`, which will always return `false`.
return uuid in keys(last_stdlibs)
Expand Down
9 changes: 5 additions & 4 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2519,12 +2519,13 @@ using Pkg.Types: is_stdlib
end

@testset "STDLIBS_BY_VERSION up-to-date" begin
test_result = Pkg.Types.STDLIBS_BY_VERSION[end][2] == Pkg.Types.load_stdlib()
last_stdlibs = Pkg.Types.get_last_stdlibs(VERSION)
test_result = last_stdlibs == Pkg.Types.load_stdlib()
if !test_result
@error("STDLIBS_BY_VERSION out of date! Manually fix given the info below, or re-run generate_historical_stdlibs.jl!")
@show length(Pkg.Types.STDLIBS_BY_VERSION[end][2]) length(Pkg.Types.load_stdlib())
@show setdiff(Pkg.Types.STDLIBS_BY_VERSION[end][2], Pkg.Types.load_stdlib())
@show setdiff(Pkg.Types.load_stdlib(), Pkg.Types.STDLIBS_BY_VERSION[end][2])
@show length(last_stdlibs) length(Pkg.Types.load_stdlib())
@show setdiff(last_stdlibs, Pkg.Types.load_stdlib())
@show setdiff(Pkg.Types.load_stdlib(), last_stdlibs)
end
@test test_result
end
Expand Down

0 comments on commit ed19f82

Please sign in to comment.