Fix unused native image in application. 53/104753/1
authorpius.lee <pius.lee@samsung.com>
Wed, 30 Nov 2016 09:22:11 +0000 (18:22 +0900)
committerJongHeon Choi <j-h.choi@samsung.com>
Wed, 14 Dec 2016 08:08:14 +0000 (17:08 +0900)
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
NativeLauncher/launcher/main.cc
Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs

index 509248d..cb9fcd0 100644 (file)
@@ -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);
index 3d574ec..314e719 100644 (file)
 
 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<char*> 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))
index ea31f8f..26b8868 100644 (file)
@@ -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});