lauromoura pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=77207f9b5855189a4e818ed087f702080afc2068

commit 77207f9b5855189a4e818ed087f702080afc2068
Author: Lauro Moura <lauromo...@expertisesolutions.com.br>
Date:   Thu Nov 7 22:46:15 2019 -0300

    csharp: Fix running headless tests in dotnet
    
    Summary:
    CoreCLR, the runtime of dotnet, has some issues regarding storing
    environment variables (see dotnet/coreclr issue #15812), keeping them in
    a local cache instead of flushing to the native `setenv`.
    
    This commit replaces the usage of
    `System.Environment.SetEnvironmentVariable` with a `setenv` wrapper.
    
    Test Plan: Run without DISPLAY set and with dotnet.
    
    Reviewers: felipealmeida, brunobelo, segfaultxavi, YOhoho
    
    Reviewed By: brunobelo
    
    Subscribers: cedric, #reviewers, #committers
    
    Tags: #efl
    
    Differential Revision: https://phab.enlightenment.org/D10619
---
 src/bindings/mono/efl_mono/meson.build          |  1 +
 src/bindings/mono/eina_mono/eina_common.cs      |  2 +-
 src/bindings/mono/eina_mono/eina_environment.cs | 53 +++++++++++++++++++++++++
 src/bindings/mono/eina_mono/meson.build         |  3 +-
 src/lib/efl_mono/efl_custom_exports_mono.c      | 11 +++++
 src/tests/efl_mono/Main.cs                      | 10 ++++-
 6 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/src/bindings/mono/efl_mono/meson.build 
b/src/bindings/mono/efl_mono/meson.build
index 8bfba319c1..e93d323747 100644
--- a/src/bindings/mono/efl_mono/meson.build
+++ b/src/bindings/mono/efl_mono/meson.build
@@ -41,6 +41,7 @@ if get_option('build-tests')
      mono_friend_assemblies += 'efl_sharp_test_suite'
   else
      mono_friend_assemblies += 'efl_mono_test'
+     mono_friend_assemblies += 'efl-mono-suite'
   endif
 endif
 
diff --git a/src/bindings/mono/eina_mono/eina_common.cs 
b/src/bindings/mono/eina_mono/eina_common.cs
index 9465891998..a4f2ff4c5f 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -31,7 +31,7 @@ internal delegate void EinaFreeCb(IntPtr data);
 
 }
 
-internal static class NativeCustomExportFunctions
+internal static partial class NativeCustomExportFunctions
 {
     [DllImport(efl.Libs.CustomExports)] public static extern void
         efl_mono_native_free(IntPtr ptr);
diff --git a/src/bindings/mono/eina_mono/eina_environment.cs 
b/src/bindings/mono/eina_mono/eina_environment.cs
new file mode 100644
index 0000000000..7cef31cbf1
--- /dev/null
+++ b/src/bindings/mono/eina_mono/eina_environment.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Eina
+{
+
+/// <summary>
+/// Class to deal with native Environment variables.
+///
+/// <para>To be used in place of <see cref="System.Environment" /> methods when
+/// accessing the native environment directly.</para>
+/// <para>Since EFL 1.24.</para>
+/// </summary>
+internal static class Environment
+{
+    /// <summary>
+    /// Returns the value of the environment variable named <c>name</c>.
+    ///
+    /// <para>Since EFL 1.24</para>
+    /// </summary>
+    /// <param name="name">The name of the variable to be retrieved</param>
+    /// <returns>The value of the variable. <c>null</c> if not set.</returns>
+    public static string GetEnv(string name)
+    {
+        return Eina.NativeCustomExportFunctions.efl_mono_native_getenv(name);
+    }
+
+    /// <summary>
+    /// Sets a native environment variable.
+    ///
+    /// <para>Since EFL 1.24</para>
+    /// </summary>
+    /// <param name="name">The name of the variable</param>
+    /// <param name="value">The value to be set.</param>
+    /// <param name="overwrite"><c>true</c> if an existing variable must be 
overwritten.</param>
+    public static void SetEnv(string name, string value, bool overwrite=true)
+    {
+        Eina.Error error = 
Eina.NativeCustomExportFunctions.efl_mono_native_setenv(name, value, overwrite 
? 1 : 0);
+        Eina.Error.Raise(error);
+    }
+}
+
+internal static partial class NativeCustomExportFunctions
+{
+    [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
+    [return: MarshalAs(UnmanagedType.CustomMarshaler, 
MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]
+    public static extern string efl_mono_native_getenv(string name);
+
+    [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
+    public static extern Eina.Error efl_mono_native_setenv(string name, string 
value, int overwrite);
+}
+
+}
\ No newline at end of file
diff --git a/src/bindings/mono/eina_mono/meson.build 
b/src/bindings/mono/eina_mono/meson.build
index 1d9e4e6a43..82c418f399 100644
--- a/src/bindings/mono/eina_mono/meson.build
+++ b/src/bindings/mono/eina_mono/meson.build
@@ -16,5 +16,6 @@ mono_files += files(
   'eina_value.cs',
   'eina_promises.cs',
   'eina_accessor.cs',
-  'eina_strbuf.cs'
+  'eina_strbuf.cs',
+  'eina_environment.cs',
 )
diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c 
b/src/lib/efl_mono/efl_custom_exports_mono.c
index c3e8191e22..ede573f875 100644
--- a/src/lib/efl_mono/efl_custom_exports_mono.c
+++ b/src/lib/efl_mono/efl_custom_exports_mono.c
@@ -202,6 +202,17 @@ EAPI Efl_Substitute_Ctor_Cb 
efl_mono_avoid_top_level_constructor_callback_addr_g
    return &_efl_mono_avoid_top_level_constructor_cb;
 }
 
+// Environment wrappers //
+EAPI const char *efl_mono_native_getenv(const char *name)
+{
+   return getenv(name);
+}
+
+EAPI Eina_Error efl_mono_native_setenv(const char *name, const char *value, 
int overwrite)
+{
+   return setenv(name, value, overwrite);
+}
+
 // Iterator Wrapper //
 
 typedef struct _Eina_Iterator_Wrapper_Mono
diff --git a/src/tests/efl_mono/Main.cs b/src/tests/efl_mono/Main.cs
index 059ad4cf0d..7829cf359f 100644
--- a/src/tests/efl_mono/Main.cs
+++ b/src/tests/efl_mono/Main.cs
@@ -30,8 +30,13 @@ class TestMain
 
     static int Main(string[] args)
     {
-        if (Environment.GetEnvironmentVariable("ELM_ENGINE") == null)
-            Environment.SetEnvironmentVariable("ELM_ENGINE", "buffer");
+        /// We do not use System.Environment due to CoreCLR open issues 
regarding
+        /// setenv modifying the actual C environment. See issue #1592 in 
CoreCLR repo.
+        Eina.Config.Init();
+        if (Eina.Environment.GetEnv("ELM_ENGINE") == null)
+        {
+            Eina.Environment.SetEnv("ELM_ENGINE", "buffer", true);
+        }
 
         Efl.All.Init(Efl.Csharp.Components.Ui);
 
@@ -114,6 +119,7 @@ class TestMain
         Console.WriteLine("[   END SUITE ] " + ckRunSuite);
 
         Efl.All.Shutdown();
+        Eina.Config.Shutdown(); // For the extra init in getenv/setenv above
 
         if (!pass)
           return -1;

-- 


Reply via email to