diff --git a/src/API.jl b/src/API.jl index b9555bfc4f..14536c8a59 100644 --- a/src/API.jl +++ b/src/API.jl @@ -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}() @@ -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..." @@ -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) diff --git a/src/Artifacts.jl b/src/Artifacts.jl index 0951bbebff..f12aa41aaf 100644 --- a/src/Artifacts.jl +++ b/src/Artifacts.jl @@ -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 diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index f0866a438a..99bfa55d3e 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -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) diff --git a/test/api.jl b/test/api.jl index 4e91b4b025..195a3c8cd1 100644 --- a/test/api.jl +++ b/test/api.jl @@ -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 diff --git a/test/artifacts.jl b/test/artifacts.jl index 5aa58a5992..29eb217139 100644 --- a/test/artifacts.jl +++ b/test/artifacts.jl @@ -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 diff --git a/test/extensions.jl b/test/extensions.jl index e9fe24f081..1a76757d7d 100644 --- a/test/extensions.jl +++ b/test/extensions.jl @@ -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