Skip to content

Commit

Permalink
1.9 backports (#3438)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefan Karpinski <[email protected]>
Co-authored-by: Simeon Schaub <[email protected]>
fix minor print bug (#3431)
fix handling of relative paths in `bind_artifact!` (#3435)
Fixes JuliaPackaging/ArtifactUtils.jl#19
  • Loading branch information
IanButterworth authored Apr 13, 2023
1 parent 1b73599 commit 3ca8865
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,13 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
end

# return early if no deps
isempty(depsmap) && return
if isempty(depsmap)
if isempty(pkgs)
return
else
pkgerror("No direct dependencies outside of the sysimage found matching $(repr([p.name for p in pkgs]))")
end
end

# initialize signalling
started = Dict{Base.PkgId,Bool}()
Expand Down Expand Up @@ -1227,13 +1233,19 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
end
keep = Base.PkgId[]
for dep in depsmap
if first(dep).name in pkgs_names
push!(keep, first(dep))
append!(keep, collect_all_deps(depsmap, first(dep)))
dep_pkgid = first(dep)
if dep_pkgid.name in pkgs_names
push!(keep, dep_pkgid)
append!(keep, collect_all_deps(depsmap, dep_pkgid))
end
end
for ext in keys(exts)
if issubset(collect_all_deps(depsmap, ext), keep) # if all extension deps are kept
push!(keep, ext)
end
end
filter!(d->in(first(d), keep), depsmap)
isempty(depsmap) && pkgerror("No direct dependencies found matching $(repr(pkgs_names))")
isempty(depsmap) && pkgerror("No direct dependencies outside of the sysimage found matching $(repr(pkgs_names))")
target = join(pkgs_names, ", ")
else
target = "project..."
Expand Down Expand Up @@ -1284,7 +1296,7 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
wait(first_started)
(isempty(pkg_queue) || interrupted_or_done.set) && return
fancyprint && lock(print_lock) do
printpkgstyle(io, :Precompiling, "environment...")
printpkgstyle(io, :Precompiling, target)
print(io, ansi_disablecursor)
end
t = Timer(0; interval=1/10)
Expand Down
3 changes: 2 additions & 1 deletion src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ function bind_artifact!(artifacts_toml::String, name::String, hash::SHA1;

# Spit it out onto disk
let artifact_dict = artifact_dict
temp_artifacts_toml = tempname(dirname(artifacts_toml))
parent_dir = dirname(artifacts_toml)
temp_artifacts_toml = isempty(parent_dir) ? tempname(pwd()) : tempname(parent_dir)
open(temp_artifacts_toml, "w") do io
TOML.print(io, artifact_dict, sorted=true)
end
Expand Down
3 changes: 2 additions & 1 deletion src/REPLMode/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,11 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
push!(shown_envs, expanded_env)
end
menu = TerminalMenus.RadioMenu(option_list, keybindings=keybindings, pagesize=length(option_list))
default = min(2, length(option_list))
print(ctx.io, "\e[1A\e[1G\e[0J") # go up one line, to the start, and clear it
printstyled(ctx.io, ""; color=:green)
choice = try
TerminalMenus.request("Select environment:", menu)
TerminalMenus.request("Select environment:", menu, cursor=default)
catch err
if err isa InterruptException # if ^C is entered
println(ctx.io)
Expand Down
9 changes: 9 additions & 0 deletions test/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ end
Pkg.activate(".")
Pkg.activate("CircularDep3")
@test_logs (:warn, r"Circular dependency detected") Pkg.precompile()

Pkg.activate(temp=true)
Pkg.precompile() # precompile an empty env should be a no-op
@test_throws Pkg.Types.PkgError Pkg.precompile("DoesNotExist") # fail to find a nonexistant dep in an empty env

Pkg.add("Random")
@test_throws Pkg.Types.PkgError Pkg.precompile("Random") # Random is a dep but in the sysimage
@test_throws Pkg.Types.PkgError Pkg.precompile("DoesNotExist")
Pkg.precompile() # should be a no-op
end end
end

Expand Down
20 changes: 20 additions & 0 deletions test/artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,26 @@ end
meta = artifact_meta("foo_txt", artifacts_toml; platform=win32)
@test meta["download"][1]["url"] == "http://google.com/hello_world"
@test meta["download"][2]["sha256"] == "a"^64

rm(artifacts_toml)

# test relative Artifacts.toml paths (https://github.com/simeonschaub/ArtifactUtils.jl/issues/19)
cd(path) do
hash3 = create_artifact() do path
open(joinpath(path, "foo.txt"), "w") do io
print(io, "bla bla")
end
end

# Bind this artifact to something
artifacts_toml = "Artifacts.toml" # no parent dir specified
@test artifact_hash("foo_txt", artifacts_toml) == nothing
bind_artifact!(artifacts_toml, "foo_txt", hash3)

# Test that this binding worked
@test artifact_hash("foo_txt", artifacts_toml) == hash3
@test ensure_artifact_installed("foo_txt", artifacts_toml) == artifact_path(hash3)
end
end

# Let's test some known-bad Artifacts.toml files
Expand Down
16 changes: 16 additions & 0 deletions test/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,20 @@ using Test
Pkg.test("HasDepWithExtensions", julia_args=`--depwarn=no`) # OffsetArrays errors from depwarn
@test_throws Pkg.Resolve.ResolverError Pkg.add(; name = "OffsetArrays", version = "0.9.0")
end
isolate(loaded_depot=false) do
withenv("JULIA_PKG_PRECOMPILE_AUTO" => 0) do
depot = mktempdir(); empty!(DEPOT_PATH); push!(DEPOT_PATH, depot)
Pkg.activate(; temp=true)
Pkg.Registry.add(Pkg.RegistrySpec(path=joinpath(@__DIR__, "test_packages", "ExtensionExamples", "ExtensionRegistry")))
Pkg.Registry.add("General")
Pkg.add("HasDepWithExtensions")
end
iob = IOBuffer()
Pkg.precompile("HasDepWithExtensions", io=iob)
out = String(take!(iob))
@test occursin("Precompiling", out)
@test occursin("OffsetArraysExt", out)
@test occursin("HasExtensions", out)
@test occursin("HasDepWithExtensions", out)
end
end

0 comments on commit 3ca8865

Please sign in to comment.