From ac952532bac864e145498a0cc724d84a67339ac0 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Wed, 30 Nov 2016 18:22:11 +0900 Subject: [PATCH] Fix unused native image in application. Now launcher use Native image in application's bin, lib directory. --native option is added to dotnet-launcher. It must be use with --standalone. --native launch dll without managed launcher. But it can't launch ni.dll. Change-Id: Icf0ab0e9330ec1e94db5440e517e76710f1d81e1 --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 12 ++++++++++++ NativeLauncher/launcher/main.cc | 18 ++++++++++++++++++ Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs | 11 ++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 509248d..cb9fcd0 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -277,6 +277,18 @@ int CoreRuntime::Launch(const char* root, const char* path, int argc, char* argv return 1; } + std::string cpppath(path); + + if (IsManagedAssembly(cpppath) && !IsNativeImage(cpppath)) + { + size_t extindex = cpppath.size() - 4; + cpppath = cpppath.substr(0, extindex) + ".ni" + cpppath.substr(extindex, 4); + if (!FileNotExist(cpppath)) + { + path = cpppath.c_str(); + } + } + if (FileNotExist(path)) { _ERR("File not exist : %s", path); diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 3d574ec..314e719 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -38,12 +38,14 @@ static std::string VersionOption("--version"); static std::string StandaloneOption("--standalone"); +static std::string NativeOption("--native"); int main(int argc, char *argv[]) { int i; bool standalone = false; const char* standalonePath = nullptr; + bool nativeOnly = false; std::vector vargs; @@ -66,12 +68,22 @@ int main(int argc, char *argv[]) i++; standalonePath = argv[i]; } + else if (NativeOption.compare(argv[i]) == 0) + { + nativeOnly = true; + } else { vargs.push_back(argv[i]); } } + if (!standalone && nativeOnly) + { + fprintf(stderr, "\"--native\" option must be use with \"--standalone\"\n"); + return 1; + } + using tizen::runtime::LauncherInterface; using tizen::runtime::Launchpad; using tizen::runtime::AppInfo; @@ -120,6 +132,12 @@ int main(int argc, char *argv[]) return 1; } + if (!nativeOnly && runtime->RunManagedLauncher() != 0) + { + _ERR("Failed to run managed launcher"); + return 1; + } + int args_len = vargs.size(); char** args = &vargs[0]; if (runtime->Launch(approot.c_str(), standalonePath, args_len, args)) diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index ea31f8f..26b8868 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -165,7 +165,16 @@ namespace Tizen.Runtime.Coreclr FileInfo f = new FileInfo(dllPath); if (File.Exists(f.FullName)) { - Assembly asm = CurrentAssemblyLoaderContext.LoadFromAssemblyPath(f.FullName); + Assembly asm = null; + if (0 == string.Compare(f.FullName, f.FullName.Length - 7, ".ni", 0, 3, StringComparison.OrdinalIgnoreCase)) + { + asm = CurrentAssemblyLoaderContext.LoadFromNativeImagePath(f.FullName, null); + } + else + { + 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 object[]{argv}); -- 2.7.4