Skip to content

Commit

Permalink
backport: fix missing uuid check on extension when finding the locati…
Browse files Browse the repository at this point in the history
…on of an extension (#54658) (#54663)
  • Loading branch information
KristofferC authored Jun 4, 2024
1 parent 61f9847 commit d2ea484
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
# if `pkg` matches the project, return the project itself
return project_file_path(project_file)
end
mby_ext = project_file_ext_path(project_file, pkg.name)
mby_ext = project_file_ext_path(project_file, pkg)
mby_ext === nothing || return mby_ext
# look for manifest file and `where` stanza
return explicit_manifest_uuid_path(project_file, pkg)
Expand All @@ -676,13 +676,13 @@ function find_ext_path(project_path::String, extname::String)
return joinpath(project_path, "ext", extname * ".jl")
end

function project_file_ext_path(project_file::String, name::String)
function project_file_ext_path(project_file::String, ext::PkgId)
d = parsed_toml(project_file)
p = project_file_path(project_file)
exts = get(d, "extensions", nothing)::Union{Dict{String, Any}, Nothing}
if exts !== nothing
if name in keys(exts)
return find_ext_path(p, name)
if ext.name in keys(exts) && ext.uuid == uuid5(UUID(d["uuid"]::String), ext.name)
return find_ext_path(p, ext.name)
end
end
return nothing
Expand Down
13 changes: 13 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1183,3 +1183,16 @@ end
@testset "Upgradable stdlibs" begin
@test success(`$(Base.julia_cmd()) --startup-file=no -e 'using DelimitedFiles'`)
end

@testset "extension path computation name collision" begin
old_load_path = copy(LOAD_PATH)
try
empty!(LOAD_PATH)
push!(LOAD_PATH, joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_A"))
push!(LOAD_PATH, joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_B"))
ext_B = Base.PkgId(Base.uuid5(Base.identify_package("ExtNameCollision_B").uuid, "REPLExt"), "REPLExt")
@test Base.locate_package(ext_B) == joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_B", "ext", "REPLExt.jl")
finally
copy!(LOAD_PATH, old_load_path)
end
end
9 changes: 9 additions & 0 deletions test/project/Extensions/ExtNameCollision_A/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "ExtNameCollision_A"
uuid = "9f48de98-8f56-4937-aa32-2a5530882eaa"
version = "0.1.0"

[weakdeps]
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[extensions]
REPLExt = "REPL"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ExtNameCollision_A

greet() = print("Hello World!")

end # module ExtNameCollision_A
9 changes: 9 additions & 0 deletions test/project/Extensions/ExtNameCollision_B/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "ExtNameCollision_B"
uuid = "597d654f-44d8-4443-9b1e-1f2f4b45906f"
version = "0.1.0"

[weakdeps]
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[extensions]
REPLExt = "REPL"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ExtNameCollision_B

greet() = print("Hello World!")

end # module ExtNameCollision_B

0 comments on commit d2ea484

Please sign in to comment.