Skip to content

Commit

Permalink
Fix Pkg2-style REQUIRE parsing into Pkg3 types
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobaldassi authored and KristofferC committed Jan 29, 2018
1 parent 5a30b4e commit eb05d94
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions src/Pkg2/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down

0 comments on commit eb05d94

Please sign in to comment.