find dlls in the app directory first for app NI 91/119491/1
authorCho Woong Suk <ws77.cho@samsung.com>
Fri, 17 Mar 2017 06:23:42 +0000 (15:23 +0900)
committerCho Woong Suk <ws77.cho@samsung.com>
Fri, 17 Mar 2017 06:23:42 +0000 (15:23 +0900)
Change-Id: Id0e89694d0cb1889938741227bf882b3eb6560d4

NativeLauncher/inc/utils.h
NativeLauncher/installer-plugin/common.cc
NativeLauncher/util/utils.cc

index b66a708..59774cb 100755 (executable)
@@ -20,6 +20,7 @@
 #include <string>
 #include <vector>
 #include <functional>
+#include <map>
 
 #ifndef PATH_SEPARATOR
 #define PATH_SEPARATOR '/'
@@ -36,9 +37,10 @@ std::string AbsolutePath (const std::string& path);
 std::string Basename (const std::string& path);
 bool EndWithIgnoreCase (const std::string& str1, const std::string& str2, std::string& filename);
 void AssembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
+
 bool FileNotExist(const std::string& path);
 std::string JoinStrings(const std::vector<std::string>& strings, const char* const delimeter);
 
-typedef std::function<void (const char*)> FileReader;
+typedef std::function<void (const char*, const char*)> FileReader;
 void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth);
 #endif  // __UTILS_H__
index ddeabdc..5d1306c 100644 (file)
@@ -165,9 +165,25 @@ static void crossgen(const char* dll_path, const char* app_path)
   }
   else
   {
-    std::vector<std::string> tpaDir = {
-      RuntimeDir, DeviceAPIDir
-    };
+    // search dlls in the application directory first, to use application dlls
+    // instead of system dlls when proceeding NI
+    std::vector<std::string> tpaDir;
+    if (app_path != NULL)
+    {
+      std::string path(app_path);
+      std::string::size_type prev_pos = 0, pos = 0;
+      while((pos = path.find(':', pos)) != std::string::npos)
+      {
+        std::string substring(path.substr(prev_pos, pos - prev_pos));
+        tpaDir.push_back(substring);
+        prev_pos = ++pos;
+      }
+      std::string substring(path.substr(prev_pos, pos - prev_pos));
+      tpaDir.push_back(substring);
+    }
+    tpaDir.push_back(RuntimeDir);
+    tpaDir.push_back(DeviceAPIDir);
+
     std::string tpa;
     AssembliesInDirectory(tpaDir, tpa);
 
@@ -273,7 +289,7 @@ void create_ni_under_dirs(const char* root_paths[], int count, const char* ignor
   if (app_paths.back() == ':')
     app_paths.pop_back();
 
-  auto convert = [&app_paths, ignores, igcount, &cb](const char* path)
+  auto convert = [&app_paths, ignores, igcount, &cb](const char* path, const char* name)
   {
     for (int i=0; i<igcount; i++)
     {
index 212f1d6..75dbcec 100755 (executable)
@@ -182,14 +182,14 @@ std::string StripNIDLL(const std::string& path)
 {
   std::string npath(path);
   if (path.size() < 5) return npath;
-  if (strncasecmp(path.c_str() + path.size() - 4, ".dll", 4))
+  if (!strncasecmp(path.c_str() + path.size() - 4, ".dll", 4))
   {
     npath = path.substr(0, path.size()-4);
-  }else if (strncasecmp(path.c_str() + path.size() - 4, ".exe", 4))
+  }else if (!strncasecmp(path.c_str() + path.size() - 4, ".exe", 4))
   {
     npath = path.substr(0, path.size()-4);
   }
-  if (strncasecmp(npath.c_str() + npath.size() - 3, ".ni", 3))
+  if (!strncasecmp(npath.c_str() + npath.size() - 3, ".ni", 3))
   {
     return npath.substr(0, npath.size()-3);
   }
@@ -240,37 +240,23 @@ namespace std
 
 void AssembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList)
 {
-  std::unordered_map<AssemblyFile, bool> addedAssemblies;
+  std::map<std::string, std::string> assemblyList;
+  std::map<std::string, std::string> tmpList;
 
-  auto reader = [&addedAssemblies] (const char* path)
+  auto reader = [&assemblyList, &tmpList] (const char* path, const char* name)
   {
     std::string _path(path);
-
-    std::string::size_type dotp = _path.rfind('.');
-    std::string ext = dotp != std::string::npos ? _path.substr(dotp) : "";
-    std::string noext;
-    bool ni = false;
-
     if (IsManagedAssembly(_path))
     {
-      if (IsNativeImage(_path))
-      {
-        noext = _path.substr(0, _path.size()-7);
-        ni = true;
-      }
-      else
-      {
-        noext = _path.substr(0, _path.size()-4);
-      }
-
-      AssemblyFile f = {noext, ext};
-      if (addedAssemblies.find(f) == addedAssemblies.end())
+      std::string dll_name = StripNIDLL(name);
+      std::pair<std::map<std::string, std::string>::iterator, bool> ret;
+      ret = tmpList.insert(std::pair<std::string, std::string>(dll_name, _path));
+      if (ret.second == false)
       {
-        addedAssemblies[f] = ni;
-      }
-      else
-      {
-        addedAssemblies[f] |= ni;
+        if (IsNativeImage(_path))
+        {
+          tmpList[dll_name] = _path;
+        }
       }
     }
   };
@@ -278,15 +264,20 @@ void AssembliesInDirectory(const std::vector<std::string>& directories, std::str
   for (auto directory : directories)
   {
     ScanFilesInDir(directory.c_str(), reader, 1);
+    // merge scaned dll list to tpa list.
+    // if the dll is already exist in the list, that is skipped.
+    assemblyList.insert(tmpList.begin(), tmpList.end());
   }
 
-  for (auto kv : addedAssemblies)
+  std::map<std::string, std::string>::iterator it;
+  for (it = assemblyList.begin(); it != assemblyList.end(); it++)
   {
-    tpaList += kv.first.noext + (kv.second ? ".ni" : "") +  kv.first.ext + ':';
+    tpaList += it->second + ':';
   }
-
   if (tpaList.back() == ':')
+  {
     tpaList.pop_back();
+  }
 }
 
 void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth)
@@ -332,7 +323,7 @@ void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth
     }
     if (!isDir)
     {
-      reader(path.c_str()); 
+      reader(path.c_str(), entry->d_name);
     }
     else if (depth > 1 && strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
     {