Skip to content

Commit

Permalink
Fix source basedir resolution for erlang preloaded modules (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi authored Jan 31, 2024
1 parent c5ffca5 commit 3062cd9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/ex_doc/language/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,27 @@ defmodule ExDoc.Language.Source do
## We use `module_info(:compile)[:source]` to get an absolute path
## to the source file and calculate the basedir from that

module.module_info(:compile)[:source]
compile_source =
cond do
source = module.module_info(:compile)[:source] ->
source

module in :erlang.pre_loaded() ->
{:ok, {_, [compile_info: compile_info]}} =
:beam_lib.chunks(
Application.app_dir(:erts, "ebin/#{module}.beam")
|> String.to_charlist(),
[:compile_info]
)

compile_info[:source]

true ->
# This should never happen...
raise "could not find source or debug info for #{inspect(module)}"
end

compile_source
|> String.Chars.to_string()
|> Path.absname()
|> Path.split()
Expand Down

0 comments on commit 3062cd9

Please sign in to comment.