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 source basedir resolution for erlang preloaded modules #1856

Merged
merged 4 commits into from
Jan 31, 2024
Merged
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
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
Loading