From: Woongsuk Cho Date: Wed, 29 Nov 2023 04:16:49 +0000 (+0900) Subject: Remove duplicated ni regeneration X-Git-Tag: accepted/tizen/unified/20240220.115648~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fdotnet%2Flauncher.git;a=commitdiff_plain;h=eb573fc01e0feffa08a10b4bb37510311f95c056 Remove duplicated ni regeneration 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. --- diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 43e9b19..d0a74c6 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -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 *pkgList = (std::vector *)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 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; }