Meta JSON serialization does not preserve VersionSpec
Closed this issue · 3 comments
benlorenz commented
The JSON serialization via --meta-json
that is used during the Yggdrasil build will convert any VersionSpec to just a fixed full VersionNumber x.y.z
, this is done here
BinaryBuilderBase.jl/src/Dependencies.jl
Lines 127 to 149 in 573b396
This happened for example in JuliaPackaging/Yggdrasil#2235 where
Dependency(PackageSpec(name="FLINT_jll", version=VersionSpec("200.690"))),
resulted in
- registry
FLINT_jll = "200.690.0"
- project file
FLINT_jll = "=200.690.0"
cc @fingolfin
fingolfin commented
So I guess to fix it, we need proper JSON serialization for VersionSpec
... the relevant types for that are:
struct VersionBound
t::NTuple{3,UInt32}
n::Int
...
end
struct VersionRange
lower::VersionBound
upper::VersionBound
...
end
struct VersionSpec
ranges::Vector{VersionRange}
...
end
We could use the serialization support in JSON? I don't know whether JSON.jl support deserialization (I couldn't find anything about that), so I hacked something up as a proof of concept
julia> using Pkg, JSON
julia> vs = Pkg.Types.VersionSpec("1.4")
VersionSpec("1.4")
julia> str = JSON.json(vs)
"{\"ranges\":[{\"lower\":{\"t\":[1,4,0],\"n\":2},\"upper\":{\"t\":[1,4,0],\"n\":2}}]}"
julia> d = JSON.parse(str)
Dict{String,Any} with 1 entry:
"ranges" => Any[Dict{String,Any}("lower"=>Dict{String,Any}("t"=>Any[1, 4, 0],"n"=>2),"upper"=>Dict…
julia> Pkg.Types.VersionBound(d::Dict{String,Any}) = Pkg.Types.VersionBound(NTuple{d["n"],Int}(d["t"]))
julia> Pkg.Types.VersionRange(d::Dict{String,Any}) = Pkg.Types.VersionRange(Pkg.Types.VersionBound(d["lower"]), Pkg.Types.VersionBound(d["upper"]))
julia> Pkg.Types.VersionSpec(d::Dict{String,Any}) = Pkg.Types.VersionSpec([Pkg.Types.VersionRange(v) for v in d["ranges"]])
julia> Pkg.Types.VersionSpec(d)
VersionSpec("1.4")
fingolfin commented
Yes