Skip to content

Commit

Permalink
Merge pull request JuliaLang#26336 from JuliaLang/kc/bump_pkg3
Browse files Browse the repository at this point in the history
Update Pkg3
  • Loading branch information
KristofferC authored Mar 9, 2018
2 parents fe6975b + ebc1105 commit a475e93
Show file tree
Hide file tree
Showing 19 changed files with 769 additions and 334 deletions.
6 changes: 4 additions & 2 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ function parse_load_path(str::String)
end

function init_load_path(BINDIR = Sys.BINDIR)
load_path = get(ENV, "JULIA_LOAD_PATH", "@|@v#.#.#|@v#.#|@v#|@default|@!v#.#")
append!(empty!(LOAD_PATH), parse_load_path(load_path))
if !Base.creating_sysimg
load_path = get(ENV, "JULIA_LOAD_PATH", "@|@v#.#.#|@v#.#|@v#|@default|@!v#.#")
append!(empty!(LOAD_PATH), parse_load_path(load_path))
end
vers = "v$(VERSION.major).$(VERSION.minor)"
push!(LOAD_PATH, abspath(BINDIR, "..", "local", "share", "julia", "site", vers))
push!(LOAD_PATH, abspath(BINDIR, "..", "share", "julia", "site", vers))
Expand Down
9 changes: 7 additions & 2 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ include("loading.jl")
# misc useful functions & macros
include("util.jl")

creating_sysimg = true
# set up depot & load paths to be able to find stdlib packages
let BINDIR = Sys.BINDIR
init_depot_path(BINDIR)
Expand Down Expand Up @@ -927,14 +928,15 @@ end
# Clear global state
empty!(Core.ARGS)
empty!(Base.ARGS)
empty!(DEPOT_PATH)
empty!(LOAD_PATH)
@eval Base.Sys BINDIR = ""
@eval Base creating_sysimg = false
Base.init_load_path() # want to be able to find external packages in userimg.jl

let
tot_time_userimg = @elapsed (Base.isfile("userimg.jl") && Base.include(Main, "userimg.jl"))
tot_time_precompile = Base.is_primary_base_module ? (@elapsed Base.include(Base, "precompile.jl")) : 0.0


tot_time_base = (Base.end_base_include - Base.start_base_include) * 10.0^(-9)
tot_time = tot_time_base + Base.tot_time_stdlib[] + tot_time_userimg + tot_time_precompile

Expand All @@ -947,3 +949,6 @@ print("Userimg: ──── "); Base.time_print(tot_time_userimg * 10^9);
end
print("Precompile: ─ "); Base.time_print(tot_time_precompile * 10^9); print(" "); showcompact((tot_time_precompile / tot_time) * 100); println("%")
end

empty!(LOAD_PATH)
empty!(DEPOT_PATH)
6 changes: 4 additions & 2 deletions stdlib/Pkg/src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ custom METADATA setup.
init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) = Dir.init(meta,branch)

function __init__()
vers = "v$(VERSION.major).$(VERSION.minor)"
push!(Base.LOAD_PATH, dir)
if !Base.creating_sysimg
vers = "v$(VERSION.major).$(VERSION.minor)"
push!(Base.LOAD_PATH, dir)
end
end

