diff options
author | JongHeon Choi <j-h.choi@samsung.com> | 2017-03-30 13:40:14 +0900 |
---|---|---|
committer | JongHeon Choi <j-h.choi@samsung.com> | 2017-04-07 09:18:42 +0900 |
commit | bd5c5f3430720a35e67306bab83e9903bb4803de (patch) | |
tree | fc6054312067304866a50961f0ee84b3b450c15f | |
parent | 79b355e6ffe71ac43b9c052549351815b1627fe7 (diff) | |
download | launcher-bd5c5f3430720a35e67306bab83e9903bb4803de.tar.gz launcher-bd5c5f3430720a35e67306bab83e9903bb4803de.tar.bz2 launcher-bd5c5f3430720a35e67306bab83e9903bb4803de.zip |
Remove the Mono profile
Change-Id: If5ce5c0b76d626cfd38cfe607f20b277909f32db
-rwxr-xr-x | NativeLauncher/CMakeLists.txt | 5 | ||||
-rw-r--r-- | NativeLauncher/launcher/main.cc | 22 | ||||
-rw-r--r-- | NativeLauncher/launcher/mono/mono_launcher.cc | 264 | ||||
-rw-r--r-- | NativeLauncher/launcher/mono/mono_launcher.h | 98 | ||||
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | Tizen.Runtime/Tizen.Runtime.Mono.csproj | 75 | ||||
-rw-r--r-- | Tizen.Runtime/Tizen.Runtime.Mono.project.json | 11 | ||||
-rw-r--r-- | Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs | 169 | ||||
-rwxr-xr-x | packaging/dotnet-launcher.spec | 9 |
9 files changed, 12 insertions, 659 deletions
diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 6799712..0d4e53b 100755 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -22,10 +22,6 @@ IF(DEFINED CORECLR_LAUNCHER_ASSEMBLY_PATH) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DCORECLR_LAUNCHER_ASSEMBLY_PATH=${CORECLR_LAUNCHER_ASSEMBLY_PATH}") ENDIF(DEFINED CORECLR_LAUNCHER_ASSEMBLY_PATH) -IF(DEFINED MONO_LAUNCHER_ASSEMBLY_PATH) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DMONO_LAUNCHER_ASSEMBLY_PATH=${MONO_LAUNCHER_ASSEMBLY_PATH}") -ENDIF(DEFINED MONO_LAUNCHER_ASSEMBLY_PATH) - IF(DEFINED DEVICE_API_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DDEVICE_API_DIR=${DEVICE_API_DIR}") ENDIF(DEFINED DEVICE_API_DIR) @@ -65,7 +61,6 @@ SET(${DOTNET_LAUNCHER}_SOURCE_FILES util/utils.cc launcher/launcher.cc launcher/dotnet/dotnet_launcher.cc - launcher/mono/mono_launcher.cc ) ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${DOTNET_LAUNCHER}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER} PROPERTIES COMPILE_FLAGS "-fPIE") diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 5c1ba49..c39b3e8 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -15,7 +15,6 @@ */ #include "dotnet/dotnet_launcher.h" -#include "mono/mono_launcher.h" #include "utils.h" #include "log.h" @@ -90,24 +89,9 @@ int main(int argc, char *argv[]) using tizen::runtime::AppInfo; std::unique_ptr<LauncherInterface> runtime; - bool useMono = !FileNotExist("/etc/.use_mono"); - - if (!useMono) - { - using tizen::runtime::dotnetcore::CoreRuntime; - std::unique_ptr<LauncherInterface> coreRuntime(new CoreRuntime()); - runtime = std::move(coreRuntime); - - _DBG("##### CoreCLR Launcher ######"); - } - else - { - using tizen::runtime::mono::MonoRuntime; - std::unique_ptr<LauncherInterface> monoRuntime(new MonoRuntime()); - runtime = std::move(monoRuntime); - - _DBG("##### Mono Launcher ######"); - } + using tizen::runtime::dotnetcore::CoreRuntime; + std::unique_ptr<LauncherInterface> coreRuntime(new CoreRuntime()); + runtime = std::move(coreRuntime); if (standalone) { diff --git a/NativeLauncher/launcher/mono/mono_launcher.cc b/NativeLauncher/launcher/mono/mono_launcher.cc deleted file mode 100644 index 97813b3..0000000 --- a/NativeLauncher/launcher/mono/mono_launcher.cc +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2016 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. - */ - - -#include "mono_launcher.h" -#include "utils.h" -#include "log.h" - -#include <dlfcn.h> -#include <string> - -namespace tizen { -namespace runtime { -namespace mono { - -static const char* DOMAIN_NAME = "tizen_mono_domain"; -static const char* LIBMONO = "/usr/lib/libmono-2.0.so.1"; - -MonoRuntime::MonoRuntime() : - monolib(nullptr), - domain(nullptr), - launch(nullptr) -{ - -#define __XSTR(x) #x -#define __STR(x) __XSTR(x) - -#ifdef MONO_LAUNCHER_ASSEMBLY_PATH - launcherAssemblyPath = __STR(MONO_LAUNCHER_ASSEMBLY_PATH); -#endif - -#ifdef DEVICE_API_DIR - deviceAPIDirectory = __STR(DEVICE_API_DIR); -#endif -#ifdef RUNTIME_DIR - runtimeDirectory = __STR(RUNTIME_DIR); -#endif - -#undef __STR -#undef __XSTR -} - -MonoRuntime::~MonoRuntime() -{ - Dispose(); -} - -int MonoRuntime::Initialize(bool standalone) -{ - if (standalone) - { - const char *_deviceapi_directory = getenv("DeviceAPIDirectory"); - const char *_runtime_directory = getenv("RuntimeDirectory"); - const char *_launcher_assembly = getenv("LauncherAssembly"); - if (_deviceapi_directory != nullptr) - deviceAPIDirectory = _deviceapi_directory; - if (_runtime_directory != nullptr) - runtimeDirectory = _runtime_directory; - if (_launcher_assembly != nullptr) - launcherAssemblyPath = _launcher_assembly; - } - - if (FileNotExist(LIBMONO)) - { - _DBG("mono is not exist in %s", LIBMONO); - return 1; - } - - monolib = dlopen(LIBMONO, RTLD_LAZY); -#define MONOLIB_RETURN_IF_NOSYM(type, variable, name) \ - do { \ - variable = (type)dlsym(monolib, name); \ - if (variable == nullptr) { \ - _ERR(name " is not found in libmono"); \ - return 1; \ - }} while(0) - - MONOLIB_RETURN_IF_NOSYM(mono_set_dirs_ptr, SetDirs, "mono_set_dirs"); - MONOLIB_RETURN_IF_NOSYM(mono_set_assemblies_path_ptr, SetAssembliesPath, "mono_set_assemblies_path"); - MONOLIB_RETURN_IF_NOSYM(mono_jit_init_ptr, JitInit, "mono_jit_init"); - MONOLIB_RETURN_IF_NOSYM(mono_domain_assembly_open_ptr, DomainAssemblyOpen, "mono_domain_assembly_open"); - MONOLIB_RETURN_IF_NOSYM(mono_assembly_get_image_ptr, AssemblyGetImage, "mono_assembly_get_image"); - MONOLIB_RETURN_IF_NOSYM(mono_class_from_name_ptr, ClassFromName, "mono_class_from_name"); - MONOLIB_RETURN_IF_NOSYM(mono_runtime_invoke_ptr, RuntimeInvoke, "mono_runtime_invoke"); - MONOLIB_RETURN_IF_NOSYM(mono_class_get_method_from_name_ptr, ClassGetMethodFromName, "mono_class_get_method_from_name"); - MONOLIB_RETURN_IF_NOSYM(mono_object_to_string_ptr, ObjectToString, "mono_object_to_string"); - MONOLIB_RETURN_IF_NOSYM(mono_string_to_utf8_ptr, StringToUtf8, "mono_string_to_utf8"); - MONOLIB_RETURN_IF_NOSYM(mono_string_new_ptr, NewString, "mono_string_new"); - MONOLIB_RETURN_IF_NOSYM(mono_get_string_class_ptr, GetStringClass, "mono_get_string_class"); - MONOLIB_RETURN_IF_NOSYM(mono_array_new_ptr, ArrayNew, "mono_array_new"); - MONOLIB_RETURN_IF_NOSYM(mono_array_addr_with_size_ptr, ArrayAddrWithSize, "mono_array_addr_with_size"); - MONOLIB_RETURN_IF_NOSYM(mono_jit_cleanup_ptr, DomainCleanup, "mono_jit_cleanup"); - MONOLIB_RETURN_IF_NOSYM(mono_jit_exec_ptr, AssemblyExec, "mono_jit_exec"); - -#undef MONOLIB_RETURN_IF_NOSYM - - _DBG("libmono dlopen and dlsym success"); - - return 0; -} - -void MonoRuntime::Dispose() -{ - if (domain != nullptr) - { - DomainCleanup(domain); - } - if (monolib != nullptr && dlclose(monolib) != 0) - { - _ERR("libmono close failed"); - } - monolib = nullptr; -} - -int MonoRuntime::RunManagedLauncher() -{ - if (FileNotExist(launcherAssemblyPath.c_str())) - { - _ERR("Launcher Assembly is not exist in %s", launcherAssemblyPath.c_str()); - return 1; - } - -// _DBG("mono_set_dirs(\"%s\", nullptr);", runtimeDirectory.c_str()); -// _DBG("mono_set_assemblies_path(\"%s\");", deviceAPIDirectory.c_str()); - -// SetDirs(runtimeDirectory.c_str(), nullptr); -/* - std::string assembliesPath = runtimeDirectory+":"+deviceAPIDirectory; - _DBG("assembliesPath : %s", assembliesPath.c_str()); - SetAssembliesPath(assembliesPath.c_str()); - */ - SetAssembliesPath(deviceAPIDirectory.c_str()); - - domain = JitInit(DOMAIN_NAME); - if (domain == nullptr) - { - _ERR("Failed to init mono jit"); - return 1; - } - - launcherAssembly = DomainAssemblyOpen(domain, launcherAssemblyPath.c_str()); - if (launcherAssembly == nullptr) - { - _ERR("Failed to Load Launcher Assembly"); - return 1; - } - - monoImage = AssemblyGetImage(launcherAssembly); - if (monoImage == nullptr) - { - _ERR("Failed to get image from launcher assembly"); - return 1; - } - - assemblyManagerClass = ClassFromName(monoImage, "Tizen.Runtime.Mono", "AssemblyManager"); - if (assemblyManagerClass == nullptr) - { - _ERR("Failed to get AssemblyManager class in namespace Tizen.Runtime.Mono from launcher image"); - return 1; - } - - prepareLaunch = ClassGetMethodFromName(assemblyManagerClass, "Prepared", 0); - if (prepareLaunch == nullptr) - { - _ERR("Failed to get Prepared() method from Tizen.Runtime.Mono.AssemblyManager"); - return 1; - } - MonoObject* exception = nullptr; - RuntimeInvoke(prepareLaunch, nullptr, nullptr, &exception); - if (exception != nullptr) - { - MonoString * exceptionMsg = ObjectToString(exception, nullptr); - char* cstringMsg = StringToUtf8(exceptionMsg); - _ERR("Failed to invoke method in runtime"); - _ERR("%s", cstringMsg); - free(cstringMsg); - return 1; - } - - launch = ClassGetMethodFromName(assemblyManagerClass, "Launch", 4); - - return 0; -} - -#define ArrayAddr(array,type,index) ((type*)(void*) ArrayAddrWithSize (array, sizeof (type), index)) -#define ArraySet(array,type,index,value) \ - do { \ - type *__p = (type *) ArrayAddr ((array), type, (index)); \ - *__p = (value); \ - } while (0) - -int MonoRuntime::Launch(const char* root, const char* path, int argc, char* argv[]) -{ - if (domain == nullptr) - { - domain = JitInit(DOMAIN_NAME); - if (domain == nullptr) - { - _ERR("Failed to init mono jit"); - return 1; - } - } - if (launch != nullptr) - { - MonoString *rootMonoString = NewString(domain, root); - MonoString *pathMonoString = NewString(domain, path); - MonoArray *argvMonoArray = ArrayNew(domain, GetStringClass(), argc); - for (int i=0; i<argc; i++) - { - MonoString *arg = NewString(domain, argv[i]); - ArraySet(argvMonoArray, MonoString*, i, arg); - } - - void **args = new void*[argc+2]; - args[0] = rootMonoString; - args[1] = pathMonoString; - args[2] = &argc; - args[3] = argvMonoArray; - - MonoObject* exception = nullptr; - RuntimeInvoke(launch, nullptr, args, &exception); - if (exception != nullptr) - { - MonoString * exceptionMsg = ObjectToString(exception, nullptr); - char* cstringMsg = StringToUtf8(exceptionMsg); - _ERR("Failed to invoke launch method in runtime"); - _ERR("%s", cstringMsg); - free(cstringMsg); - return 1; - } - } - else - { - std::string appBin = ConcatPath(root, "bin"); - std::string appLib = ConcatPath(root, "lib"); - std::string probePath = deviceAPIDirectory + ":" + appBin + ":" + appLib; - SetAssembliesPath(probePath.c_str()); - MonoAssembly* app = DomainAssemblyOpen(domain, path); - if (app == nullptr) - { - _ERR("Failed to open assembly : %s", path); - return 1; - } - AssemblyExec(domain, app, argc, argv); - } - return 0; -} - -} // namespace dotnetcore -} // namespace runtime -} // namespace mono diff --git a/NativeLauncher/launcher/mono/mono_launcher.h b/NativeLauncher/launcher/mono/mono_launcher.h deleted file mode 100644 index 4e73670..0000000 --- a/NativeLauncher/launcher/mono/mono_launcher.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2016 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. - */ - -#include "launcher.h" - -extern "C" -{ - typedef struct _MonoDomain MonoDomain; - typedef struct _NonoAssembly MonoAssembly; - typedef struct _MonoImage MonoImage; - typedef struct _MonoClass MonoClass; - typedef struct _MonoObject MonoObject; - typedef struct _MonoMethod MonoMethod; - typedef struct _MonoString MonoString; - typedef struct _MonoArray MonoArray; - - typedef void (*mono_set_dirs_ptr) (const char *, const char *); - typedef void (*mono_set_assemblies_path_ptr) (const char*); - typedef MonoDomain* (*mono_jit_init_ptr) (const char *); - typedef void (*mono_config_parse_ptr) (const char *); - typedef MonoAssembly* (*mono_domain_assembly_open_ptr) (MonoDomain *, const char *); - typedef MonoImage* (*mono_assembly_get_image_ptr) (MonoAssembly *); - typedef MonoClass* (*mono_class_from_name_ptr) (MonoImage *, const char *, const char *); - typedef MonoObject* (*mono_runtime_invoke_ptr) (MonoMethod *, void *, void **, MonoObject **); - typedef MonoMethod* (*mono_class_get_method_from_name_ptr) (MonoClass *, const char *, int param_count); - typedef MonoString* (*mono_string_new_ptr) (MonoDomain *, const char *); - typedef MonoString* (*mono_object_to_string_ptr) (MonoObject *, MonoObject **); - typedef char* (*mono_string_to_utf8_ptr) (MonoString *string_obj); - - typedef MonoClass* (*mono_get_string_class_ptr) (); - typedef MonoArray* (*mono_array_new_ptr) (MonoDomain *, MonoClass *, uintptr_t); - typedef char* (*mono_array_addr_with_size_ptr) (MonoArray *, int, uintptr_t); - typedef void (*mono_jit_cleanup_ptr) (MonoDomain *domain); - typedef int (*mono_jit_exec_ptr) (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]); -} - -namespace tizen { -namespace runtime { -namespace mono { - -class MonoRuntime : public tizen::runtime::LauncherInterface -{ - public: - MonoRuntime(); - ~MonoRuntime(); - int Initialize(bool standalone) override; - void Dispose() override; - int RunManagedLauncher() override; - int Launch(const char* root, const char* path, int argc, char* argv[]) override; - - private: - void* monolib; - mono_set_dirs_ptr SetDirs; - mono_set_assemblies_path_ptr SetAssembliesPath; - mono_jit_init_ptr JitInit; - mono_domain_assembly_open_ptr DomainAssemblyOpen; - mono_assembly_get_image_ptr AssemblyGetImage; - mono_class_from_name_ptr ClassFromName; - mono_runtime_invoke_ptr RuntimeInvoke; - mono_class_get_method_from_name_ptr ClassGetMethodFromName; - mono_object_to_string_ptr ObjectToString; - mono_string_to_utf8_ptr StringToUtf8; - mono_string_new_ptr NewString; - mono_get_string_class_ptr GetStringClass; - mono_array_new_ptr ArrayNew; - mono_array_addr_with_size_ptr ArrayAddrWithSize; - mono_jit_cleanup_ptr DomainCleanup; - mono_jit_exec_ptr AssemblyExec; - - MonoDomain* domain; - MonoAssembly* launcherAssembly; - MonoImage* monoImage; - MonoClass* assemblyManagerClass; - MonoMethod* prepareLaunch; - MonoMethod* launch; - - std::string launcherAssemblyPath; - std::string deviceAPIDirectory; - std::string runtimeDirectory; -}; - - -} // namespace mono -} // namespace runtime -} // namespace tizen @@ -19,14 +19,14 @@ dotnet-launcher [options...] [args...] ### Anatomy ``` -+----------------------------------------------------+ -| Tizen.Runtime.Mono.dll | Tizen.Runtime.Coreclr.dll | -+-----------+------------------------+---------------+ -| | libmono.so | | libcoreclr.so | -| +------------+ +---------------+ -| Mono Native Launcher | CoreClr Native Launcher | -+------------------------+---------------------------+ -| Dotnet launcher | -+----------------------------------------------------+ +----------------------------- +| Tizen.Runtime.Coreclr.dll | +------------+---------------+ +| | libcoreclr.so | +| +---------------+ +| CoreClr Native Launcher | ++---------------------------+ +| Dotnet launcher | ++---------------------------+ ``` diff --git a/Tizen.Runtime/Tizen.Runtime.Mono.csproj b/Tizen.Runtime/Tizen.Runtime.Mono.csproj deleted file mode 100644 index e570697..0000000 --- a/Tizen.Runtime/Tizen.Runtime.Mono.csproj +++ /dev/null @@ -1,75 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="14.0" 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.Mono</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - </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> - -<!-- Roslyn Not Support Assembly Signing yet. - <PropertyGroup> - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>Tizen.Runtime.snk</AssemblyOriginatorKeyFile> - </PropertyGroup> ---> - - <PropertyGroup> - <DefineConstants Condition=" '$(CLOG)' != '' ">$(DefineConstants);CLOG</DefineConstants> - </PropertyGroup> - - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Net.Http" /> - <Reference Include="System.Xml" /> - </ItemGroup> - - <ItemGroup> - <Compile Include="Tizen.Runtime.Mono/AssemblyManager.cs" /> - <Compile Include="Tizen.Runtime/Log.cs" /> - <Compile Include="Tizen.Runtime/DefaultConfigAttribute.cs" /> - </ItemGroup> - - <Target Name="CheckConfig"> - <Message Text="MSBuildProjectDirectory = $(MSBuildProjectDirectory)"/> - </Target> - - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - - <Target Name="BeforeCompile"> - <ItemGroup> - <AssemblyAttributes Include="DefaultConfigAttribute" Condition=" $(PreloadPath) != '' "> - <_Parameter1>PreloadPath=$(PreloadPath)</_Parameter1> - </AssemblyAttributes> - </ItemGroup> - - <WriteCodeFragment AssemblyAttributes="@(AssemblyAttributes)" - Language="C#" - OutputDirectory="$(IntermediateOutputPath)" - OutputFile="Config.cs"> - <Output TaskParameter="OutputFile" ItemName="Compile" /> - </WriteCodeFragment> - - </Target> -</Project> diff --git a/Tizen.Runtime/Tizen.Runtime.Mono.project.json b/Tizen.Runtime/Tizen.Runtime.Mono.project.json deleted file mode 100644 index 710ecfa..0000000 --- a/Tizen.Runtime/Tizen.Runtime.Mono.project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - }, - "frameworks": { - "net45": {} - }, - "runtimes": { - "win": {} - } -} - diff --git a/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs deleted file mode 100644 index 441317a..0000000 --- a/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2016 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; -using System.IO; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.InteropServices; -using Tizen.Runtime; - -namespace Tizen.Runtime.Mono -{ - public static class AssemblyManager - { - - private static SortedSet<string> ResolveDirectories = new SortedSet<string>(); - private static SortedSet<string> ResolveFiles = new SortedSet<string>(); - - public static bool Launch( - [In] string rootPath, - [In] string path, - [In] int argc, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)] - [In] string[] argv) - { - ALog.Debug($"Application Launch path : {path}"); - try - { - DirectoryInfo bindir = new DirectoryInfo(Path.Combine(rootPath, "bin")); - DirectoryInfo libdir = new DirectoryInfo(Path.Combine(rootPath, "lib")); - if (Directory.Exists(bindir.FullName)) - { - ResolveDirectories.Add(bindir.FullName); - } - if (Directory.Exists(libdir.FullName)) - { - ResolveDirectories.Add(libdir.FullName); - } - ResolveFiles.Add(path); - Execute(path, argv); - } - catch(Exception e) - { - ALog.Debug("Exception in Launch()"); - PrintException(e); - return false; - } - - return true; - } - - static readonly string[] assemblyExtensions = {".dll", ".exe"}; - - public static Assembly AssemblyResolverHandler(object sender, ResolveEventArgs args) - { - // find dll name + ext in paths for resolving - foreach (string path in ResolveDirectories) - { - foreach (string ext in assemblyExtensions) - { - string assemblyPath = Path.Combine(path, new AssemblyName(args.Name).Name + ext); - if (File.Exists(assemblyPath)) - { - Assembly assembly = Assembly.LoadFrom(assemblyPath); - return assembly; - } - } - } - - return null; - } - - public static void Prepared() - { - try - { - string preloadPath = ""; - ICustomAttributeProvider assembly = typeof(AssemblyManager).GetTypeInfo().Assembly; - var attributes = assembly.GetCustomAttributes(typeof(DefaultConfigAttribute), false); - foreach (DefaultConfigAttribute dca in attributes) - { - ALog.Debug($"{dca.Key} = {dca.Value}"); - if (dca.Key == "PreloadPath") - { - preloadPath = dca.Value; - } - } - - if (!Initialize(preloadPath)) - { - ALog.Debug($"Failed to Initialized with {preloadPath}"); - } - - AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolverHandler; - } - catch(Exception e) - { - ALog.Debug("Exception at Preparing"); - PrintException(e); - } - } - - private static void PrintException(Exception exception) - { - while (exception != null) - { - ALog.Debug(exception.ToString()); - exception = exception.InnerException; - } - } - - public static bool Initialize(string preloadDirectory) - { - try - { - if (!string.IsNullOrEmpty(preloadDirectory)) - { - ALog.Debug($"Load from [{preloadDirectory}]"); - DirectoryInfo d = new DirectoryInfo(preloadDirectory); - if (Directory.Exists(d.FullName)) - { - ResolveDirectories.Add(d.FullName); - } - } - } - catch (Exception e) - { - ALog.Debug("Exception on Initialized"); - PrintException(e); - return false; - } - return true; - } - - - public static void Execute(string dllPath, string[] argv) - { - try - { - FileInfo f = new FileInfo(dllPath); - if (File.Exists(f.FullName)) - { - Assembly asm = Assembly.LoadFile(f.FullName); - if (asm.EntryPoint == null) throw new ArgumentException($"{f.FullName} did not have EntryPoint"); - asm.EntryPoint.Invoke(null, new object[]{argv}); - } - } - catch (Exception e) - { - ALog.Debug("Exception on Execute"); - PrintException(e); - } - } - - } -} diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 4ce5d38..78ca701 100755 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -71,7 +71,6 @@ cmake \ -DRUNTIME_DIR=%{_runtime_dir} \ -DCROSSGEN_PATH=%{_device_api_dir}/crossgen \ -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Coreclr.dll \ - -DMONO_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Mono.dll \ -DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \ -DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \ -DVERSION=%{version} \ @@ -85,17 +84,10 @@ xbuild \ /p:Configuration=%{_dotnet_build_conf} \ Tizen.Runtime/Tizen.Runtime.Coreclr.csproj -nuget restore Tizen.Runtime/Tizen.Runtime.Mono.project.json - -xbuild \ - /p:Configuration=%{_dotnet_build_conf} \ - Tizen.Runtime/Tizen.Runtime.Mono.csproj - %install rm -rf %{buildroot} %make_install install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Coreclr.dll %{buildroot}%{_bindir} -install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir} %files %manifest dotnet-launcher.manifest @@ -107,7 +99,6 @@ install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir %caps(cap_mac_admin,cap_setgid=ei) %{_install_plugin_dir}/libui-application.so %caps(cap_mac_admin,cap_setgid=ei) %{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Coreclr.dll -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Mono.dll %files -n scd-launcher %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/scd-launcher |