File 0630-Fix-inconsistency-in-defining-FILE-macro.patch of Package erlang

From 1aa9de4f4164708b2ce5f1cafe0b217099648705 Mon Sep 17 00:00:00 2001
From: Per Gustafsson <pergu@fb.com>
Date: Mon, 23 Aug 2021 09:33:51 +0100
Subject: [PATCH] Fix inconsistency in defining ?FILE macro

This happens when the source_name is explicitly defined as an option to epp:parse_file/2. Before an include it got expanded to the actual file name, after an include it was defined as the source_name. With this change it will always be the source_name.

This come up when using --deterministic mode to compile causing the output to be less deterministic if you use the ?FILE macro before any includes.
---
 lib/stdlib/src/epp.erl                        |  3 +--
 lib/stdlib/test/epp_SUITE.erl                 | 21 ++++++++++++++-----
 lib/stdlib/test/epp_SUITE_data/file_macro.erl |  9 ++++++++
 lib/stdlib/test/epp_SUITE_data/file_macro.hrl |  0
 4 files changed, 26 insertions(+), 7 deletions(-)
 create mode 100644 lib/stdlib/test/epp_SUITE_data/file_macro.erl
 create mode 100644 lib/stdlib/test/epp_SUITE_data/file_macro.hrl

diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index 9db34afdad..bf944156fa 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -545,7 +545,7 @@ server(Pid, Name, Options) ->
 init_server(Pid, FileName, Options, St0) ->
     SourceName = proplists:get_value(source_name, Options, FileName),
     Pdm = proplists:get_value(macros, Options, []),
-    Ms0 = predef_macros(FileName),
+    Ms0 = predef_macros(SourceName),
     case user_predef(Pdm, Ms0) of
 	{ok,Ms1} ->
 	    #epp{file = File, location = AtLocation} = St0,
@@ -1820,4 +1820,3 @@ interpret_file_attr([Form0 | Forms], Delta, Fs) ->
     [Form | interpret_file_attr(Forms, Delta, Fs)];
 interpret_file_attr([], _Delta, _Fs) ->
     [].
-
diff --git a/lib/stdlib/test/epp_SUITE.erl b/lib/stdlib/test/epp_SUITE.erl
index 8ec9b7acb8..ae4ca3cd2c 100644
--- a/lib/stdlib/test/epp_SUITE.erl
+++ b/lib/stdlib/test/epp_SUITE.erl
@@ -18,7 +18,7 @@
 %% %CopyrightEnd%
 
 -module(epp_SUITE).
--export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
+-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
 	 init_per_group/2,end_per_group/2]).
 
 -export([rec_1/1, include_local/1, predef_mac/1,
@@ -29,7 +29,7 @@
          otp_8562/1, otp_8665/1, otp_8911/1, otp_10302/1, otp_10820/1,
          otp_11728/1, encoding/1, extends/1,  function_macro/1,
 	 test_error/1, test_warning/1, otp_14285/1,
-	 test_if/1,source_name/1,otp_16978/1]).
+	 test_if/1,source_name/1,otp_16978/1,file_macro/1]).
 
 -export([epp_parse_erl_form/2]).
 
@@ -63,16 +63,16 @@ suite() ->
     [{ct_hooks,[ts_install_cth]},
      {timetrap,{minutes,1}}].
 
-all() -> 
+all() ->
     [rec_1, {group, upcase_mac}, include_local, predef_mac,
      {group, variable}, otp_4870, otp_4871, otp_5362, pmod,
      not_circular, skip_header, otp_6277, otp_7702, otp_8130,
      overload_mac, otp_8388, otp_8470, otp_8562,
      otp_8665, otp_8911, otp_10302, otp_10820, otp_11728,
      encoding, extends, function_macro, test_error, test_warning,
-     otp_14285, test_if, source_name, otp_16978].
+     otp_14285, test_if, source_name, otp_16978, file_macro].
 
-groups() -> 
+groups() ->
     [{upcase_mac, [], [upcase_mac_1, upcase_mac_2]},
      {variable, [], [variable_1]}].
 
@@ -113,6 +113,17 @@ include_local(Config) when is_list(Config) ->
         [ FileLine || {attribute,_,file,FileLine} <- List ],
     ok.
 
+file_macro(Config) when is_list(Config) ->
+    DataDir = proplists:get_value(data_dir, Config),
+    File = filename:join(DataDir, "file_macro.erl"),
+    {ok, List} = epp:parse_file(File, [{includes, [DataDir]},
+                                       {source_name, "Other source"}]),
+    %% Both attribute a and b are defined as ?FILE, they should be the same
+    {attribute,_,a,FileA} = lists:keyfind(a, 3, List),
+    {attribute,_,b,FileB} = lists:keyfind(b, 3, List),
+    "Other source" = FileA = FileB,
+    ok.
+
 %%% Here is a little reimplementation of epp:parse_file, which times out
 %%% after 4 seconds if the epp server doesn't respond. If we use the
 %%% regular epp:parse_file, the test case will time out, and then epp
diff --git a/lib/stdlib/test/epp_SUITE_data/file_macro.erl b/lib/stdlib/test/epp_SUITE_data/file_macro.erl
new file mode 100644
index 0000000000..b30d237363
--- /dev/null
+++ b/lib/stdlib/test/epp_SUITE_data/file_macro.erl
@@ -0,0 +1,9 @@
+-module(file_macro).
+
+-export([]).
+
+-a(?FILE).
+
+-include("file_macro.hrl").
+
+-b(?FILE).
diff --git a/lib/stdlib/test/epp_SUITE_data/file_macro.hrl b/lib/stdlib/test/epp_SUITE_data/file_macro.hrl
new file mode 100644
index 0000000000..e69de29bb2
-- 
2.31.1

openSUSE Build Service is sponsored by