Skip to content

Commit

Permalink
change source resolution order
Browse files Browse the repository at this point in the history
  • Loading branch information
00vareladavid committed Feb 12, 2020
1 parent 630bf0a commit f21ee36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ function update_env!(ctx::Context, pkgs::Vector{PackageSpec})
pkg.uuid in values(ctx.env.project.deps) || continue
!is_tracking_registry(pkg) || continue
pkg.repo.source !== nothing || continue # old style project files discard the source when tracking path
# TODO filter by unregistered UUID
ctx.env.project.source[pkg.name] = pkg.repo.source
end
# remove unnecesary sources for project
Expand Down Expand Up @@ -993,11 +992,12 @@ function add_package(ctx::Context, pkg::PackageSpec, entry::PackageEntry)
return pkg
end

is_registered(ctx::Context, uuid::UUID) = !isempty(registered_paths(ctx, uuid))
function check_registered(ctx::Context, pkgs::Vector{PackageSpec})
pkgs = filter(tracking_registered_version, pkgs)
find_registered!(ctx, UUID[pkg.uuid for pkg in pkgs])
for pkg in pkgs
isempty(registered_paths(ctx, pkg.uuid)) || continue
is_registered(ctx, pkg.uuid) && continue
pkgerror("expected package $(err_rep(pkg)) to be registered")
end
end
Expand Down Expand Up @@ -1068,7 +1068,7 @@ end

has_unregistered_source(project::Project, pkg::PackageSpec) = pkg.uuid in keys(project.deps) && pkg.name in values(project.source)

function collect_unregistered!(ctx::Context, pkg::PackageSpec, dev::Bool, new_git::Vector{UUID}, pkgs::Vector{PackageSpec})
function collect_unregistered!(ctx::Context, pkg::PackageSpec, new_git::Vector{UUID}, pkgs::Vector{PackageSpec})
project_path = project_rel_path(ctx, source_path(pkg))
projectfile = projectfile_path(project_path; strict=true)
if projectfile === nothing
Expand All @@ -1079,26 +1079,26 @@ function collect_unregistered!(ctx::Context, pkg::PackageSpec, dev::Bool, new_gi
for (name, uuid) in src_project.deps
new_pkg = nothing
entry = get(src_manifest, uuid, nothing)
if dev && entry !== nothing && is_tracking_path(entry)
if (source = get(src_project.source, name, nothing)) !== nothing
new_pkg = PackageSpec(;repo=GitRepo(;source=source))
Types.handle_repo_add!(ctx, new_pkg) && push!(new_git, new_pkg.uuid)
elseif entry !== nothing && is_tracking_path(entry) && !is_registered(ctx, uuid)
path = project_rel_path(project_path, entry.path)
new_pkg = PackageSpec(;name=name, uuid=uuid, path=path, repo=entry.repo, tree_hash=entry.tree_hash)
if !isdir(path)
pkgerror("expected package $(err_rep(new_pkg)) to exist at directory `$path`")
end
elseif (source = get(src_project.source, name, nothing)) !== nothing
new_pkg = PackageSpec(;repo=GitRepo(;source=source))
Types.handle_repo_add!(ctx, new_pkg) && push!(new_git, new_pkg.uuid)
end
new_pkg === nothing && continue
findfirst(pkg -> pkg.uuid == new_pkg.uuid, pkgs) === nothing || continue
push!(pkgs, new_pkg)
collect_unregistered!(ctx, new_pkg, dev, new_git, pkgs)
collect_unregistered!(ctx, new_pkg, new_git, pkgs)
end
end

function collect_unregistered!(ctx::Context, pkgs::Vector{PackageSpec}, new_git; dev::Bool=false)
function collect_unregistered!(ctx::Context, pkgs::Vector{PackageSpec}, new_git)
for pkg in filter(!is_tracking_registry, pkgs)
collect_unregistered!(ctx, pkg, dev, new_git, pkgs)
collect_unregistered!(ctx, pkg, new_git, pkgs)
end
return pkgs
end
Expand Down Expand Up @@ -1135,7 +1135,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Vector{UUID};
pkgs = load_direct_deps(ctx, pkgs)
# handle unregistered dependencies
# TODO make sure filter is working well with invariants
collect_unregistered!(ctx, pkgs, new_git; dev=true)
collect_unregistered!(ctx, pkgs, new_git)
check_registered(ctx, pkgs)
# resolve & apply package versions
pkgs = resolve(ctx, pkgs, preserve)
Expand Down Expand Up @@ -1208,7 +1208,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec}, level::UpgradeLevel)
new && push!(new_git, pkg.uuid)
end
end
collect_unregistered!(ctx, pkgs, new_git; dev=true)
collect_unregistered!(ctx, pkgs, new_git)
check_registered(ctx, pkgs)
resolve_versions!(ctx, pkgs)
prune_manifest(ctx)
Expand Down
15 changes: 14 additions & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ function devpath(ctx::Context, name::String, shared::Bool)
return joinpath(dev_dir, name)
end

function extract_source(path)
source = nothing
try
LibGit2.with(LibGit2.GitRepo(path)) do repo
GitTools.check_valid_HEAD(repo)
source = path
source = LibGit2.url(LibGit2.get(LibGit2.GitRemote, repo, "origin"))
end
catch err
end
return source
end

function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool)
# First, check if we can compute the path easily (which requires a given local path or name)
is_local_path = pkg.repo.source !== nothing && !isurl(pkg.repo.source)
Expand All @@ -441,7 +454,7 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool)
else
pkg.path = shared ? dev_path : relative_project_path(ctx, dev_path)
end
pkg.repo.source = nothing
pkg.repo.source = extract_source(pkg.repo.source)
return false
end
end
Expand Down

0 comments on commit f21ee36

Please sign in to comment.