Add managed launcher part
authorpius.lee <pius.lee@samsung.com>
Fri, 19 Aug 2016 04:57:46 +0000 (13:57 +0900)
committerpius.lee <pius.lee@samsung.com>
Fri, 19 Aug 2016 04:57:46 +0000 (13:57 +0900)
Move native launcher part from src to NativeLauncher
Add Tizen.Runtime.dll to Tizen.Runtime
Tizen.Runtime can preload and launching another assembly

18 files changed:
NativeLauncher/CMakeLists.txt [moved from CMakeLists.txt with 92% similarity]
NativeLauncher/dotnet-launcher.ini [moved from packaging/dotnet-launcher.ini with 100% similarity]
NativeLauncher/dotnet.loader [moved from packaging/dotnet.loader with 100% similarity]
NativeLauncher/src/environment.h [moved from src/environment.h with 100% similarity]
NativeLauncher/src/launcher.cc [moved from src/launcher.cc with 100% similarity]
NativeLauncher/src/launcher.h [moved from src/launcher.h with 100% similarity]
NativeLauncher/src/log.h [moved from src/log.h with 100% similarity]
NativeLauncher/src/tini.hpp [moved from src/tini.hpp with 100% similarity]
NativeLauncher/src/waiter.cc [moved from src/waiter.cc with 100% similarity]
NativeLauncher/src/waiter.h [moved from src/waiter.h with 100% similarity]
Tizen.Runtime/Tizen.CoreFX.Ref.Targets [new file with mode: 0644]
Tizen.Runtime/Tizen.Runtime.csproj [new file with mode: 0644]
Tizen.Runtime/Tizen.Runtime.snk [new file with mode: 0644]
Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs [new file with mode: 0644]
Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs [new file with mode: 0644]
Tizen.Runtime/Tizen.Runtime/Log.cs [new file with mode: 0644]
Tizen.Runtime/Tizen.Runtime/test.cs [new file with mode: 0644]
packaging/dotnet-launcher.spec

similarity index 92%
rename from CMakeLists.txt
rename to NativeLauncher/CMakeLists.txt
index 0d49eba..e55c12c 100644 (file)
@@ -50,6 +50,6 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME}
 
 IF(NOT DEFINED NO_TIZEN)
        INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
-       INSTALL(FILES packaging/dotnet.loader DESTINATION ${LOADERDIR})
-       INSTALL(FILES packaging/dotnet-launcher.ini DESTINATION ${CONFIGDIR})
+       INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR})
+       INSTALL(FILES dotnet-launcher.ini DESTINATION ${CONFIGDIR})
 ENDIF(NOT DEFINED NO_TIZEN)
