From fd1820e7af1078216c315f718fad3ad9a17aa3c1 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Tue, 6 Apr 2021 14:40:35 +0200 Subject: [PATCH] fix STDLIBS_BY_VERSION on non-latest version of Julia --- src/Types.jl | 24 ++++++++++++++---------- test/new.jl | 9 +++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Types.jl b/src/Types.jl index cf7d70dc22..67f7cc92e9 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -370,6 +370,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 @@ -388,16 +401,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) diff --git a/test/new.jl b/test/new.jl index 4a1a0e2d2b..34103d68ac 100644 --- a/test/new.jl +++ b/test/new.jl @@ -2603,12 +2603,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