Nuget with no dependency applies TAC
authorj-h.choi <j-h.choi@samsung.com>
Tue, 6 Aug 2019 00:50:38 +0000 (09:50 +0900)
committer조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Tue, 6 Aug 2019 22:40:53 +0000 (07:40 +0900)
NativeLauncher/inc/ni_common.h
NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
NativeLauncher/tool/ni_common.cc
NativeLauncher/tool/tac_common.cc
NativeLauncher/util/utils.cc

index 3f3de82..9c1fc26 100644 (file)
@@ -67,6 +67,13 @@ void createNiPlatform(bool enableR2R);
 ni_error_e createNiDll(const std::string& dllPath, bool enableR2R);
 
 /**
+ * @brief create native images for TAC DLLs.
+ * @param[i] rootPaths directories whicn contains DLLs
+ * @param[i] count number of rootPath
+ */
+void createNiUnderTAC(const std::string rootPaths[], int count);
+
+/**
  * @brief create native images with files under specific directory.
  * @param[i] rootPaths directories whicn contains DLLs
  * @param[i] count number of rootPath
index 91204f5..f48ffe7 100644 (file)
@@ -84,7 +84,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                                                std::string originPath = bf::read_symlink(symPath).string();
                                                std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
                                                if (!bf::exists(originNiPath)) {
-                                                       if(createNiDll(originPath, false) != NI_ERROR_NONE) {
+                                                       if(createNiDllUnderPkgRoot(pkgId, originPath, false) != NI_ERROR_NONE) {
                                                                _ERR("Failed to create NI file [%s]", originPath.c_str());
                                                                return -1;
                                                        }
index 69c2dcf..f1127e4 100644 (file)
@@ -52,6 +52,7 @@
 #define __XSTR(x) #x
 #define __STR(x) __XSTR(x)
 static const char* __CROSSGEN_PATH = __STR(CROSSGEN_PATH);
+static const char* __TAC_DIR = __STR(TAC_DIR);
 
 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
 static const char* __SYSTEM_BASE_FILE = __STR(SYSTEM_BASE_FILE);
@@ -239,7 +240,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
                return NI_ERROR_UNKNOWN;
        }
 
-       if (isAppNI) {
+       if (isAppNI && strstr(absNiPath.c_str(), __TAC_DIR) == NULL) {
                absNiPath = getAppNIPath(absNiPath);
        }
 
@@ -440,6 +441,40 @@ ni_error_e createNiDll(const std::string& dllPath, bool enableR2R)
        return status;
 }
 
+void createNiUnderTAC(const std::string rootPaths[], int count)
+{
+       std::string appPaths;
+       try {
+               for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
+                       std::string nugetPath = nuget.path().string();
+                       if (bf::is_directory(nugetPath)) {
+                               appPaths += nugetPath;
+                               appPaths += ':';
+                       }
+               }
+               if (appPaths.back() == ':') {
+                       appPaths.pop_back();
+               }
+
+               auto convert = [&appPaths](const std::string& path, const char* name) {
+                       if (strstr(path.c_str(), TAC_APP_LIST_DB) != NULL ||
+                               strstr(path.c_str(), TAC_APP_LIST_RESTORE_DB) != NULL ||
+                               strstr(path.c_str(), TAC_SHA_256_INFO) != NULL)
+                               return;
+                       if (!crossgen(path, appPaths.c_str(), false)) {
+                               waitInterval();
+                       }
+               };
+
+               for (int i = 0; i < count; i++) {
+                       scanFilesInDir(rootPaths[i], convert, -1);
+               }
+       } catch (const bf::filesystem_error& error) {
+               fprintf(stderr, "Failed to recursive directory: %s", error.what());
+               return;
+       }
+}
+
 void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool isAppNI)
 {
        createCoreLibNI(enableR2R);
index 78c20cf..b767c91 100644 (file)
@@ -286,18 +286,7 @@ tac_error_e regenerateTAC()
 {
        const std::string tacDir[] = {__TAC_DIR};
        removeNiUnderDirs(tacDir, 1);
-
-       auto convert = [](const std::string& path, std::string name) {
-               if (strstr(path.c_str(), TAC_APP_LIST_DB) != NULL ||
-                       strstr(path.c_str(), TAC_APP_LIST_RESTORE_DB) != NULL ||
-                       strstr(path.c_str(), TAC_SHA_256_INFO) != NULL)
-                       return;
-               if(createNiDll(path, false) != NI_ERROR_NONE) {
-                       fprintf(stderr, "Failed to create NI file [%s]\n", path.c_str());
-                       return;
-               }
-       };
-       scanFilesInDir(tacDir[0], convert, -1);
+       createNiUnderTAC(tacDir, 1);
        return TAC_ERROR_NONE;
 }
 
index 45b2bad..3d5a5f6 100644 (file)
@@ -619,6 +619,19 @@ std::vector<std::string> depsJsonParser(std::string rootPath, std::string execNa
                        }
                        const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
                        const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
+                       std::vector<std::string> appDependencies;
+                       for (auto& nuget : nugetPackages.getMemberNames()) {
+                               if (strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL ||
+                                       strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) {
+                                       const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
+                                       if (assemblies != Json::nullValue) {
+                                               const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
+                                               for (auto& dependency : dependencies.getMemberNames()) {
+                                                       appDependencies.push_back(dependency);
+                                               }
+                                       }
+                               }
+                       }
                        for (auto& nuget : nugetPackages.getMemberNames()) {
                                //Skip the nuget package related to Tizen
                                if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
@@ -634,6 +647,14 @@ std::vector<std::string> depsJsonParser(std::string rootPath, std::string execNa
                                                        if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
                                                                strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) == NULL) {
                                                                hasDependency = true;
+                                                               for (auto& ad : appDependencies) {
+                                                                       if (!strcmp(ad.c_str(), dependency.c_str())) {
+                                                                               hasDependency = true;
+                                                                               break;
+                                                                       } else {
+                                                                               hasDependency = false;
+                                                                       }
+                                                               }
                                                        }
                                                }
                                                if (!hasDependency) {
@@ -660,6 +681,7 @@ std::vector<std::string> depsJsonParser(std::string rootPath, std::string execNa
                                        }
                                }
                        }
+                       appDependencies.clear();
                        ifs.close();
                }
        }