Remove duplicated ni regeneration
authorWoongsuk Cho <ws77.cho@samsung.com>
Wed, 29 Nov 2023 04:16:49 +0000 (13:16 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Mon, 19 Feb 2024 05:33:28 +0000 (14:33 +0900)
In case of --ni-regen-all-app option, AOTC was performed multiply for one package if multiple app is contained in it.
To avoid this situation, get unique candiate package list for --ni-regen-all-app.

NativeLauncher/tool/ni_common.cc

index 43e9b19..d0a74c6 100644 (file)
@@ -853,23 +853,10 @@ static ni_error_e doAOTFile(const std::string& dllFile, const std::string& refPa
 }
 
 // callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
-static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
+static int getPkgIdCb(pkgmgrinfo_appinfo_h handle, void *userData)
 {
        char *pkgId = NULL;
        int ret = 0;
-       NIOption **pOptions = (NIOption**)userData;
-
-       if ((*pOptions)->flags & NI_FLAGS_SKIP_RO_APP) {
-               bool isSystem = false;
-               int ret = pkgmgrinfo_appinfo_is_system(handle, &isSystem);
-               if (ret != PMINFO_R_OK) {
-                       _SERR("Failed to check that app is System or not\n");
-                       return -1;
-               }
-               if (isSystem) {
-                       return 0;
-               }
-       }
 
        ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
        if (ret != PMINFO_R_OK) {
@@ -877,19 +864,33 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
                return -1;
        }
 
-       if (removeNIUnderPkgRoot(pkgId) != NI_ERROR_NONE) {
-               _SERR("Failed to remove previous dlls from [%s]", pkgId);
-               return -1;
+       std::vector<std::string> *pkgList = (std::vector<std::string> *)userData;
+       pkgList->push_back(pkgId);
+
+       return 0;
+}
+
+static bool isReadOnlyPkg(std::string pkgId)
+{
+       int ret = 0;
+       bool readonly = false;
+       pkgmgrinfo_pkginfo_h handle;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &handle);
+       if (ret != PMINFO_R_OK) {
+               _ERR("Fail to get pkginfo");
+               return false;
        }
 
-       if (createNIUnderPkgRoot(pkgId, *pOptions) != NI_ERROR_NONE) {
-               _SERR("Failed to generate NI file [%s]", pkgId);
-               return -1;
-       } else {
-               _SOUT("Complete make application to native image");
+       ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly);
+       if (ret != PMINFO_R_OK) {
+               _ERR("Fail to get is_readonly");
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return false;
        }
 
-       return 0;
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return readonly;
 }
 
 ni_error_e initNICommon()
@@ -1217,6 +1218,7 @@ ni_error_e regenerateAppNI(NIOption* opt)
 {
        int ret = 0;
        pkgmgrinfo_appinfo_metadata_filter_h handle;
+       std::vector<std::string> pkgList;
 
        ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
        if (ret != PMINFO_R_OK)
@@ -1228,12 +1230,34 @@ ni_error_e regenerateAppNI(NIOption* opt)
                return NI_ERROR_UNKNOWN;
        }
 
-       ret = pkgmgrMDFilterForeach(handle, appAotCb, &opt);
+       ret = pkgmgrMDFilterForeach(handle, getPkgIdCb, &pkgList);
        if (ret != 0) {
                pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
                return NI_ERROR_UNKNOWN;
        }
 
+       // remove duplicated pkg in the list.
+       // If one package has multiple apps, there can be duplicate values.
+       pkgList.erase(unique(pkgList.begin(), pkgList.end()), pkgList.end());
+
+       for (auto pkg : pkgList) {
+               if (isReadOnlyPkg(pkg) && opt->flags & NI_FLAGS_SKIP_RO_APP) {
+                       continue;
+               }
+
+               if (removeNIUnderPkgRoot(pkg) != NI_ERROR_NONE) {
+                       _SERR("Failed to remove previous dlls from [%s]", pkg.c_str());
+                       return NI_ERROR_UNKNOWN;
+               }
+
+               if (createNIUnderPkgRoot(pkg, opt) != NI_ERROR_NONE) {
+                       _SERR("Failed to generate NI file [%s]", pkg.c_str());
+                       return NI_ERROR_UNKNOWN;
+               } else {
+                       _SOUT("Complete make application to native image");
+               }
+       }
+
        pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
        return NI_ERROR_NONE;
 }