File 6682-Include-doc-attributes-in-.abstr-files.patch of Package erlang

From 8ddce39008c675d605c908208ff70a82c2322d07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 23 Sep 2025 06:31:05 +0200
Subject: [PATCH] Include doc attributes in .abstr files

When compiling with the `to_abstr` option, the resulting `.abstr`
file would not include documentation attributes. That means that
the BEAM file resulting from the following commands would not
include documentation:

    erlc +to_abstr some_module.erl
    erlc some_module.abstr
---
 lib/compiler/src/compile.erl        | 13 +++++++------
 lib/compiler/test/compile_SUITE.erl | 25 ++++++++++++++++++-------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 7af4c39dd2..1a86bcfb52 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -1656,8 +1656,6 @@ standard_passes() ->
 
      {iff,'dpp',{listing,"pp"}},
      ?pass(lint_module),
-     {unless,no_docs,?pass(beam_docs)},
-     ?pass(remove_doc_attributes),
 
      {iff,'P',{src_listing,"P"}},
      {iff,'to_pp',{done,"P"}},
@@ -1668,12 +1666,15 @@ standard_passes() ->
 
 abstr_passes(AbstrStatus) ->
     case AbstrStatus of
-        non_verified_abstr -> [{unless, no_lint, ?pass(lint_module)},
-                               {unless,no_docs,?pass(beam_docs)},
-                               ?pass(remove_doc_attributes)];
-        verified_abstr -> []
+        non_verified_abstr ->
+            [{unless, no_lint, ?pass(lint_module)}];
+        verified_abstr ->
+            []
     end ++
         [
+         {unless,no_docs,?pass(beam_docs)},
+         ?pass(remove_doc_attributes),
+
          %% Add all -compile() directives to #compile.options
          ?pass(compile_directives),
 
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 3184e0e835..d8adc03552 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -238,7 +238,7 @@ forms_2(Config) when is_list(Config) ->
 
     Src = Simple,
     AbsSrc = filename:absname(Src),
-    {ok,[],SimpleCode} = compile:file(Simple, [dabstr,binary]),
+    {ok,[],SimpleCode} = compile:file(Simple, [to_abstr,binary]),
 
     {ok,simple,Bin1} = compile:forms(SimpleCode, [binary,{source,Src}]),
     {ok,simple,_} = compile:forms(SimpleCode,
@@ -250,7 +250,18 @@ forms_2(Config) when is_list(Config) ->
     %% Load and test that the proper source is returned.
     AbsSrc = forms_load_code(simple, Src, Bin1),
 
-    %% Work in a deleted directory.
+    %% For the rest of this function, compiling will be done in a
+    %% deleted directory (on Unix). See GH-3136. We will need to strip
+    %% the doc chunks because building documentation requires
+    %% determining the absolute path of the module (and that will not
+    %% work in deleted directory).
+
+    SimpleCodeNoDoc = [F || F <- SimpleCode,
+                            element(1, F) =/= attribute orelse element(3, F) =/= doc],
+
+    %% Test that the `to_abstr` option retains the doc attributes.
+    true = SimpleCodeNoDoc =/= SimpleCode,
+
     PrivDir = proplists:get_value(priv_dir, Config),
     WorkDir = filename:join(PrivDir, ?FUNCTION_NAME),
     ok = file:make_dir(WorkDir),
@@ -259,10 +270,10 @@ forms_2(Config) when is_list(Config) ->
 	{unix,_} -> os:cmd("rm -rf " ++ WorkDir);
 	_ -> ok
     end,
-    {ok,simple,Bin2} = compile:forms(SimpleCode),
+    {ok,simple,Bin2} = compile:forms(SimpleCodeNoDoc),
     undefined = forms_load_code(simple, "ignore", Bin2),
 
-    {ok,simple,Bin3} = compile:forms(SimpleCode, [{source,Src},report]),
+    {ok,simple,Bin3} = compile:forms(SimpleCodeNoDoc, [{source,Src},report]),
     case forms_load_code(simple, "ignore", Bin3) of
 	Src ->					%Unix.
 	    ok;
@@ -270,15 +281,15 @@ forms_2(Config) when is_list(Config) ->
 	    ok
     end,
 
-    {ok,simple,Core} = compile:forms(SimpleCode, [to_core0,binary]),
+    {ok,simple,Core} = compile:forms(SimpleCodeNoDoc, [to_core0,binary]),
     forms_compile_and_load(Core, [from_core]),
 
-    {ok,simple,Asm} = compile:forms(SimpleCode, [to_asm,binary]),
+    {ok,simple,Asm} = compile:forms(SimpleCodeNoDoc, [to_asm,binary]),
     forms_compile_and_load(Asm, [from_asm]),
 
     %% The `from_abstr` option is redundant when compiling from forms,
     %% but it should work.
-    forms_compile_and_load(SimpleCode, [from_abstr]),
+    forms_compile_and_load(SimpleCodeNoDoc, [from_abstr]),
 
     %% Cover the error handling code.
     error = compile:forms(bad_core, [from_core,report]),
-- 
2.51.0

openSUSE Build Service is sponsored by