Skip to content

Commit 883e7ef

Browse files
KristofferCKristofferC
authored andcommitted
inline the historical stdlib data, use STDLIBS_BY_VERSION in case we ask for a version later than what we have data for
1 parent 88a46e6 commit 883e7ef

File tree

7 files changed

+1359
-47
lines changed

7 files changed

+1359
-47
lines changed

data/version_map_compressed.jl

Lines changed: 1257 additions & 0 deletions
Large diffs are not rendered by default.

src/HistoricalStdlibs.jl

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,89 @@ struct StdlibInfo
1111
weakdeps::Vector{UUID}
1212
end
1313

14+
# Base info struct for stdlib segments (excludes version)
15+
Base.@kwdef struct StdlibBaseInfo
16+
name::String
17+
uuid::UUID
18+
deps::Vector{UUID} = UUID[]
19+
weakdeps::Vector{UUID} = UUID[]
20+
end
21+
22+
# Segment struct that combines base info with version ranges
23+
Base.@kwdef struct StdlibSegment
24+
base_info::StdlibBaseInfo
25+
version_ranges::Vector{Pair{Tuple{VersionNumber, VersionNumber}, Union{Nothing, VersionNumber}}}
26+
end
27+
1428
const DictStdLibs = Dict{UUID, StdlibInfo}
1529

16-
# Julia standard libraries with duplicate entries removed so as to store only the
17-
# first release in a set of releases that all contain the same set of stdlibs.
18-
#
19-
# This needs to be populated via HistoricalStdlibVersions.jl by consumers
20-
# (e.g. BinaryBuilder) that want to use the "resolve things as if it were a
21-
# different Julia version than what is currently running" feature.
30+
# Load the compressed version map data structure
31+
include(joinpath(@__DIR__, "..", "data", "version_map_compressed.jl"))
32+
33+
# Populated by HistoricalStdlibVersions.jl, used if we have a version later than we know about
2234
const STDLIBS_BY_VERSION = Pair{VersionNumber, DictStdLibs}[]
2335

24-
# This is a list of stdlibs that must _always_ be treated as stdlibs,
25-
# because they cannot be resolved in the registry; they have only ever existed within
26-
# the Julia stdlib source tree, and because of that, trying to resolve them will fail.
27-
const UNREGISTERED_STDLIBS = DictStdLibs()
36+
"""
37+
query_stdlib_segments(julia_version::VersionNumber) -> DictStdLibs
38+
39+
Query the compressed stdlib segments to build a dictionary of stdlib info
40+
for the given Julia version. Returns a Dict{UUID, StdlibInfo} containing
41+
all stdlibs available for that Julia version.
42+
"""
43+
function query_stdlib_segments(julia_version::VersionNumber)
44+
result = DictStdLibs()
45+
46+
# Normalize the julia_version to just major.minor.patch
47+
jv = VersionNumber(julia_version.major, julia_version.minor, julia_version.patch)
48+
49+
# Iterate through all stdlib UUIDs in the segments
50+
for (uuid, segments) in STDLIB_SEGMENTS
51+
# For each stdlib, find the segment and version range that matches
52+
for segment in segments
53+
for (range, pkg_version) in segment.version_ranges
54+
min_v, max_v = range
55+
# Check if julia_version falls within this range
56+
if jv >= min_v && jv <= max_v
57+
# Found the matching range, create StdlibInfo
58+
result[uuid] = StdlibInfo(
59+
segment.base_info.name,
60+
segment.base_info.uuid,
61+
pkg_version,
62+
segment.base_info.deps,
63+
segment.base_info.weakdeps
64+
)
65+
@goto next_stdlib
66+
end
67+
end
68+
end
69+
@label next_stdlib
70+
end
71+
72+
return result
73+
end
74+
75+
"""
76+
version_covered_by_segments(julia_version::VersionNumber) -> Bool
77+
78+
Check if the given Julia version is covered by at least one stdlib in STDLIB_SEGMENTS.
79+
Returns false if the version is outside all recorded ranges, indicating we should
80+
fall back to STDLIBS_BY_VERSION.
81+
"""
82+
function version_covered_by_segments(julia_version::VersionNumber)
83+
# Normalize the julia_version to just major.minor.patch
84+
jv = VersionNumber(julia_version.major, julia_version.minor, julia_version.patch)
85+
86+
# Check if any stdlib has a range that covers this version
87+
for (uuid, segments) in STDLIB_SEGMENTS
88+
for segment in segments
89+
for (range, pkg_version) in segment.version_ranges
90+
min_v, max_v = range
91+
if jv >= min_v && jv <= max_v
92+
return true
93+
end
94+
end
95+
end
96+
end
97+
98+
return false
99+
end