"""
Expand Down
4 changes: 4 additions & 0 deletions stdlib/Pkg3/bin/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ for (bucket, b_pkgs) in buckets, (pkg, p) in b_pkgs
val = f(dep, d)
val == nothing && continue
haskey(data, ver) || (data[ver] = Dict{String,String}())
# BinDeps injects a dependency on Libdl
if name == "Deps" && dep == "BinDeps"
data[ver]["Libdl"] = "\"8f399da3-3557-5675-b5ff-fb832c97cbdb\""
end
data[ver][dep] = val
end
compressed = compress_versions_data(data, versions)
Expand Down
54 changes: 29 additions & 25 deletions stdlib/Pkg3/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import Random
import Dates
import LibGit2

import Pkg3
import Pkg3: depots, logdir, devdir, print_first_command_header
using Pkg3.Types
using Pkg3.TOML
import ..depots, ..logdir, ..devdir, ..print_first_command_header
import ..Operations, ..Display
using ..Types, ..TOML


preview_info() = @info("In preview mode")
Expand All @@ -22,10 +21,12 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
handle_repos!(ctx.env, pkgs)
project_resolve!(ctx.env, pkgs)
registry_resolve!(ctx.env, pkgs)
stdlib_resolve!(ctx, pkgs)
ensure_resolved(ctx.env, pkgs, true)
Pkg3.Operations.add(ctx, pkgs)
Operations.add(ctx, pkgs)
end


Expand All @@ -39,7 +40,7 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
manifest_resolve!(ctx.env, pkgs)
Pkg3.Operations.rm(ctx, pkgs)
Operations.rm(ctx, pkgs)
end


Expand Down Expand Up @@ -120,7 +121,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
manifest_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs)
end
Pkg3.Operations.up(ctx, pkgs)
Operations.up(ctx, pkgs)
end


Expand All @@ -134,7 +135,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs)
Pkg3.Operations.pin(ctx, pkgs)
Operations.pin(ctx, pkgs)
end


Expand All @@ -146,28 +147,31 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
registry_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs)
Pkg3.Operations.free(ctx, pkgs)
Operations.free(ctx, pkgs)
end


checkout(pkg::Union{String, PackageSpec}; kwargs...) = checkout([pkg]; kwargs...)
checkout(pkg::String, branch::String; kwargs...) = checkout([(PackageSpec(pkg), branch)]; kwargs...)
checkout(pkg::PackageSpec, branch::String; kwargs...) = checkout([(pkg, branch)]; kwargs...)
checkout(pkgs::Vector{String}; kwargs...) = checkout([(PackageSpec(pkg), nothing) for pkg in pkgs]; kwargs...)
checkout(pkgs::Vector{PackageSpec}; kwargs...) = checkout([(pkg, nothing) for pkg in pkgs]; kwargs...)
checkout(pkgs_branches::Vector; kwargs...) = checkout(Context(), pkgs_branches; kwargs...)
#deprecated
@deprecate checkout develop

develop(pkg::Union{String, PackageSpec}; kwargs...) = develop([pkg]; kwargs...)
develop(pkg::String, branch::String; kwargs...) = develop([(PackageSpec(pkg), branch)]; kwargs...)
develop(pkg::PackageSpec, branch::String; kwargs...) = develop([(pkg, branch)]; kwargs...)
develop(pkgs::Vector{String}; kwargs...) = develop([(PackageSpec(pkg), nothing) for pkg in pkgs]; kwargs...)
develop(pkgs::Vector{PackageSpec}; kwargs...) = develop([(pkg, nothing) for pkg in pkgs]; kwargs...)
develop(pkgs_branches::Vector; kwargs...) = develop(Context(), pkgs_branches; kwargs...)

function checkout(ctx::Context, pkgs_branches::Vector; path = devdir(), kwargs...)
function develop(ctx::Context, pkgs_branches::Vector; path = devdir(), kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
pkgs = [p[1] for p in pkgs_branches]
project_resolve!(ctx.env, pkgs)
registry_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs)
Pkg3.Operations.checkout(ctx, pkgs_branches; path = path)
Operations.develop(ctx, pkgs_branches; path = path)
end


Expand All @@ -183,13 +187,13 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, kwargs...
project_resolve!(ctx.env, pkgs)
manifest_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs)
Pkg3.Operations.test(ctx, pkgs; coverage=coverage)
Operations.test(ctx, pkgs; coverage=coverage)
end


function installed(mode::PackageMode=PKGMODE_MANIFEST)::Dict{String, VersionNumber}
diffs = Pkg3.Display.status(Context(), mode, #=use_as_api=# true)
version_status = Dict{String, VersionNumber}()
function installed(mode::PackageMode=PKGMODE_MANIFEST)
diffs = Display.status(Context(), mode, #=use_as_api=# true)
version_status = Dict{String, Union{VersionNumber,Nothing}}()
diffs == nothing && return version_status
for entry in diffs
version_status[entry.name] = entry.new.ver
Expand Down Expand Up @@ -244,7 +248,7 @@ function gc(ctx::Context=Context(); period = Dates.Week(6), kwargs...)
stanzas = _stanzas[1]
if stanzas isa Dict && haskey(stanzas, "uuid") && haskey(stanzas, "git-tree-sha1")
push!(paths_to_keep,
Pkg3.Operations.find_installed(name, UUID(stanzas["uuid"]), SHA1(stanzas["git-tree-sha1"])))
Operations.find_installed(name, UUID(stanzas["uuid"]), SHA1(stanzas["git-tree-sha1"])))
end
end
end
Expand Down Expand Up @@ -334,15 +338,15 @@ function build(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
uuids = UUID[]
_get_deps!(ctx, pkgs, uuids)
length(uuids) == 0 && (@info("no packages to build"); return)
Pkg3.Operations.build_versions(ctx, uuids; do_resolve=true)
Operations.build_versions(ctx, uuids; might_need_to_resolve=true)
end

init() = init(Context())
init(path::String) = init(Context(), path)
function init(ctx::Context, path::String=pwd())
print_first_command_header()
Context!(ctx; env = EnvCache(joinpath(path, "Project.toml")))
Pkg3.Operations.init(ctx)
Operations.init(ctx)
end

end # module
46 changes: 28 additions & 18 deletions stdlib/Pkg3/src/Display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module Display
using UUIDs
import LibGit2

using Pkg3.Types
import Pkg3: @info, Nothing

using ..Types

const colors = Dict(
' ' => :white,
Expand Down Expand Up @@ -45,18 +43,18 @@ function status(ctx::Context, mode::PackageMode, use_as_api=false)
m₀ = filter_manifest(in_project(project₀["deps"]), manifest₀)
m₁ = filter_manifest(in_project(project₁["deps"]), manifest₁)
use_as_api || @info("Status $(pathrepr(env, env.project_file))")
diff = manifest_diff(m₀, m₁)
diff = manifest_diff(ctx, m₀, m₁)
use_as_api || print_diff(diff)
end
if mode == PKGMODE_MANIFEST
use_as_api || @info("Status $(pathrepr(env, env.manifest_file))")
diff = manifest_diff(manifest₀, manifest₁)
diff = manifest_diff(ctx, manifest₀, manifest₁)
use_as_api || print_diff(diff)
elseif mode == PKGMODE_COMBINED
p = not_in_project(merge(project₀["deps"], project₁["deps"]))
m₀ = filter_manifest(p, manifest₀)
m₁ = filter_manifest(p, manifest₁)
c_diff = filter!(x->x.old != x.new, manifest_diff(m₀, m₁))
c_diff = filter!(x->x.old != x.new, manifest_diff(ctx, m₀, m₁))
if !isempty(c_diff)
use_as_api || @info("Status $(pathrepr(env, env.manifest_file))")
use_as_api || print_diff(c_diff)
Expand All @@ -66,19 +64,19 @@ function status(ctx::Context, mode::PackageMode, use_as_api=false)
return diff
end

function print_project_diff(env₀::EnvCache, env₁::EnvCache)
function print_project_diff(ctx::Context, env₀::EnvCache, env₁::EnvCache)
pm₀ = filter_manifest(in_project(env₀.project["deps"]), env₀.manifest)
pm₁ = filter_manifest(in_project(env₁.project["deps"]), env₁.manifest)
diff = filter!(x->x.old != x.new, manifest_diff(pm₀, pm₁))
diff = filter!(x->x.old != x.new, manifest_diff(ctx, pm₀, pm₁))
if isempty(diff)
printstyled(color = color_dark, " [no changes]\n")
else
print_diff(diff)
end
end

function print_manifest_diff(env₀::EnvCache, env₁::EnvCache)
diff = manifest_diff(env₀.manifest, env₁.manifest)
function print_manifest_diff(ctx::Context, env₀::EnvCache, env₁::EnvCache)
diff = manifest_diff(ctx, env₀.manifest, env₁.manifest)
diff = filter!(x->x.old != x.new, diff)
if isempty(diff)
printstyled(color = color_dark, " [no changes]\n")
Expand All @@ -92,12 +90,18 @@ struct VerInfo
path::Union{String,Nothing}
ver::Union{VersionNumber,Nothing}
pinned::Bool
repo::Union{Types.GitRepo, Nothing}
end

revstring(str::String) = contains(str, r"\b([a-f0-9]{40})\b") ? str[1:7] : str

vstring(a::VerInfo) =
string(a.ver == nothing ? "[$(string(a.hash)[1:16])]" : "v$(a.ver)",
string((a.ver == nothing && a.hash != nothing) ? "[$(string(a.hash)[1:16])]" : "",
a.ver != nothing ? "v$(a.ver)" : "",
a.pinned == true ? "" : "",
a.path != nothing ? " [$(a.path)]" : "")
a.path != nothing ? " [$(a.path)]" : "",
a.repo != nothing ? " #$(revstring(a.repo.rev))" : ""
)

Base.:(==)(a::VerInfo, b::VerInfo) =
a.hash == b.hash && a.ver == b.ver && a.pinned == b.pinned
Expand Down Expand Up @@ -126,7 +130,8 @@ function print_diff(io::IO, diff::Vector{DiffEntry})
verb = x.old.ver == nothing || x.new.ver == nothing ||
x.old.ver == x.new.ver ? '~' :
x.old.ver < x.new.ver ? '' : ''
elseif x.old.ver == x.new.ver && x.old.pinned != x.new.pinned
elseif x.old.ver == x.new.ver && x.old.pinned != x.new.pinned ||
x.old.repo != nothing || x.new.repo != nothing
verb = '~'
else
verb = '?'
Expand All @@ -150,8 +155,8 @@ function print_diff(io::IO, diff::Vector{DiffEntry})
vstr = "[unknown]"
end
v = same ? "" : " $verb"
printstyled(color = color_dark, " [$(string(x.uuid)[1:8])]")
printstyled(color = colors[verb], "$v $(x.name) $vstr\n")
printstyled(io, " [$(string(x.uuid)[1:8])]"; color = color_dark)
printstyled(io, "$v $(x.name) $vstr\n"; color = colors[verb])
end
end
print_diff(diff::Vector{DiffEntry}) = print_diff(stdout, diff)
Expand All @@ -172,10 +177,15 @@ function name_ver_info(info::Dict)
ver = haskey(info, "version") ? VersionNumber(info["version"]) : nothing
path = get(info, "path", nothing)
pin = get(info, "pinned", false)
name, VerInfo(hash, path, ver, pin)
if haskey(info, "repo-url")
repo = Types.GitRepo(info["repo-url"], info["repo-rev"])
else
repo = nothing
end
name, VerInfo(hash, path, ver, pin, repo)
end

function manifest_diff(manifest₀::Dict, manifest₁::Dict)
function manifest_diff(ctx::Context, manifest₀::Dict, manifest₁::Dict)
diff = DiffEntry[]
entries₀ = manifest_by_uuid(manifest₀)
entries₁ = manifest_by_uuid(manifest₁)
Expand All @@ -192,7 +202,7 @@ function manifest_diff(manifest₀::Dict, manifest₁::Dict)
push!(diff, DiffEntry(uuid, name₁, nothing, v₁))
end
end
sort!(diff, by=x->(x.name, x.uuid))
sort!(diff, by=x->(x.uuid in keys(ctx.stdlibs), x.name, x.uuid))
end

function filter_manifest!(predicate, manifest::Dict)
Expand Down
5 changes: 2 additions & 3 deletions stdlib/Pkg3/src/GraphType.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

module GraphType

import ..Pkg3
using Pkg3.Types
import Pkg3: equalto, Nothing, Types.uuid_julia
using ..Types
import ..Types.uuid_julia

export Graph, ResolveLog, add_reqs!, add_fixed!, simplify_graph!, simplify_graph_soft!,
get_resolve_log, showlog, push_snapshot!, pop_snapshot!, wipe_snapshots!
Expand Down
Loading

0 comments on commit a475e93

Please sign in to comment.