Nuget with no dependency applies TAC
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / ni_common.cc
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);