File 5451-stdlib-Change-missing-doc-file-to-be-a-warning.patch of Package erlang
From b499f9e7d16387683db9c3f16cdb3905e1132efb Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Tue, 4 Jun 2024 09:32:43 +0200
Subject: [PATCH] stdlib: Change missing doc file to be a warning
When we cannot find the documentation file, we issue a warning
instead of error do that compilation can complete anyway. This
so that we don't have to have the docs available when compiling
a file.
---
lib/compiler/test/beam_doc_SUITE.erl | 18 +++++++++++-------
lib/stdlib/src/epp.erl | 6 ++++++
lib/stdlib/test/epp_SUITE.erl | 10 +++++-----
3 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/lib/compiler/test/beam_doc_SUITE.erl b/lib/compiler/test/beam_doc_SUITE.erl
index a44a8bf841..f347274efc 100644
--- a/lib/compiler/test/beam_doc_SUITE.erl
+++ b/lib/compiler/test/beam_doc_SUITE.erl
@@ -524,13 +524,17 @@ doc_with_file(Conf) ->
doc_with_file_error(Conf) ->
ModuleName = ?get_name(),
- {error,
- [{_,
- [{{6,2},epp,{moduledoc,file,"doesnotexist"}},
- {{8,2},epp,{doc,file,"doesnotexist"}},
- {{11,2},epp,{doc,file,"doesnotexist"}}]}] = Errors, []} = default_compile_file(Conf, ModuleName),
- [[Mod:format_error(Error) || {_Loc, Mod, Error} <- Errs] || {_File, Errs} <- Errors],
- {error, _, []} = default_compile_file(Conf, ModuleName, [report]),
+ {ok, _, Warnings} = default_compile_file(Conf, ModuleName, [return_warnings]),
+
+ [{File,
+ [{{6,2},epp,{moduledoc,file,"doesnotexist"}},
+ {{8,2},epp,{doc,file,"doesnotexist"}},
+ {{11,2},epp,{doc,file,"doesnotexist"}}]}] = Warnings,
+
+ ?assertEqual("doc_with_file_error.erl", filename:basename(File)),
+
+ {ok, _} = default_compile_file(Conf, ModuleName, [report]),
+
ok.
all_string_formats(Conf) ->
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index cba9df2483..bde54ea751 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -1232,6 +1232,12 @@ scan_filedoc_content({string, _A, DocFilename}, Dot,
epp_reply(From, {error,{DocLoc,epp,{Doc, file, DocFilename}}}),
wait_req_scan(St)
end;
+ {error, enoent} ->
+ epp_reply(From, {warning,{DocLoc,epp,{Doc, file, DocFilename}}}),
+ epp_reply(From, {ok,
+ [{'-',DocLoc}, {atom, DocLoc, Doc}]
+ ++ [{string, DocLoc, ""}, {dot,DocLoc}]}),
+ wait_req_scan(St);
{error, _} ->
epp_reply(From, {error,{DocLoc,epp,{Doc, file, DocFilename}}}),
wait_req_scan(St)
diff --git a/lib/stdlib/test/epp_SUITE.erl b/lib/stdlib/test/epp_SUITE.erl
index 9a747cb609..84d0d89940 100644
--- a/lib/stdlib/test/epp_SUITE.erl
+++ b/lib/stdlib/test/epp_SUITE.erl
@@ -159,11 +159,11 @@ moduledoc_include(Config) when is_list(Config) ->
{attribute, _, moduledoc, ModuleDoc} = lists:keyfind(moduledoc, 3, List),
?assertEqual({ok, unicode:characters_to_binary(ModuleDoc)}, file:read_file(DocName)),
- %% negative test: checks that we produce an expected error
- ModuleErrContent = binary:replace(ModuleFileContent, <<"README">>, <<"NotExistingFile">>),
- ModuleErrName = CreateFile("module_attr", "moduledoc_err.erl", ModuleErrContent),
- {ok, ListErr} = epp:parse_file(ModuleErrName, []),
- {error,{_,epp,{moduledoc,file, "NotExistingFile.md"}}} = lists:keyfind(error, 1, ListErr),
+ %% negative test: checks that we produce an expected warning
+ ModuleWarnContent = binary:replace(ModuleFileContent, <<"README">>, <<"NotExistingFile">>),
+ ModuleWarnName = CreateFile("module_attr", "moduledoc_err.erl", ModuleWarnContent),
+ {ok, ListWarn} = epp:parse_file(ModuleWarnName, []),
+ {warning,{_,epp,{moduledoc,file, "NotExistingFile.md"}}} = lists:keyfind(warning, 1, ListWarn),
ok.
--
2.35.3