Skip to content

Commit 29124f2

Browse files
committed
Merge branch 'frazze/stdlib/render_man_test_fix' into maint
* frazze/stdlib/render_man_test_fix: stdlib: man_docs no longer depends on ERL_TOP OTP-19787
2 parents b25b4a7 + 4274a4c commit 29124f2

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

lib/stdlib/src/man_docs.erl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,7 @@ markdown_to_manpage(Markdown, Path, Section) ->
6767
markdown_to_manpage1(shell_docs_markdown:parse_md(Markdown), Path, Section).
6868
markdown_to_manpage1(MarkdownChunks, Path, Section) ->
6969
Path1 = filename:absname(Path),
70-
App = case filename:split(string:prefix(Path1, os:getenv("ERL_TOP"))) of
71-
["/", "lib", AppStr | _] ->
72-
list_to_atom(AppStr);
73-
["lib", AppStr | _] ->
74-
list_to_atom(AppStr);
75-
["/", "erts" | _] ->
76-
list_to_atom("erts");
77-
["nomatch"] ->
78-
error("ERL_TOP environment variable doesn't match the PATH " ++ Path)
79-
end,
70+
App = get_app(Path1),
8071
Version = case application:load(App) of
8172
ok -> {ok,Vsn} = application:get_key(App, vsn), Vsn;
8273
{error, {"no such file or directory","erts.app"}} -> erlang:system_info(version);
@@ -91,6 +82,19 @@ markdown_to_manpage1(MarkdownChunks, Path, Section) ->
9182
I = conv(MarkdownChunks, Name),
9283
iolist_to_binary([Prelude|I]).
9384

85+
get_app(Path) ->
86+
case string:split(Path, "/erts/") of
87+
[_, _] -> list_to_atom("erts");
88+
_ -> case string:split(Path, "/lib/") of
89+
[_, Rest] ->
90+
case string:split(Rest, "/") of
91+
[AppStr, _] -> list_to_atom(AppStr);
92+
_ -> error("Could not find app from path " ++ Path)
93+
end;
94+
_ -> error("Could not find app from path " ++ Path)
95+
end
96+
end.
97+
9498
get_name([{h1,_,[Name]}|_], _) when is_binary(Name) ->
9599
Name;
96100
get_name(_, Default) when is_binary(Default) ->

lib/stdlib/test/shell_docs_SUITE.erl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,16 @@ render_callback(_Config) ->
319319
ok.
320320

321321
render_man(_Config) ->
322-
Old_ERL_TOP = os:getenv("ERL_TOP"),
323-
case Old_ERL_TOP of
324-
false -> os:putenv("ERL_TOP", code:root_dir());
325-
_ -> ok
326-
end,
327322
docsmap(
328323
fun(Mod, #docs_v1{metadata = Metadata} = D) ->
329324
try
330325
Path1 = case Metadata of
331326
#{source_path := Path} -> Path;
332-
#{} -> proplists:get_value(source, proplists:get_value(compile, Mod:module_info()))
327+
#{} -> try
328+
proplists:get_value(source, proplists:get_value(compile, Mod:module_info()))
329+
catch _:_ ->
330+
throw({error, no_path_to_source})
331+
end
333332
end,
334333
man_docs:module_to_manpage(Mod, Path1, D, "3")
335334
catch _E:R:ST ->
@@ -338,10 +337,6 @@ render_man(_Config) ->
338337
exit(R)
339338
end
340339
end),
341-
case Old_ERL_TOP of
342-
false -> os:unsetenv("ERL_TOP");
343-
_ -> os:putenv("ERL_TOP", Old_ERL_TOP)
344-
end,
345340
ok.
346341

347342
docsmap(Fun) ->
@@ -365,9 +360,11 @@ docsmap(Fun) ->
365360
try
366361
_ = Fun(Mod, Docs),
367362
{ok, self(), Mod}
368-
catch E:R:ST ->
369-
io:format("Failed to render ~p~n~p:~p:~p~n",[Mod,E,R,ST]),
370-
erlang:raise(E,R,ST)
363+
catch throw:{error, no_path_to_source} ->
364+
ok;
365+
E:R:ST ->
366+
io:format("Failed to render ~p~n~p:~p:~p~n",[Mod,E,R,ST]),
367+
erlang:raise(E,R,ST)
371368
end
372369
end
373370
end,

0 commit comments

Comments
 (0)