src/Operations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ function fixups_from_projectfile!(ctx::Context)
382382
for pkg in values(env.manifest)
383383
if ctx.julia_version !== VERSION && is_stdlib(pkg.uuid, ctx.julia_version)
384384
# Special handling for non-current julia_version resolving given the source for historical stdlibs
385-
# isn't available at this stage as Pkg thinks it should not be needed, so rely on STDLIBS_BY_VERSION
385+
# isn't available at this stage as Pkg thinks it should not be needed, so query stdlib info on-demand
386386
stdlibs = Types.get_last_stdlibs(ctx.julia_version)
387387
p = stdlibs[pkg.uuid]
388388
pkg.weakdeps = Dict{String, Base.UUID}(stdlibs[uuid].name => uuid for uuid in p.weakdeps)
389-
# pkg.exts = p.exts # TODO: STDLIBS_BY_VERSION doesn't record this
390-
# pkg.entryfile = p.entryfile # TODO: STDLIBS_BY_VERSION doesn't record this
389+
# pkg.exts = p.exts # TODO: stdlib data doesn't record this
390+
# pkg.entryfile = p.entryfile # TODO: stdlib data doesn't record this
391391
for (name, _) in pkg.weakdeps
392392
if !(name in p.deps)
393393
delete!(pkg.deps, name)

