Skip to content

Commit

Permalink
refactor pkgs handling
Browse files Browse the repository at this point in the history
  • Loading branch information
00vareladavid committed Feb 18, 2020
1 parent f75e641 commit 338b489
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 190 deletions.
66 changes: 31 additions & 35 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
end
end

new_git = handle_repos_develop!(ctx, pkgs, shared)
new = handle_repos_develop!(ctx, pkgs, shared)

for pkg in pkgs
if Types.collides_with_project(ctx, pkg)
Expand All @@ -100,7 +100,8 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
end
end

Operations.develop(ctx, pkgs, new_git; preserve=preserve, platform=platform)
Operations.assert_can_add(ctx, pkgs)
Operations.develop(ctx, pkgs, new; preserve=preserve, platform=platform)
return
end

Expand Down Expand Up @@ -145,7 +146,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=PR
end

repo_pkgs = [pkg for pkg in pkgs if (pkg.repo.source !== nothing || pkg.repo.rev !== nothing)]
new_git = handle_repos_add!(ctx, repo_pkgs)
new = handle_repos_add!(ctx, repo_pkgs)
# repo + unpinned -> name, uuid, repo.rev, repo.source, tree_hash
# repo + pinned -> name, uuid, tree_hash

Expand All @@ -162,7 +163,8 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=PR
end
end

Operations.add(ctx, pkgs, new_git; preserve=preserve, platform=platform)
Operations.assert_can_add(ctx, pkgs)
Operations.add(ctx, pkgs, new; preserve=preserve, platform=platform)
return
end

Expand Down Expand Up @@ -195,50 +197,45 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode=PKGMODE_PROJECT, kwarg
return
end

up(ctx::Context; kwargs...) = up(ctx, PackageSpec[]; kwargs...)
up(; kwargs...) = up(PackageSpec[]; kwargs...)
up(pkg::Union{AbstractString, PackageSpec}; kwargs...) = up([pkg]; kwargs...)
up(pkgs::Vector{<:AbstractString}; kwargs...) = up([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)
update(ctx::Context; kwargs...) = update(ctx, PackageSpec[]; kwargs...)
update(; kwargs...) = update(PackageSpec[]; kwargs...)
update(pkg::Union{AbstractString, PackageSpec}; kwargs...) = update([pkg]; kwargs...)
update(pkgs::Vector{<:AbstractString}; kwargs...) = update([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
update(pkgs::Vector{PackageSpec}; kwargs...) = update(Context(), pkgs; kwargs...)

function up(ctx::Context, pkgs::Vector{PackageSpec};
function update(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT,
update_registry::Bool=true, kwargs...)
pkgs = deepcopy(pkgs) # deepcopy for avoid mutating PackageSpec members
foreach(pkg -> pkg.mode = mode, pkgs)

Context!(ctx; kwargs...)

if update_registry
Types.clone_default_registries(ctx)
Types.update_registries(ctx; force=true)
end

new = UUID[]
if isempty(pkgs)
if mode == PKGMODE_PROJECT
for (name::String, uuid::UUID) in ctx.env.project.deps
repo = haskey(ctx.env.project.source, name) ? GitRepo(;source=ctx.env.project.source[name]) : GitRepo()
push!(pkgs, PackageSpec(name=name, uuid=uuid, repo=repo))
end
elseif mode == PKGMODE_MANIFEST
for (uuid, entry) in ctx.env.manifest
repo = GitRepo()
if uuid in values(ctx.env.project.deps) && haskey(ctx.env.project.source, entry.name)
repo = GitRepo(;source=ctx.env.project.source[entry.name])
end
push!(pkgs, PackageSpec(name=entry.name, uuid=uuid, repo=repo))
end
if mode === PKGMODE_PROJECT
pkgs = Operations.load_direct_deps(ctx, pkgs, new)
else
pkgs = Operations.load_all_deps(ctx, pkgs, new)
end
else
foreach(pkg -> pkg.mode = PKGMODE_PROJECT, pkgs)
project_deps_resolve!(ctx, pkgs)
manifest_resolve!(ctx, pkgs)
ensure_resolved(ctx, pkgs)
uuids = UUID[pkg.uuid for pkg in pkgs]
pkgs = filter(pkg -> pkg.uuid in uuids, Operations.load_direct_deps(ctx, PackageSpec[], new))
end
Operations.up(ctx, pkgs, level)

Operations.update(ctx, pkgs, new, level)
return
end

resolve(; kwargs...) = resolve(Context(); kwargs...)
function resolve(ctx::Context; kwargs...)
up(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, kwargs...)
update(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, kwargs...)
return nothing
end

Expand Down Expand Up @@ -758,9 +755,8 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
platform::Platform=platform_key_abi(), kwargs...)
Context!(ctx; kwargs...)
if !isfile(ctx.env.project_file) && isfile(ctx.env.manifest_file)
_manifest = Pkg.Types.read_manifest(ctx.env.manifest_file)
deps = Dict()
for (uuid, pkg) in _manifest
for (uuid, pkg) in Pkg.Types.read_manifest(ctx.env.manifest_file)
if pkg.name in keys(deps)
# TODO, query what package to put in Project when in interactive mode?
pkgerror("cannot instantiate a manifest without project file when the manifest has multiple packages with the same name ($(pkg.name))")
Expand All @@ -771,7 +767,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
return instantiate(Context(); manifest=manifest, update_registry=update_registry, verbose=verbose, kwargs...)
end
if (!isfile(ctx.env.manifest_file) && manifest === nothing) || manifest == false
up(ctx; update_registry=update_registry)
update(ctx; update_registry=update_registry)
return
end
if !isfile(ctx.env.manifest_file) && manifest == true
Expand All @@ -792,7 +788,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
Types.update_registries(ctx)
pkgs = Operations.load_all_deps(ctx)
Operations.check_registered(ctx, pkgs)
new_git = UUID[]
new = UUID[]
# Handling packages tracking repos
for pkg in pkgs
pkg.repo.source !== nothing || continue
Expand Down Expand Up @@ -821,15 +817,15 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
end
mkpath(sourcepath)
GitTools.checkout_tree_to_path(repo, tree_hash_object, sourcepath)
push!(new_git, pkg.uuid)
push!(new, pkg.uuid)
end
end

# Ensure artifacts are installed for the dependent packages, and finally this overall project
Operations.download_artifacts(ctx, pkgs; platform=platform, verbose=verbose)

new_apply = Operations.download_source(ctx, pkgs)
Operations.build_versions(ctx, union(UUID[pkg.uuid for pkg in new_apply], new_git); verbose=verbose)
union!(new, Operations.uuids(Operations.download_source(ctx, pkgs)))
Operations.build_versions(ctx, new; verbose=verbose)
end


Expand Down
Loading

0 comments on commit 338b489

Please sign in to comment.