Skip to content

Commit 39b1b47

Browse files
KristofferCKristofferC
authored and
KristofferC
committed
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 (cherry picked from commit 5034e87)
1 parent 61f9847 commit 39b1b47

File tree

8 files changed

+45
-4
lines changed

8 files changed

+45
-4
lines changed

base/loading.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
658658
# if `pkg` matches the project, return the project itself
659659
return project_file_path(project_file)
660660
end
661-
mby_ext = project_file_ext_path(project_file, pkg.name)
661+
mby_ext = project_file_ext_path(project_file, pkg)
662662
mby_ext === nothing || return mby_ext
663663
# look for manifest file and `where` stanza
664664
return explicit_manifest_uuid_path(project_file, pkg)
@@ -676,13 +676,13 @@ function find_ext_path(project_path::String, extname::String)
676676
return joinpath(project_path, "ext", extname * ".jl")
677677
end
678678

679-
function project_file_ext_path(project_file::String, name::String)
679+
function project_file_ext_path(project_file::String, ext::PkgId)
680680
d = parsed_toml(project_file)
681681
p = project_file_path(project_file)
682682
exts = get(d, "extensions", nothing)::Union{Dict{String, Any}, Nothing}
683683
if exts !== nothing
684-
if name in keys(exts)
685-
return find_ext_path(p, name)
684+
if ext.name in keys(exts) && ext.uuid == uuid5(UUID(d["uuid"]::String), ext.name)
685+
return find_ext_path(p, ext.name)
686686
end
687687
end
688688
return nothing

test/loading.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,3 +1183,16 @@ end
11831183
@testset "Upgradable stdlibs" begin
11841184
@test success(`$(Base.julia_cmd()) --startup-file=no -e 'using DelimitedFiles'`)
11851185
end
1186+
1187+
@testset "extension path computation name collision" begin
1188+
old_load_path = copy(LOAD_PATH)
1189+
try
1190+
empty!(LOAD_PATH)
1191+
push!(LOAD_PATH, joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_A"))
1192+
push!(LOAD_PATH, joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_B"))
1193+
ext_B = Base.PkgId(Base.uuid5(Base.identify_package("ExtNameCollision_B").uuid, "REPLExt"), "REPLExt")
1194+
@test Base.locate_package(ext_B) == joinpath(@__DIR__, "project", "Extensions", "ExtNameCollision_B", "ext", "REPLExt.jl")
1195+
finally
1196+
copy!(LOAD_PATH, old_load_path)
1197+
end
1198+
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)