Skip to content

Commit 3ec97bd

Browse files
fix pkgdir for extensions
1 parent 95c643a commit 3ec97bd

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

base/loading.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ package root.
508508
To get the root directory of the package that implements the current module
509509
the form `pkgdir(@__MODULE__)` can be used.
510510
511+
If an extension module is given, the root of the parent package is returned.
512+
511513
```julia-repl
512514
julia> pkgdir(Foo)
513515
"/path/to/Foo.jl"
@@ -525,7 +527,23 @@ function pkgdir(m::Module, paths::String...)
525527
rootmodule = moduleroot(m)
526528
path = pathof(rootmodule)
527529
path === nothing && return nothing
528-
return joinpath(dirname(dirname(path)), paths...)
530+
original = copy(path)
531+
path = dirname(path)
532+
if endswith(path, "src")
533+
path = dirname(path)
534+
elseif contains(path, "ext")
535+
# extensions can reside at `../ext/FooExt.jl` or `../ext/FooExt/FooExt.jl`
536+
if endswith(path, "ext")
537+
path = dirname(path)
538+
else
539+
path = dirname(path)
540+
endswith(path, "ext") || error("Unexpected path structure for extension module: $original")
541+
path = dirname(path)
542+
end
543+
else
544+
error("Unexpected path structure for modul source: $original")
545+
end
546+
return joinpath(path, paths...)
529547
end
530548

531549
function get_pkgversion_from_path(path)

0 commit comments

Comments
 (0)