File 1243-Compiler-new-function-env_compiler_options-0.patch of Package erlang

From 60a13b64316a79edbf830811cdf113311c6547b7 Mon Sep 17 00:00:00 2001
From: alisdair sullivan <alisdairsullivan@yahoo.ca>
Date: Mon, 6 Jun 2016 21:52:14 -0700
Subject: [PATCH 1/2] Compiler: new function env_compiler_options/0

retrieve the value of the environment variable ERL_COMPILER_OPTIONS
in the same manner as used by file/2, forms/2 and output_generated/2
---
 lib/compiler/doc/src/compile.xml    | 17 +++++++++++++++++
 lib/compiler/src/compile.erl        |  9 +++++++++
 lib/compiler/test/compile_SUITE.erl | 22 ++++++++++++++++++++--
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/lib/compiler/doc/src/compile.xml b/lib/compiler/doc/src/compile.xml
index 954750f..0fb0906 100644
--- a/lib/compiler/doc/src/compile.xml
+++ b/lib/compiler/doc/src/compile.xml
@@ -40,6 +40,19 @@
 
   <funcs>
     <func>
+      <name>env_compiler_options()</name>
+      <fsummary>
+	Compiler options defined via the environment variable
+	<c>ERL_COMPILER_OPTIONS</c>
+      </fsummary>
+      <desc>
+	<p>Return compiler options given via the environment variable
+	  <c>ERL_COMPILER_OPTIONS</c>. If the value is a list, it is
+	  returned as is. If it is not a list, it is put into a list.
+	</p>
+      </desc>
+    </func>
+    <func>
       <name>file(File)</name>
       <fsummary>Compiles a file.</fsummary>
       <desc>
@@ -768,6 +781,10 @@ module.beam: module.erl \
       if you do not want the environment variable to be consulted,
       for example, if you are calling the compiler recursively from
       inside a parse transform.</p>
+
+      <p>The list can be retrieved with
+      <seealso marker="#env_compiler_options/0">env_compiler_options/0</seealso>
+      .</p>
   </section>
 
   <section>
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 1490861..82ff8a9 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -26,6 +26,7 @@
 -export([forms/1,forms/2,noenv_forms/2]).
 -export([output_generated/1,noenv_output_generated/1]).
 -export([options/0]).
+-export([env_compiler_options/0]).
 
 %% Erlc interface.
 -export([compile/3,compile_beam/3,compile_asm/3,compile_core/3]).
@@ -120,6 +121,14 @@ noenv_output_generated(Opts) ->
 	end, Passes).
 
 %%
+%% Retrieve ERL_COMPILER_OPTIONS as a list of terms
+%%
+
+-spec env_compiler_options() -> [term()].
+
+env_compiler_options() -> env_default_opts().
+
+%%
 %%  Local functions
 %%
 
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index a15efc2..b0148f7 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -32,7 +32,7 @@
 	 bad_record_use1/1, bad_record_use2/1, strict_record/1,
 	 missing_testheap/1, cover/1, env/1, core/1, asm/1,
 	 sys_pre_attributes/1, dialyzer/1,
-	 warnings/1
+	 warnings/1, env_compiler_options/1
 	]).
 
 -export([init/3]).
@@ -50,7 +50,7 @@ all() ->
      other_output, encrypted_abstr,
      {group, bad_record_use}, strict_record,
      missing_testheap, cover, env, core, asm,
-     sys_pre_attributes, dialyzer, warnings].
+     sys_pre_attributes, dialyzer, warnings, env_compiler_options].
 
 groups() -> 
     [{bad_record_use, [],
@@ -962,6 +963,23 @@ compiler_modules() ->
     do_warnings_1(Next, F).
 
 
+%% Test that ERL_COMPILER_OPTIONS are correctly retrieved
+%% by env_compiler_options/0
+
+env_compiler_options(_Config) ->
+    Cases = [
+        {"bin_opt_info", [bin_opt_info]},
+        {"'S'", ['S']},
+        {"{source, \"test.erl\"}", [{source, "test.erl"}]},
+        {"[{d,macro_one,1},{d,macro_two}]", [{d, macro_one, 1}, {d, macro_two}]},
+        {"[warn_export_all, warn_export_vars]", [warn_export_all, warn_export_vars]}
+    ],
+    F = fun({Env, Expected}) ->
+        true = os:putenv("ERL_COMPILER_OPTIONS", Env),
+        Expected = compile:env_compiler_options()
+    end,
+    lists:foreach(F, Cases).
+
 %%%
 %%% Utilities.
 %%%
-- 
2.1.4

openSUSE Build Service is sponsored by