diff --git a/base/loading.jl b/base/loading.jl index 2b1f934ff6ffe..d406d3a409737 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1652,7 +1652,8 @@ function srctext_files(f::IO, srctextpos::Int64) end # Test to see if this UUID is mentioned in this `Project.toml`; either as -# the top-level UUID (e.g. that of the project itself) or as a dependency. +# the top-level UUID (e.g. that of the project itself), as a dependency, +# or as a extra for Preferences. function get_uuid_name(project::Dict{String, Any}, uuid::UUID) uuid_p = get(project, "uuid", nothing)::Union{Nothing, String} name = get(project, "name", nothing)::Union{Nothing, String} @@ -1667,6 +1668,16 @@ function get_uuid_name(project::Dict{String, Any}, uuid::UUID) end end end + for subkey in ("deps", "extras") + subsection = get(project, subkey, nothing)::Union{Nothing, Dict{String, Any}} + if subsection !== nothing + for (k, v) in subsection + if uuid == UUID(v::String) + return k + end + end + end + end return nothing end diff --git a/test/loading.jl b/test/loading.jl index c56f6c463a21f..3970813fbd29b 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -189,6 +189,42 @@ end end end +# extras +@testset "extras" begin + mktempdir() do dir + project_file = joinpath(dir, "Project.toml") + touch(project_file) # dummy_uuid calls realpath + # various UUIDs to work with + proj_uuid = dummy_uuid(project_file) + root_uuid = uuid4() + this_uuid = uuid4() + + old_load_path = copy(LOAD_PATH) + try + copy!(LOAD_PATH, [project_file]) + write(project_file, """ + name = "Root" + uuid = "$root_uuid" + [extras] + This = "$this_uuid" + """) + # look up various packages by name + root = Base.identify_package("Root") + this = Base.identify_package("This") + that = Base.identify_package("That") + + @test root.uuid == root_uuid + @test this == nothing + @test that == nothing + + @test Base.get_uuid_name(project_file, this_uuid) == "This" + finally + copy!(LOAD_PATH, old_load_path) + end + end +end + + ## functional testing of package identification, location & loading ## saved_load_path = copy(LOAD_PATH)