src/Types.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -566,20 +566,26 @@ function is_or_was_stdlib(uuid::UUID, julia_version::Union{VersionNumber, Nothin
566566
end
567567

568568

569-
function historical_stdlibs_check()
570-
return if isempty(STDLIBS_BY_VERSION)
571-
pkgerror("If you want to set `julia_version`, you must first populate the `STDLIBS_BY_VERSION` global constant. Try `using HistoricalStdlibVersions`")
572-
end
573-
end
574-
575-
# Find the entry in `STDLIBS_BY_VERSION`
576-
# that corresponds to the requested version, and use that.
577-
# If we can't find one, defaults to `UNREGISTERED_STDLIBS`
569+
# Query stdlib info for a specific Julia version.
570+
# Uses the compressed STDLIB_SEGMENTS data structure if available,
571+
# otherwise falls back to STDLIBS_BY_VERSION for backwards compatibility.
578572
function get_last_stdlibs(julia_version::VersionNumber; use_historical_for_current_version = false)
579573
if !use_historical_for_current_version && julia_version == VERSION
580574
return stdlib_infos()
581575
end
582-
historical_stdlibs_check()
576+
577+
# Use the new compressed data structure if this version is covered
578+
if version_covered_by_segments(julia_version)
579+
stdlibs = query_stdlib_segments(julia_version)
580+
# Merge with unregistered stdlibs
581+
return merge(UNREGISTERED_STDLIBS, stdlibs)
582+
end
583+
584+
# Fall back to old STDLIBS_BY_VERSION logic for versions outside the covered range
585+
if isempty(STDLIBS_BY_VERSION)
586+
pkgerror("If you want to set `julia_version`, you must first populate the `STDLIBS_BY_VERSION` global constant. Try `using HistoricalStdlibVersions`")
587+
end
588+
583589
last_stdlibs = UNREGISTERED_STDLIBS
584590
last_version = nothing
585591

@@ -604,7 +610,6 @@ end
604610
# stdlibs as normal packages so that we get the latest versions of everything, ignoring
605611
# julia compat. So we set the list of stdlibs to that of only the unregistered stdlibs.
606612
function get_last_stdlibs(::Nothing)
607-
historical_stdlibs_check()
608613
return UNREGISTERED_STDLIBS
609614
end
610615

@@ -634,7 +639,6 @@ function stdlib_version(uuid::UUID, julia_version::Union{VersionNumber, Nothing}
634639
end
635640

636641
function is_unregistered_stdlib(uuid::UUID)
637-
historical_stdlibs_check()
638642
return haskey(UNREGISTERED_STDLIBS, uuid)
639643
end
640644

test/Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
33
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
4-
HistoricalStdlibVersions = "6df8b67a-e8a0-4029-b4b7-ac196fe72102"
54
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
65
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
76
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
@@ -17,4 +16,3 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1716

1817
[compat]
1918
Aqua = "0.8.10"
20-
HistoricalStdlibVersions = "2"

test/historical_stdlib_version.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ using Base.BinaryPlatforms: HostPlatform, Platform, platforms_match
66
using Test
77
using TOML
88

9-
ENV["HISTORICAL_STDLIB_VERSIONS_AUTO_REGISTER"] = "false"
10-
using HistoricalStdlibVersions
11-
129
include("utils.jl")
1310
using .Utils
1411

1512
@testset "is_stdlib() across versions" begin
16-
HistoricalStdlibVersions.register!()
17-
1813
networkoptions_uuid = Base.UUID("ca575930-c2e3-43a9-ace4-1e988b2c1908")
1914
pkg_uuid = Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f")
2015
mbedtls_jll_uuid = Base.UUID("c8ffd9c3-330d-5841-b78e-0817d7145fa1")
@@ -44,17 +39,13 @@ using .Utils
4439
@test is_stdlib(mbedtls_jll_uuid, v"1.11")
4540
@test is_stdlib(mbedtls_jll_uuid, v"1.10")
4641

47-
HistoricalStdlibVersions.unregister!()
4842
# Test that we can probe for stdlibs for the current version with no STDLIBS_BY_VERSION,
4943
# but that we throw a PkgError if we ask for a particular julia version.
5044
@test is_stdlib(networkoptions_uuid)
51-
@test_throws Pkg.Types.PkgError is_stdlib(networkoptions_uuid, v"1.6")
5245
end
5346

5447

5548
@testset "Pkg.add() with julia_version" begin
56-
HistoricalStdlibVersions.register!()
57-
5849
# A package with artifacts that went from normal package -> stdlib
5950
gmp_jll_uuid = "781609d7-10c4-51f6-84f2-b8444358ff6d"
6051
# A package that has always only ever been an stdlib
@@ -153,12 +144,9 @@ end
153144
p7zip_jll_uuid = Base.UUID("3f19e933-33d8-53b3-aaab-bd5110c3b7a0")
154145
@test !("Pkg" in keys(Pkg.dependencies()[p7zip_jll_uuid].dependencies))
155146
end
156-
157-
HistoricalStdlibVersions.unregister!()
158147
end
159148

160149
@testset "Resolving for another version of Julia" begin
161-
HistoricalStdlibVersions.register!()
162150
temp_pkg_dir() do dir
163151
function find_by_name(versions, name)
164152
idx = findfirst(p -> p.name == name, versions)
@@ -207,7 +195,6 @@ end
207195
@test mpfr !== nothing
208196
@test mpfr.version.major == 4 && mpfr.version.minor == 0
209197
end
210-
HistoricalStdlibVersions.unregister!()
211198
end
212199

213200
HelloWorldC_jll_UUID = Base.UUID("dca1746e-5efc-54fc-8249-22745bc95a49")
@@ -218,7 +205,6 @@ libblastrampoline_jll_UUID = Base.UUID("8e850b90-86db-534c-a0d3-1478176c7d93")
218205

219206
isolate(loaded_depot = true) do
220207
@testset "Elliot and Mosè's mini Pkg test suite" begin # https://github.com/JuliaPackaging/JLLPrefixes.jl/issues/6
221-
HistoricalStdlibVersions.register!()
222208
@testset "Standard add" begin
223209
Pkg.activate(temp = true)
224210
# Standard add (non-stdlib, flexible version)
@@ -350,7 +336,6 @@ isolate(loaded_depot = true) do
350336
end
351337
end
352338
end
353-
HistoricalStdlibVersions.unregister!()
354339
end
355340
end
356341

test/runtests.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ module PkgTestsInner
6767
"stdlib_compat.jl",
6868
]
6969

70-
# Only test these if the test deps are available (they aren't typically via `Base.runtests`)
71-
HSV_pkgid = Base.PkgId(Base.UUID("6df8b67a-e8a0-4029-b4b7-ac196fe72102"), "HistoricalStdlibVersions")
72-
if Base.locate_package(HSV_pkgid) !== nothing
73-
push!(test_files, "historical_stdlib_version.jl")
74-
end
70+
push!(test_files, "historical_stdlib_version.jl")
7571
Aqua_pkgid = Base.PkgId(Base.UUID("4c88cf16-eb10-579e-8560-4a9242c79595"), "Aqua")
7672
if Base.locate_package(Aqua_pkgid) !== nothing
7773
push!(test_files, "aqua.jl")

0 commit comments

Comments
 (0)