Add Dotnet.Launcher.Environment.SetEnvironmentVariable wrapper for System.Environment...
authorGleb Balykov <g.balykov@samsung.com>
Tue, 25 Jun 2019 09:56:38 +0000 (12:56 +0300)
committerGleb Balykov <g.balykov@samsung.com>
Wed, 3 Jul 2019 09:01:30 +0000 (12:01 +0300)
Managed/Dotnet.Launcher.cs [new file with mode: 0644]
Managed/Dotnet.Launcher.csproj [new file with mode: 0644]
NativeLauncher/inc/coreclr_host.h
NativeLauncher/launcher/dotnet/dotnet_launcher.cc
packaging/dotnet-launcher.spec

diff --git a/Managed/Dotnet.Launcher.cs b/Managed/Dotnet.Launcher.cs
new file mode 100644 (file)
index 0000000..8beccdd
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Dotnet.Launcher
+{
+    class Environment
+    {
+        public static void SetEnvironmentVariable(string variable, string value)
+        {
+            System.Environment.SetEnvironmentVariable(variable, value);
+        }
+    }
+}
diff --git a/Managed/Dotnet.Launcher.csproj b/Managed/Dotnet.Launcher.csproj
new file mode 100644 (file)
index 0000000..e5fed71
--- /dev/null
@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+    <PropertyGroup>
+           <TargetFramework>netcoreapp2.1</TargetFramework>
+           <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
+           <NoWin32Manifest>True</NoWin32Manifest>
+           <Configuration>Release</Configuration>
+    </PropertyGroup>
+
+</Project>
index 3b96d6c..6a795ee 100644 (file)
@@ -48,8 +48,8 @@ extern "C"
                        const char* entryPointMethodName,
                        void** delegate);
 
-       typedef bool (*set_environment_variable_ptr)(const char16_t* name,
-                       const char16_t* value);
+       typedef bool (*set_environment_variable_ptr)(const char* name,
+                       const char* value);
 
        typedef int (*multi_byte_to_wide_char_ptr)(
                        unsigned int CodePage,
index 8ad60ed..16d3fd6 100644 (file)
@@ -221,12 +221,6 @@ static void initEnvForSpecialFolder()
        }
 }
 
-static std::u16string utf8ToUtf16(char* str)
-{
-       std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
-       return convert.from_bytes(str);
-}
-
 void CoreRuntime::preloadTypes()
 {
        const static std::string initDllPath = "/usr/share/dotnet.tizen/framework/Tizen.Init.dll";
@@ -376,7 +370,6 @@ int CoreRuntime::initialize(bool standalone)
        CORELIB_RETURN_IF_NOSYM(coreclr_execute_assembly_ptr, executeAssembly, "coreclr_execute_assembly");
        CORELIB_RETURN_IF_NOSYM(coreclr_shutdown_ptr, shutdown, "coreclr_shutdown");
        CORELIB_RETURN_IF_NOSYM(coreclr_create_delegate_ptr, createDelegate, "coreclr_create_delegate");
-       CORELIB_RETURN_IF_NOSYM(set_environment_variable_ptr, setEnvironmentVariable, "SetEnvironmentVariableW");
 
 #undef CORELIB_RETURN_IF_NOSYM
 
@@ -401,6 +394,12 @@ int CoreRuntime::initialize(bool standalone)
                return -1;
        }
 
+       int st = createDelegate(__hostHandle, __domainId, "Dotnet.Launcher", "Dotnet.Launcher.Environment", "SetEnvironmentVariable", (void**)&setEnvironmentVariable);
+       if (st < 0 || setEnvironmentVariable == nullptr) {
+               _ERR("Create delegate for Dotnet.Launcher.dll -> Dotnet.Launcher.Environment -> SetEnvironmentVariable failed (0x%08x)", st);
+               return -1;
+       }
+
        __initialized = true;
 
        if (!standalone)
@@ -527,12 +526,7 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
        // application data path can be changed by owner. So, we have to set data path just before launching.
        char* localDataPath = app_get_data_path();
        if (localDataPath != nullptr) {
-               std::u16string envval = utf8ToUtf16(localDataPath);
-
-               if (!setEnvironmentVariable(u"XDG_DATA_HOME", envval.c_str())) {
-                       _ERR("Failed to set XDG_DATA_HOME");
-               }
-
+               setEnvironmentVariable("XDG_DATA_HOME", localDataPath);
                free(localDataPath);
        }
 
index 41a5138..40f11a9 100644 (file)
@@ -87,6 +87,10 @@ dotnet msbuild Init/Tizen.Init.csproj /t:clean
 dotnet msbuild Init/Tizen.Init.csproj /t:restore /p:RestoreSources=/nuget
 dotnet msbuild Init/Tizen.Init.csproj
 
+dotnet msbuild Managed/Dotnet.Launcher.csproj /t:clean
+dotnet msbuild Managed/Dotnet.Launcher.csproj /t:restore /p:RestoreSources=/nuget
+dotnet msbuild Managed/Dotnet.Launcher.csproj
+
 cmake \
        -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 %if 0%{?asan_enabled}
@@ -115,6 +119,7 @@ rm -rf %{buildroot}
 %make_install
 mkdir -p %{buildroot}%{_framework_dir}
 mv Init/bin/Release/Tizen.Init.dll %{buildroot}%{_framework_dir}
+mv Managed/bin/Release/Dotnet.Launcher.dll %{buildroot}%{_framework_dir}
 
 
 mkdir -p %{buildroot}%{_tac_dir}
@@ -146,6 +151,7 @@ chsmack -t -a User::App::Shared /opt/etc/skel/.dotnet
 /etc/tmpfiles.d/%{name}.conf
 /usr/share/parser-plugins/dotnet-launcher.info
 %{_framework_dir}/Tizen.Init.dll
+%{_framework_dir}/Dotnet.Launcher.dll
 %{_tac_dir}
 
 %files devel
@@ -157,4 +163,3 @@ chsmack -t -a User::App::Shared /opt/etc/skel/.dotnet
 %{_libdir}/libdotnet_launcher_util.so
 %{_libdir}/libni_common.so
 %{_libdir}/pkgconfig/dotnet-launcher.pc
-