From eb05d9402eec5b5658a57fdd23aabf899785d2dc Mon Sep 17 00:00:00 2001 From: Carlo Baldassi Date: Mon, 18 Dec 2017 11:44:07 +0100 Subject: [PATCH] Fix Pkg2-style REQUIRE parsing into Pkg3 types --- src/Operations.jl | 7 +------ src/Pkg2/types.jl | 22 ++++++++++++++++++++++ src/Types.jl | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index 83d6885a6a..4ab15fd5a8 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -208,12 +208,7 @@ function collect_fixed!(env, pkgs, uuids) fix_deps_map[pkg.uuid] = valtype(fix_deps_map)() !isfile(reqfile) && continue for r in filter!(r->r isa Pkg2.Reqs.Requirement, Pkg2.Reqs.read(reqfile)) - # TODO: get all intervals - pkg_name, version = r.package, r.versions.intervals[1] - # Convert to Pkg3 data types - # TODO: the upper bound here is incorrect - vspec = VersionSpec([VersionRange(VersionBound(version.lower), - VersionBound(version.upper))]) + pkg_name, vspec = r.package, VersionSpec(VersionRange[r.versions.intervals...]) deppkg = PackageSpec(pkg_name, vspec) push!(fix_deps_map[pkg.uuid], deppkg) push!(fix_deps, deppkg) diff --git a/src/Pkg2/types.jl b/src/Pkg2/types.jl index 77bb057349..05ce5731db 100644 --- a/src/Pkg2/types.jl +++ b/src/Pkg2/types.jl @@ -6,6 +6,7 @@ export VersionInterval, VersionSet import Base: show, isempty, in, intersect, union!, union, ==, hash, copy, deepcopy_internal import ...Pkg3.iswindows +import ...Pkg3.Types: VersionBound, VersionRange struct VersionInterval lower::VersionNumber @@ -21,6 +22,27 @@ intersect(a::VersionInterval, b::VersionInterval) = VersionInterval(max(a.lower, ==(a::VersionInterval, b::VersionInterval) = a.lower == b.lower && a.upper == b.upper hash(i::VersionInterval, h::UInt) = hash((i.lower, i.upper), h + (0x0f870a92db508386 % UInt)) +# Used to translate from Pkg2 intervals to Pkg3 ranges +function Base.convert(::Type{VersionRange}, a::VersionInterval) + lower, upper = a.lower, a.upper + + lb = VersionBound(lower.major, lower.minor, lower.patch) + + vb = Int[upper.major, upper.minor, upper.patch] + i = 3 + while i > 0 && vb[i] == 0 + pop!(vb) + i -= 1 + end + # NOTE: an upper bound of 0 could happen in principle, e.g. [v"0.0.0-", v"0.0.0") + # but we just ignore this here... + i > 0 || error("invalid interval upper bound v$upper") + vb[i] -= 1 + ub = VersionBound(vb...) + + return VersionRange(lb, ub) +end + function normalize!(ivals::Vector{VersionInterval}) # VersionSet internal normalization: # removes empty intervals and fuses intervals without gaps diff --git a/src/Types.jl b/src/Types.jl index d96174d3c2..b344bdef26 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -8,7 +8,7 @@ import ..Pkg3 using ..Pkg3: TOML, TerminalMenus, Dates import ..Pkg3: depots, logdir, iswindows -export UUID, pkgID, SHA1, VersionBound, VersionRange, VersionSpec, empty_versionspec, +export UUID, pkgID, SHA1, VersionRange, VersionSpec, empty_versionspec, Requires, Fixed, merge_requires!, satisfies, PkgError, PackageSpec, UpgradeLevel, EnvCache, CommandError, cmderror, has_name, has_uuid, has_path, has_url, has_version, write_env, parse_toml, find_registered!,