Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing uuid check on extension when finding the location of an extension #54658

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,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, pkg.name)
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 @@ -709,7 +709,7 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
if parent_project_file !== nothing
parentproj = project_file_name_uuid(parent_project_file, parentid.name)
if parentproj == parentid
mby_ext = project_file_ext_path(parent_project_file, pkg.name)
mby_ext = project_file_ext_path(parent_project_file, pkg)
mby_ext === nothing || return mby_ext
end
end
Expand All @@ -725,13 +725,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 = dirname(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 Expand Up @@ -834,9 +834,7 @@ function implicit_env_project_file_extension(dir::String, ext::PkgId)
for pkg in readdir(dir; join=true)
project_file = env_project_file(pkg)
project_file isa String || continue
proj = project_file_name_uuid(project_file, "")
uuid5(proj.uuid, ext.name) == ext.uuid || continue
path = project_file_ext_path(project_file, ext.name)
path = project_file_ext_path(project_file, ext)
if path !== nothing
return path, project_file
end
Expand Down
13 changes: 13 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1630,3 +1630,16 @@ end
copy!(LOAD_PATH, old_load_path)
end
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