diff --git a/base/loading.jl b/base/loading.jl index e3352d0d0b4ae1..0cbf0a52b9e68f 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1707,7 +1707,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} @@ -1722,6 +1723,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 89d61207e33d95..b9fb50a3287c17 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -178,6 +178,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)