File 2454-tools-make-Add-current-directory-to-include-path.patch of Package erlang

From 1a2e7f14aafaac1209458dcedebd4fe723e0f302 Mon Sep 17 00:00:00 2001
From: Siri Hansen <siri@erlang.org>
Date: Wed, 12 Apr 2017 12:35:52 +0200
Subject: [PATCH] [tools/make] Add current directory to include path

This is to ensure that files are recompiled if a .hrl file in the
current directory is changed.
---
 lib/tools/src/make.erl                             |  5 ++-
 lib/tools/test/make_SUITE.erl                      | 44 +++++++++++++++++++---
 .../test/make_SUITE_data/incl_src/test_incl2.erl   |  9 +++++
 lib/tools/test/make_SUITE_data/test_incl.hrl       |  1 +
 lib/tools/test/make_SUITE_data/test_incl1.erl      |  9 +++++
 5 files changed, 60 insertions(+), 8 deletions(-)
 create mode 100644 lib/tools/test/make_SUITE_data/incl_src/test_incl2.erl
 create mode 100644 lib/tools/test/make_SUITE_data/test_incl.hrl
 create mode 100644 lib/tools/test/make_SUITE_data/test_incl1.erl

diff --git a/lib/tools/src/make.erl b/lib/tools/src/make.erl
index 60695febb..0363dee02 100644
--- a/lib/tools/src/make.erl
+++ b/lib/tools/src/make.erl
@@ -290,11 +290,12 @@ coerce_2_list(X) when is_atom(X) ->
 coerce_2_list(X) ->
     X.
 
-%%% If you an include file is found with a modification
+%%% If an include file is found with a modification
 %%% time larger than the modification time of the object
 %%% file, return true. Otherwise return false.
 check_includes(File, IncludePath, ObjMTime) ->
-    Path = [filename:dirname(File)|IncludePath], 
+    {ok,Cwd} = file:get_cwd(),
+    Path = [Cwd,filename:dirname(File)|IncludePath],
     case epp:open(File, Path, []) of
 	{ok, Epp} ->
 	    check_includes2(Epp, File, ObjMTime);
diff --git a/lib/tools/test/make_SUITE.erl b/lib/tools/test/make_SUITE.erl
index 2a94ead32..2db5c6844 100644
--- a/lib/tools/test/make_SUITE.erl
+++ b/lib/tools/test/make_SUITE.erl
@@ -19,11 +19,7 @@
 %%
 -module(make_SUITE).
 
--export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
-         init_per_group/2,end_per_group/2, make_all/1, make_files/1, emake_opts/1]).
--export([otp_6057_init/1,
-         otp_6057_a/1, otp_6057_b/1, otp_6057_c/1,
-         otp_6057_end/1]).
+-compile(export_all).
 
 -include_lib("common_test/include/ct.hrl").
 
@@ -40,7 +36,8 @@
 suite() -> [{ct_hooks,[ts_install_cth]}].
 
 all() -> 
-    [make_all, make_files, emake_opts, {group, otp_6057}].
+    [make_all, make_files, recompile_on_changed_include,
+     emake_opts, {group, otp_6057}].
 
 groups() -> 
     [{otp_6057,[],[otp_6057_a, otp_6057_b,
@@ -86,6 +83,41 @@ make_files(Config) when is_list(Config) ->
     ensure_no_messages(),
     ok.
 
+recompile_on_changed_include(Config) ->
+    Current = prepare_data_dir(Config),
+
+    Files = [test_incl1,"incl_src/test_incl2"],
+    up_to_date = make:files(Files),
+    ok = ensure_exists([test_incl1,test_incl2]),
+
+    {ok, FileInfo11} = file:read_file_info("test_incl1.beam"),
+    Date11 = FileInfo11#file_info.mtime,
+    {ok, FileInfo21} = file:read_file_info("test_incl2.beam"),
+    Date21 = FileInfo21#file_info.mtime,
+    timer:sleep(2000),
+
+    %% Touch the include file
+    {ok,Bin} = file:read_file("test_incl.hrl"),
+    ok = file:delete("test_incl.hrl"),
+    ok = file:write_file("test_incl.hrl",Bin),
+
+    up_to_date = make:files(Files),
+
+    {ok, FileInfo12} = file:read_file_info("test_incl1.beam"),
+    case FileInfo12#file_info.mtime of
+        Date11 -> ct:fail({"file not recompiled", "test_incl1.beam"});
+        _Date12 -> ok
+    end,
+    {ok, FileInfo22} = file:read_file_info("test_incl2.beam"),
+    case FileInfo22#file_info.mtime of
+        Date21 -> ct:fail({"file not recompiled", "test_incl2.beam"});
+        _Date22 -> ok
+    end,
+
+    file:set_cwd(Current),
+    ensure_no_messages(),
+    ok.
+
 emake_opts(Config) when is_list(Config) ->
     Current = prepare_data_dir(Config),
 
diff --git a/lib/tools/test/make_SUITE_data/incl_src/test_incl2.erl b/lib/tools/test/make_SUITE_data/incl_src/test_incl2.erl
new file mode 100644
index 000000000..d0db98c19
--- /dev/null
+++ b/lib/tools/test/make_SUITE_data/incl_src/test_incl2.erl
@@ -0,0 +1,9 @@
+-module(test_incl2).
+-compile(export_all).
+-include("test_incl.hrl").
+
+f1() ->
+    ?d.
+
+f2() ->
+    true.
diff --git a/lib/tools/test/make_SUITE_data/test_incl.hrl b/lib/tools/test/make_SUITE_data/test_incl.hrl
new file mode 100644
index 000000000..3a1bcfadd
--- /dev/null
+++ b/lib/tools/test/make_SUITE_data/test_incl.hrl
@@ -0,0 +1 @@
+-define(d,"defined").
diff --git a/lib/tools/test/make_SUITE_data/test_incl1.erl b/lib/tools/test/make_SUITE_data/test_incl1.erl
new file mode 100644
index 000000000..4a1dd0e73
--- /dev/null
+++ b/lib/tools/test/make_SUITE_data/test_incl1.erl
@@ -0,0 +1,9 @@
+-module(test_incl1).
+-compile(export_all).
+-include("test_incl.hrl").
+
+f1() ->
+    ?d.
+
+f2() ->
+    true.
-- 
2.12.2

openSUSE Build Service is sponsored by