File 1164-stdlib-man_docs-no-longer-depends-on-ERL_TOP.patch of Package erlang
From 4274a4ce244677840e280a7172166cef7006ef92 Mon Sep 17 00:00:00 2001
From: Fredrik Frantzen <frazze@erlang.org>
Date: Mon, 24 Nov 2025 11:15:24 +0100
Subject: [PATCH] stdlib: man_docs no longer depends on ERL_TOP
fixes render_man test
test fails gracefully for modules not in OTP
---
lib/stdlib/src/man_docs.erl | 24 ++++++++++++++----------
lib/stdlib/test/shell_docs_SUITE.erl | 23 ++++++++++-------------
2 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/lib/stdlib/src/man_docs.erl b/lib/stdlib/src/man_docs.erl
index 2bcac70f1e..4b5bb45b6f 100644
--- a/lib/stdlib/src/man_docs.erl
+++ b/lib/stdlib/src/man_docs.erl
@@ -67,16 +67,7 @@ markdown_to_manpage(Markdown, Path, Section) ->
markdown_to_manpage1(shell_docs_markdown:parse_md(Markdown), Path, Section).
markdown_to_manpage1(MarkdownChunks, Path, Section) ->
Path1 = filename:absname(Path),
- App = case filename:split(string:prefix(Path1, os:getenv("ERL_TOP"))) of
- ["/", "lib", AppStr | _] ->
- list_to_atom(AppStr);
- ["lib", AppStr | _] ->
- list_to_atom(AppStr);
- ["/", "erts" | _] ->
- list_to_atom("erts");
- ["nomatch"] ->
- error("ERL_TOP environment variable doesn't match the PATH " ++ Path)
- end,
+ App = get_app(Path1),
Version = case application:load(App) of
ok -> {ok,Vsn} = application:get_key(App, vsn), Vsn;
{error, {"no such file or directory","erts.app"}} -> erlang:system_info(version);
@@ -91,6 +82,19 @@ markdown_to_manpage1(MarkdownChunks, Path, Section) ->
I = conv(MarkdownChunks, Name),
iolist_to_binary([Prelude|I]).
+get_app(Path) ->
+ case string:split(Path, "/erts/") of
+ [_, _] -> list_to_atom("erts");
+ _ -> case string:split(Path, "/lib/") of
+ [_, Rest] ->
+ case string:split(Rest, "/") of
+ [AppStr, _] -> list_to_atom(AppStr);
+ _ -> error("Could not find app from path " ++ Path)
+ end;
+ _ -> error("Could not find app from path " ++ Path)
+ end
+ end.
+
get_name([{h1,_,[Name]}|_], _) when is_binary(Name) ->
Name;
get_name(_, Default) when is_binary(Default) ->
diff --git a/lib/stdlib/test/shell_docs_SUITE.erl b/lib/stdlib/test/shell_docs_SUITE.erl
index 3c163030d4..f3da18ad10 100644
--- a/lib/stdlib/test/shell_docs_SUITE.erl
+++ b/lib/stdlib/test/shell_docs_SUITE.erl
@@ -319,17 +319,16 @@ render_callback(_Config) ->
ok.
render_man(_Config) ->
- Old_ERL_TOP = os:getenv("ERL_TOP"),
- case Old_ERL_TOP of
- false -> os:putenv("ERL_TOP", code:root_dir());
- _ -> ok
- end,
docsmap(
fun(Mod, #docs_v1{metadata = Metadata} = D) ->
try
Path1 = case Metadata of
#{source_path := Path} -> Path;
- #{} -> proplists:get_value(source, proplists:get_value(compile, Mod:module_info()))
+ #{} -> try
+ proplists:get_value(source, proplists:get_value(compile, Mod:module_info()))
+ catch _:_ ->
+ throw({error, no_path_to_source})
+ end
end,
man_docs:module_to_manpage(Mod, Path1, D, "3")
catch _E:R:ST ->
@@ -338,10 +337,6 @@ render_man(_Config) ->
exit(R)
end
end),
- case Old_ERL_TOP of
- false -> os:unsetenv("ERL_TOP");
- _ -> os:putenv("ERL_TOP", Old_ERL_TOP)
- end,
ok.
docsmap(Fun) ->
@@ -365,9 +360,11 @@ docsmap(Fun) ->
try
_ = Fun(Mod, Docs),
{ok, self(), Mod}
- catch E:R:ST ->
- io:format("Failed to render ~p~n~p:~p:~p~n",[Mod,E,R,ST]),
- erlang:raise(E,R,ST)
+ catch throw:{error, no_path_to_source} ->
+ ok;
+ E:R:ST ->
+ io:format("Failed to render ~p~n~p:~p:~p~n",[Mod,E,R,ST]),
+ erlang:raise(E,R,ST)
end
end
end,
--
2.51.0