Skip to content

Commit 5034e87

Browse files
authored
fix missing uuid check on extension when finding the location of an extension (#54658)
in stacked environments with name collisions of extensions, this could compute the path for the wrong extension Fixes JuliaLang/Pkg.jl#3906
1 parent 770a464 commit 5034e87

File tree

8 files changed

+47
-8
lines changed

8 files changed

+47
-8
lines changed

base/loading.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
694694
# if `pkg` matches the project, return the project itself
695695
return project_file_path(project_file, pkg.name)
696696
end
697-
mby_ext = project_file_ext_path(project_file, pkg.name)
697+
mby_ext = project_file_ext_path(project_file, pkg)
698698
mby_ext === nothing || return mby_ext
699699
# look for manifest file and `where` stanza
700700
return explicit_manifest_uuid_path(project_file, pkg)
@@ -709,7 +709,7 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
709709
if parent_project_file !== nothing
710710
parentproj = project_file_name_uuid(parent_project_file, parentid.name)
711711
if parentproj == parentid
712-
mby_ext = project_file_ext_path(parent_project_file, pkg.name)
712+
mby_ext = project_file_ext_path(parent_project_file, pkg)
713713
mby_ext === nothing || return mby_ext
714714
end
715715
end
@@ -725,13 +725,13 @@ function find_ext_path(project_path::String, extname::String)
725725
return joinpath(project_path, "ext", extname * ".jl")
726726
end
727727

728-
function project_file_ext_path(project_file::String, name::String)
728+
function project_file_ext_path(project_file::String, ext::PkgId)
729729
d = parsed_toml(project_file)
730730
p = dirname(project_file)
731731
exts = get(d, "extensions", nothing)::Union{Dict{String, Any}, Nothing}
732732
if exts !== nothing
733-
if name in keys(exts)
734-
return find_ext_path(p, name)
733+
if ext.name in keys(exts) && ext.uuid == uuid5(UUID(d["uuid"]::String), ext.name)
734+
return find_ext_path(p, ext.name)
735735
end
736736
end
737737
return nothing
@@ -834,9 +834,7 @@ function implicit_env_project_file_extension(dir::String, ext::PkgId)
834834
for pkg in readdir(dir; join=true)
835835
project_file = env_project_file(pkg)
836836
project_file isa String || continue
837-
proj = project_file_name_uuid(project_file, "")
838-
uuid5(proj.uuid, ext.name) == ext.uuid || continue
839-
path = project_file_ext_path(project_file, ext.name)
837+
path = project_file_ext_path(project_file, ext)
840838
if path !== nothing
841839
return path, project_file
842840
end

test/loading.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,3 +1630,16 @@ end
16301630
copy!(LOAD_PATH, old_load_path)
16311631
end
16321632
end
1633+
1634+
@testset "extension path computation name collision" begin
1635+
old_load_path = copy(LOAD_PATH)
1636+
try
1637+
empty!(LOAD_PATH)
1638+
push!(LOAD_PATH, joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_A"))
1639+
push!(LOAD_PATH, joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_B"))
1640+
ext_B = Base.PkgId(Base.uuid5(Base.identify_package("ExtNameCollision_B").uuid, "REPLExt"), "REPLExt")
1641+
@test Base.locate_package(ext_B) == joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_B", "ext", "REPLExt.jl")
1642+
finally
1643+
copy!(LOAD_PATH, old_load_path)
1644+
end
1645+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "ExtNameCollision_A"
2+
uuid = "9f48de98-8f56-4937-aa32-2a5530882eaa"
3+
version = "0.1.0"
4+
5+
[weakdeps]
6+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
7+
8+
[extensions]
9+
REPLExt = "REPL"

test/project/Extensions/ExtNameCollision_A/ext/REPLExt.jl

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module ExtNameCollision_A
2+
3+
greet() = print("Hello World!")
4+
5+
end # module ExtNameCollision_A
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "ExtNameCollision_B"
2+
uuid = "597d654f-44d8-4443-9b1e-1f2f4b45906f"
3+
version = "0.1.0"
4+
5+
[weakdeps]
6+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
7+
8+
[extensions]
9+
REPLExt = "REPL"

test/project/Extensions/ExtNameCollision_B/ext/REPLExt.jl

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module ExtNameCollision_B
2+
3+
greet() = print("Hello World!")
4+
5+
end # module ExtNameCollision_B

0 commit comments

Comments
 (0)