add ni regeneration feature to support FOTA 10/191310/1 accepted/tizen/4.0/unified/20181016.040128 submit/tizen_4.0/20181016.020113
authorWoongsuk Cho <ws77.cho@samsung.com>
Tue, 16 Oct 2018 01:59:08 +0000 (10:59 +0900)
committerWoongsuk Cho <ws77.cho@samsung.com>
Tue, 16 Oct 2018 01:59:08 +0000 (10:59 +0900)
Change-Id: I0e3a9100d1f486effd8414aad293367f873ad85c

NativeLauncher/installer-plugin/common.cc
NativeLauncher/installer-plugin/common.h
NativeLauncher/installer-plugin/nitool.cc

index f1d212e..3cda7b3 100644 (file)
@@ -233,6 +233,32 @@ static bool niExist(const std::string& path, std::string& ni)
        return false;
 }
 
+static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
+{
+       char *pkgId = NULL;
+       int ret = 0;
+
+       ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
+       if (ret != PMINFO_R_OK) {
+               fprintf(stderr, "Failed to get pkgid\n");
+               return -1;
+       }
+
+       if (removeNiUnderPkgRoot(pkgId) != 0) {
+               fprintf(stderr, "Failed to remove previous dlls from [%s]\n", pkgId);
+               return -1;
+       }
+
+       if (createNiUnderPkgRoot(pkgId) != 0) {
+               fprintf(stderr, "Failed to get root path from [%s]\n", pkgId);
+               return -1;
+       } else {
+               fprintf(stderr, "Complete make application to native image\n");
+       }
+
+       return 0;
+}
+
 static void createCoreLibNI()
 {
        std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll");
@@ -373,3 +399,62 @@ int createNiUnderPkgRoot(const char* pkgName)
 
        return 0;
 }
+
+void removeNiUnderDirs(const std::string rootPaths[], int count)
+{
+       auto convert = [](const std::string& path, std::string name) {
+               std::string ni;
+               if (isNativeImage(path)) {
+                       if (remove(path.c_str())) {
+                               fprintf(stderr, "Failed to remove %s\n", path.c_str());
+                       }
+               }
+       };
+
+       for (int i = 0; i < count; i++)
+               scanFilesInDir(rootPaths[i].c_str(), convert, -1);
+}
+
+int removeNiUnderPkgRoot(const std::string& pkgName)
+{
+       std::string pkgRoot;
+       if (getRootPath(pkgName.c_str(), pkgRoot) < 0)
+               return -1;
+
+       std::string binDir = concatPath(pkgRoot, "bin");
+       std::string libDir = concatPath(pkgRoot, "lib");
+       std::string paths[] = {binDir, libDir};
+
+       removeNiUnderDirs(paths, 2);
+
+       return 0;
+}
+
+int regenerateAppNI()
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_metadata_filter_h handle;
+
+       ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+
+       ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, "http://tizen.org/metadata/prefer_dotnet_aot", "true");
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+
+       ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, appAotCb, NULL);
+       if (ret != PMINFO_R_OK) {
+               fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n");
+               pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+
+       fprintf(stderr, "Success pkgmgrinfo_appinfo_metadata_filter_foreach\n");
+
+       pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+       return 0;
+}
+
index d36ae69..550e2f0 100644 (file)
@@ -26,5 +26,8 @@ void createNiUnderDirs(const char* rootPaths[], int count);
 int createNiUnderPkgRoot(const char* pkgName);
 void createNiPlatform();
 void createNiSelect(const char* dllPath);
+void removeNiUnderDirs(const std::string rootPaths[], int count);
+int removeNiUnderPkgRoot(const std::string& pkgId);
+int regenerateAppNI();
 
 #endif /* __INSTALLER_PLUGIN_COMMON_H__ */
index c34a696..9149623 100644 (file)
@@ -45,6 +45,7 @@ static void help(const char *argv0)
                "               --system                - Create NI under System DLLs\n"
                "               --dll                   - Create NI for DLL\n"
                "               --pkg                   - Create NI for package\n"
+               "               --regen-all-app         - Re-generate All App NI files\n"
                "\n"
                "Example:\n"
                "Create native image for dlls and exes under platform directories\n"
@@ -71,6 +72,9 @@ int main(int argc, char* argv[])
                dllMode = true;
        } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
                pkgMode = true;
+       } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
+               regenerateAppNI();
+               return 0;
        } else {
                help(argv[0]);
                return 1;