From fc48672564f10d25b3dfcd2f42cdb38b7deb6951 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Fri, 19 Aug 2016 13:57:46 +0900 Subject: [PATCH] Add managed launcher part Move native launcher part from src to NativeLauncher Add Tizen.Runtime.dll to Tizen.Runtime Tizen.Runtime can preload and launching another assembly --- CMakeLists.txt => NativeLauncher/CMakeLists.txt | 4 +- {packaging => NativeLauncher}/dotnet-launcher.ini | 0 {packaging => NativeLauncher}/dotnet.loader | 0 {src => NativeLauncher/src}/environment.h | 0 {src => NativeLauncher/src}/launcher.cc | 0 {src => NativeLauncher/src}/launcher.h | 0 {src => NativeLauncher/src}/log.h | 0 {src => NativeLauncher/src}/tini.hpp | 0 {src => NativeLauncher/src}/waiter.cc | 0 {src => NativeLauncher/src}/waiter.h | 0 Tizen.Runtime/Tizen.CoreFX.Ref.Targets | 47 ++++++++++++ Tizen.Runtime/Tizen.Runtime.csproj | 42 +++++++++++ Tizen.Runtime/Tizen.Runtime.snk | Bin 0 -> 596 bytes Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs | 45 +++++++++++ Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs | 87 ++++++++++++++++++++++ Tizen.Runtime/Tizen.Runtime/Log.cs | 55 ++++++++++++++ Tizen.Runtime/Tizen.Runtime/test.cs | 21 ++++++ packaging/dotnet-launcher.spec | 11 ++- 18 files changed, 309 insertions(+), 3 deletions(-) rename CMakeLists.txt => NativeLauncher/CMakeLists.txt (92%) rename {packaging => NativeLauncher}/dotnet-launcher.ini (100%) rename {packaging => NativeLauncher}/dotnet.loader (100%) rename {src => NativeLauncher/src}/environment.h (100%) rename {src => NativeLauncher/src}/launcher.cc (100%) rename {src => NativeLauncher/src}/launcher.h (100%) rename {src => NativeLauncher/src}/log.h (100%) rename {src => NativeLauncher/src}/tini.hpp (100%) rename {src => NativeLauncher/src}/waiter.cc (100%) rename {src => NativeLauncher/src}/waiter.h (100%) create mode 100644 Tizen.Runtime/Tizen.CoreFX.Ref.Targets create mode 100644 Tizen.Runtime/Tizen.Runtime.csproj create mode 100644 Tizen.Runtime/Tizen.Runtime.snk create mode 100644 Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs create mode 100644 Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs create mode 100644 Tizen.Runtime/Tizen.Runtime/Log.cs create mode 100644 Tizen.Runtime/Tizen.Runtime/test.cs diff --git a/CMakeLists.txt b/NativeLauncher/CMakeLists.txt similarity index 92% rename from CMakeLists.txt rename to NativeLauncher/CMakeLists.txt index 0d49eba..e55c12c 100644 --- a/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -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) diff --git a/packaging/dotnet-launcher.ini b/NativeLauncher/dotnet-launcher.ini similarity index 100% rename from packaging/dotnet-launcher.ini rename to NativeLauncher/dotnet-launcher.ini diff --git a/packaging/dotnet.loader b/NativeLauncher/dotnet.loader similarity index 100% rename from packaging/dotnet.loader rename to NativeLauncher/dotnet.loader diff --git a/src/environment.h b/NativeLauncher/src/environment.h similarity index 100% rename from src/environment.h rename to NativeLauncher/src/environment.h diff --git a/src/launcher.cc b/NativeLauncher/src/launcher.cc similarity index 100% rename from src/launcher.cc rename to NativeLauncher/src/launcher.cc diff --git a/src/launcher.h b/NativeLauncher/src/launcher.h similarity index 100% rename from src/launcher.h rename to NativeLauncher/src/launcher.h diff --git a/src/log.h b/NativeLauncher/src/log.h similarity index 100% rename from src/log.h rename to NativeLauncher/src/log.h diff --git a/src/tini.hpp b/NativeLauncher/src/tini.hpp similarity index 100% rename from src/tini.hpp rename to NativeLauncher/src/tini.hpp diff --git a/src/waiter.cc b/NativeLauncher/src/waiter.cc similarity index 100% rename from src/waiter.cc rename to NativeLauncher/src/waiter.cc diff --git a/src/waiter.h b/NativeLauncher/src/waiter.h 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 index 0000000..f2484c1 --- /dev/null +++ b/Tizen.Runtime/Tizen.CoreFX.Ref.Targets @@ -0,0 +1,47 @@ + + + + /opt/usr/share/tizen.net/ref + /usr/share/assembly + + + + true + true + $(CoreFXRefPath);$(TizenDeviceAPIPath) + false + + 1701 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CheckEnvironment + + diff --git a/Tizen.Runtime/Tizen.Runtime.csproj b/Tizen.Runtime/Tizen.Runtime.csproj new file mode 100644 index 0000000..ffe4d9c --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime.csproj @@ -0,0 +1,42 @@ + + + + + Debug + AnyCPU + Library + Tizen.Runtime + + + + true + full + bin/ + DEBUG;TRACE + + + + pdbonly + true + bin/ + TRACE + + + + true + Tizen.Runtime.snk + + + + + + + + + + + + + + + diff --git a/Tizen.Runtime/Tizen.Runtime.snk b/Tizen.Runtime/Tizen.Runtime.snk new file mode 100644 index 0000000000000000000000000000000000000000..758e318500f30ebdcdb6b05b2019411bde1962cd GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONaL0002(DGq5;*iDNmD`i!-W57Gx1KS<*(EK%3 zW@B-ZpEPiJ0fkn2_41G@5}84M{UB8~_RT4uZL3`+#TA8&{$_d&u>Cb>&i6riJ-$y6 zuB_`PSeaKUOC)MY%xjZE{2`Isnfaoi?2(H)pBE z1Xh7WLmh?%QqZWwun;}Hx8_jq>#heY*CApiQ7I;cFK6G8`TMr8Z3sO>Wwq|_K-Z%s z;P2$CvTD;C!#sg|0ZrX&h=RkOfW+@t$YU^?)jC{*p+dsOx(-o({!dOjgKh^tw<7&{ z^sgy+GVAnmKDer~rk7Zm#LdH!jI)4Kj{d`zc1@zij|;CUgc zs)cT0>q!UX)fhEr+O7o*w=R?B2l~UYrKC^NL#vc1x}(U-r^19lSv0>Kgc^?*0drAG z7}{#(d}nE8Q=U!@B$^Uvm?guBL0Go+c|JBw)sYMoiSvhE_YrZ`zgZ~WT0o17&E=O# zQU}2^(7;Ny6{||(84$e=!b`svpBzxi!3l+3z973d2fNf63|P8FJ^+P5Ct)SfYrPww iv5YkYXx%r{i2|mh%@}r=NcYwqzM-MA>ezNiWlm;6r57*& literal 0 HcmV?d00001 diff --git a/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs b/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs new file mode 100644 index 0000000..e959146 --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs @@ -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 _dllDirectories = new SortedSet(); + public IEnumerable 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 index 0000000..f7a7810 --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs @@ -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 index 0000000..064a5f3 --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime/Log.cs @@ -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 index 0000000..1c65dbe --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime/test.cs @@ -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]); + } + } +} diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 2bbc40a..353ab99 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -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 -- 2.7.4