similarity index 100%
rename from src/launcher.h
rename to NativeLauncher/src/launcher.h
similarity index 100%
rename from src/log.h
rename to NativeLauncher/src/log.h
similarity index 100%
rename from src/tini.hpp
rename to NativeLauncher/src/tini.hpp
similarity index 100%
rename from src/waiter.cc
rename to NativeLauncher/src/waiter.cc
similarity index 100%
rename from src/waiter.h
rename to NativeLauncher/src/waiter.h
diff --git a/Tizen.Runtime/Tizen.CoreFX.Ref.Targets b/Tizen.Runtime/Tizen.CoreFX.Ref.Targets
new file mode 100644 (file)
index 0000000..f2484c1
--- /dev/null
@@ -0,0 +1,47 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+       
+       <PropertyGroup>
+               <CoreFXRefPath>/opt/usr/share/tizen.net/ref</CoreFXRefPath>
+               <TizenDeviceAPIPath>/usr/share/assembly</TizenDeviceAPIPath>
+       </PropertyGroup>
+
+       <PropertyGroup>
+               <NoCompilerStandardLib Condition=" '$(NoCompilerStandardLib)' == '' ">true</NoCompilerStandardLib>
+               <NoStdLib Condition=" '$(NoStdLib)' == '' ">true</NoStdLib>
+               <AdditionalLibPaths>$(CoreFXRefPath);$(TizenDeviceAPIPath)</AdditionalLibPaths>
+               <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
+               <!-- Temporary suppress the warning... -->
+               <NoWarn>1701</NoWarn>
+       </PropertyGroup>
+
+       <ItemGroup>
+               <CoreFXRefDir Include="$(CoreFXRefPath)" Condition="Exists('$(CoreFXRefPath)')"/>
+               <CoreFXRefAssemblies Include="@(CoreFXRefDir->'%(FullPath)/*.dll')" Exclude="@(CoreFXRefDir->'%(FullPath)/mscorlib.dll')"/>
+
+               <TizenDeviceAPIDir Include="$(TizenDeviceAPIPath)" Condition="Exists('$(TizenDeviceAPIPath)')"/>
+               <TizenDeviceAPIAssemblies Include="@(TizenDeviceAPIDir->'%(FullPath)/*.dll')"/>
+       </ItemGroup>
+
+       <ItemGroup>
+               <ReferencePath Include="@(CoreFXRefAssemblies->'%(Filename).dll')"/>
+               <ReferencePath Include="@(TizenDeviceAPIAssemblies->'%(Filename).dll')"/>
+       </ItemGroup>
+
+       <Target Name="BeforeBuild">
+               <Message Text="[CoreFX Reference Environment!]"/>
+               <Message Text="CoreFX dir = $(CoreFXRefPath)"/>
+               <Message Text="CoreFX dir Check Ok" Condition="Exists('$(CoreFXRefPath)')"/>
+               <Message Text="Tizen Device API dir = $(TizenDeviceAPIPath)"/>
+               <Message Text="Tizen Device API Check Ok" Condition="Exists('$(TizenDeviceAPIPath)')"/>
+               <Message Text="CoreFXRefDir = @(CoreFXRefDir)"/>
+               <Message Text="TizenDeviceAPIDir = @(TizenDeviceAPIDir)"/>
+               <Message Text="CoreFXRefDir.Identity = %(CoreFXRefDir.Identity)"/>
+               <Message Text="TizenDeviceAPIDir.Identity = %(TizenDeviceAPIDir.Identity)"/>
+               <Message Text="CoreFXRefAssemblies = %(CoreFXRefAssemblies.Identity)"/>
+               <Message Text="TizenDeviceAPIAssemblies = %(TizenDeviceAPIAssemblies.Identity)"/>
+       </Target>
+
+       <PropertyGroup>
+               <CheckConfigDependsOn>CheckEnvironment</CheckConfigDependsOn>
+       </PropertyGroup>
+</Project>
diff --git a/Tizen.Runtime/Tizen.Runtime.csproj b/Tizen.Runtime/Tizen.Runtime.csproj
new file mode 100644 (file)
index 0000000..ffe4d9c
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project InitialTargets="CheckConfig" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+       
+       <PropertyGroup>
+               <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <OutputType>Library</OutputType>
+               <AssemblyName>Tizen.Runtime</AssemblyName>
+       </PropertyGroup>
+
+       <PropertyGroup Condition=" '$(Configuration)' == 'Debug'">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+               <OutputPath>bin/</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+       </PropertyGroup>
+
+       <PropertyGroup Condition=" '$(Configuration)' == 'Release'">
+               <DebugType>pdbonly</DebugType>
+               <Optimize>true</Optimize>
+               <OutputPath>bin/</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+       </PropertyGroup>
+
+       <PropertyGroup>
+               <SignAssembly>true</SignAssembly>
+               <AssemblyOriginatorKeyFile>Tizen.Runtime.snk</AssemblyOriginatorKeyFile>
+       </PropertyGroup>
+
+       <ItemGroup>
+               <Compile Include="Tizen.Runtime/AssemblyLoader.cs" />
+               <Compile Include="Tizen.Runtime/Log.cs" />
+               <Compile Include="Tizen.Runtime/AssemblyManager.cs" />
+       </ItemGroup>
+
+       <Target Name="CheckConfig">
+               <Message Text="MSBuildProjectDirectory = $(MSBuildProjectDirectory)"/>
+       </Target>
+
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+       <Import Project="$(MSBuildProjectDirectory)/Tizen.CoreFX.Ref.Targets" />
+</Project>
diff --git a/Tizen.Runtime/Tizen.Runtime.snk b/Tizen.Runtime/Tizen.Runtime.snk
new file mode 100644 (file)
index 0000000..758e318
Binary files /dev/null and b/Tizen.Runtime/Tizen.Runtime.snk differ
diff --git a/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs b/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs
new file mode 100644 (file)
index 0000000..e959146
--- /dev/null
@@ -0,0 +1,45 @@
+using System;
+using System.IO;
+using System.Reflection;
+using System.Runtime.Loader;
+using System.Collections.Generic;
+
+namespace Tizen.Runtime
+{
+    public class AssemblyLoader : AssemblyLoadContext
+    {
+        private SortedSet<string> _dllDirectories = new SortedSet<string>();
+        public IEnumerable<string> DllDirectories
+        {
+            get { return _dllDirectories; }
+        }
+
+        public void AddSearchableDirectory(string directory)
+        {
+            if (Directory.Exists(directory))
+            {
+                _dllDirectories.Add(directory);
+            }
+        }
+
+        public void RemoveSearchableDirectory(string directory)
+        {
+            _dllDirectories.Remove(directory);
+        }
+
+        protected override Assembly Load(AssemblyName assemblyName)
+        {
+            ALog.Debug($"Load!! : {assemblyName.Name}");
+            foreach (string dir in DllDirectories)
+            {
+                FileInfo f = new FileInfo(Path.Combine(dir, $"{assemblyName.Name}.dll"));
+                ALog.Debug(f.FullName);
+                if (File.Exists(f.FullName))
+                {
+                    return LoadFromAssemblyPath(f.FullName);
+                }
+            }
+            return Assembly.Load(assemblyName);
+        }
+    }
+}
diff --git a/Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs
new file mode 100644 (file)
index 0000000..f7a7810
--- /dev/null
@@ -0,0 +1,87 @@
+using System;
+using System.IO;
+using System.Reflection;
+using System.Runtime.Loader;
+
+namespace Tizen.Runtime
+{
+    public static class AssemblyManager
+    {
+        private static void PrintException(Exception exception)
+        {
+            while (exception != null)
+            {
+                ALog.Debug(exception.Message);
+                ALog.Debug(exception.StackTrace);
+                exception = exception.InnerException;
+            }
+        }
+
+        public static AssemblyLoader CurrentAssemblyLoaderContext
+        {
+            get;
+            private set;
+        }
+
+        public static bool Initialize(string searchableDirectories, string preloadDllPaths)
+        {
+            try
+            {
+                CurrentAssemblyLoaderContext = new AssemblyLoader();
+
+                if (searchableDirectories != null)
+                {
+                    string[] dirs = searchableDirectories.Split(':');
+                    foreach (string dir in dirs)
+                    {
+                        CurrentAssemblyLoaderContext.AddSearchableDirectory(dir);
+                    }
+                }
+
+                if (preloadDllPaths != null)
+                {
+                    string[] dllPaths = preloadDllPaths.Split(':');
+                    foreach (string dllPath in dllPaths)
+                    {
+                        FileInfo f = new FileInfo(dllPath);
+                        if (File.Exists(f.FullName))
+                        {
+                            CurrentAssemblyLoaderContext.LoadFromAssemblyPath(f.FullName);
+                        }
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                ALog.Debug("Exception on Initialized");
+                PrintException(e);
+                return false;
+            }
+            return true;
+        }
+
+        public static void Execute(string dllPath)
+        {
+            try
+            {
+                FileInfo f = new FileInfo(dllPath);
+                if (File.Exists(f.FullName))
+                {
+                    Assembly asm = CurrentAssemblyLoaderContext.LoadFromAssemblyPath(f.FullName);
+                    if (asm == null) throw new FileNotFoundException($"{f.FullName} is not found");
+                    if (asm.EntryPoint == null) throw new ArgumentException($"{f.FullName} did not have EntryPoint");
+                    asm.EntryPoint.Invoke(null, new string[]{null});
+                }
+            }
+            catch (Exception e)
+            {
+                ALog.Debug("Exception on Execute");
+                PrintException(e);
+            }
+        }
+
+        public static void Finish()
+        {
+        }
+    }
+}
diff --git a/Tizen.Runtime/Tizen.Runtime/Log.cs b/Tizen.Runtime/Tizen.Runtime/Log.cs
new file mode 100644 (file)
index 0000000..064a5f3
--- /dev/null
@@ -0,0 +1,55 @@
+using System;
+#if !CLOG
+using Tizen;
+#endif
+
+namespace Tizen.Runtime
+{
+#if CLOG
+    internal static class Log
+    {
+        static void Print(string tag, string message)
+        {
+            string[] lines = message.Split('\r');
+            foreach (string line in lines)
+            {
+                Console.WriteLine($"{tag} : {message}");
+            }
+        }
+
+        public static void Debug(string tag, string message)
+        {
+            Print($"D/{tag}", message);
+        }
+
+        public static void Info(string tag, string message)
+        {
+            Print($"I/{tag}", message);
+        }
+
+        public static void Error(string tag, string message)
+        {
+            Print($"E/{tag}", message);
+        }
+    }
+#endif
+    internal static class ALog
+    {
+        static string TAG = "Tizen.Runtime";
+
+        public static void Debug(string message)
+        {
+            Log.Debug(TAG, message);
+        }
+
+        public static void Info(string message)
+        {
+            Log.Info(TAG, message);
+        }
+
+        public static void Error(string message)
+        {
+            Log.Error(TAG, message);
+        }
+    }
+}
diff --git a/Tizen.Runtime/Tizen.Runtime/test.cs b/Tizen.Runtime/Tizen.Runtime/test.cs
new file mode 100644 (file)
index 0000000..1c65dbe
--- /dev/null
@@ -0,0 +1,21 @@
+using Tizen.Runtime;
+
+public class Program
+{
+    public static void Main(string[] args)
+    {
+        if (args.Length < 2)
+        {
+            ALog.Debug("Cancel..");
+            return;
+        }
+        string preload = Environment.GetEnvironmentVariable("PRELOAD_DLLS");
+        string searchable = String.Join(":", args, 1, args.Length - 1);
+
+        if (AssemblyManager.Initialize(searchable, preload))
+        {
+            ALog.Debug("After Initialized...");
+            AssemblyManager.Execute(args[0]);
+        }
+    }
+}
index 2bbc40a..353ab99 100644 (file)
@@ -13,6 +13,10 @@ BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(ecore)
 BuildRequires: pkgconfig(launchpad)
 BuildRequires: aul-devel
+BuildRequires: corefx-managed-32b-ref
+BuildRequires: mono-compiler
+BuildRequires: mono-devel 
+BuildRequires: csapi-tizen 
 Requires: aul
 
 Requires(post): /sbin/ldconfig
@@ -43,16 +47,21 @@ cmake \
        -DLOADERDIR=%{_loaderdir} \
        -DCONFIGDIR=%{_configdir} \
        -DCMAKE_BUILD_TYPE=%{_buildmode} \
-       -DVERSION=%{version}
+       -DVERSION=%{version} \
+       NativeLauncher
 
 make %{?jobs:-j%jobs}
 
+xbuild /p:Configuration=%{_buildmode} Tizen.Runtime/Tizen.Runtime.csproj
+
 %install
 rm -rf %{buildroot}
 %make_install
+install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.dll %{buildroot}%{_bindir}
 
 %files
 %manifest dotnet-launcher.manifest
 %config /etc/dotnet-launcher.ini
 %{_loaderdir}/dotnet.loader
 %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher
+%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.dll