X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=NativeLauncher%2Ftool%2Fni_common.cc;h=7cc1d639ff1867f87ae6e118351e89542eb816e8;hb=7a91946e9f06c8779cff7ee84177eea05a5fe111;hp=4796ad3370221099592bf0ea627bd1ae367cc2bb;hpb=0c0d4090182aa41feeee9f2b264a3e3c2b2fc712;p=platform%2Fcore%2Fdotnet%2Flauncher.git diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 4796ad3..7cc1d63 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include @@ -251,7 +253,7 @@ static std::string getAppNIFilePath(const std::string& absDllPath, NIOption* opt std::string prevPath; prevPath = getBaseName(absDllPath); - niDirPath = concatPath(prevPath, APP_NI_SUB_DIR); + niDirPath = concatPath(prevPath, APP_NI_SUB_TMP_DIR); if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) { niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); @@ -492,6 +494,12 @@ static ni_error_e crossgen2PostAction(const std::string& dllPath, const std::str } } + if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) { + if (!removeFile(dllPath)) { + _SERR("Fail to remove original file : %s", dllPath.c_str()); + } + } + if (!(opt->flags & NI_FLAGS_INPUT_BUBBLE && opt->flags & NI_FLAGS_NO_PIPELINE)) { _SOUT("Native image %s generated successfully.", outFile.c_str()); } @@ -499,6 +507,22 @@ static ni_error_e crossgen2PostAction(const std::string& dllPath, const std::str return NI_ERROR_NONE; } +void setPriority(NIOption* opt) +{ + pid_t pid = getpid(); + if (setpriority(PRIO_PROCESS, pid, opt->priority) == 0) { + std::string str = " "; + if (opt->priority <= -20) { + str = " highest "; + } else if (opt->priority >= 19) { + str = " lowest "; + } + _SOUT("Success to set the%spriority of the process. pid : [%d], priority : [%d]", str.c_str(), pid, getpriority(PRIO_PROCESS, pid)); + } else { + _SERR("Failed to set the priority of the process. pid : [%d], priority : [%d]", pid, getpriority(PRIO_PROCESS, pid)); + } +} + static ni_error_e crossgen2PipeLine(const std::vector& dllList, const std::vector& refPaths, NIOption* opt) { // fork crossgen2 @@ -521,6 +545,9 @@ static ni_error_e crossgen2PipeLine(const std::vector& dllList, con return NI_ERROR_ABNORMAL_PROCESS_TERMINATION; } } else { + if (opt->flags & NI_FLAGS_SET_PRIORITY) { + setPriority(opt); + } std::vector argv; makeArgs(argv, refPaths, opt); argv.push_back(CROSSGEN_OPT_OUT_NEAR_INPUT); @@ -594,6 +621,9 @@ static ni_error_e crossgen2NoPipeLine(const std::vector& dllList, c return NI_ERROR_ABNORMAL_PROCESS_TERMINATION; } } else { + if (opt->flags & NI_FLAGS_SET_PRIORITY) { + setPriority(opt); + } std::vector argv; makeArgs(argv, refPaths, opt); @@ -647,7 +677,15 @@ static ni_error_e createCoreLibNI(NIOption* opt) if (!isFile(coreLibBackup) && !isR2RImage(coreLib)) { if (crossgen2NoPipeLine(dllList, refPaths, opt) == NI_ERROR_NONE) { - if (rename(coreLib.c_str(), coreLibBackup.c_str())) { + if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) { + std::ofstream output(coreLibBackup); + if (!exist(coreLibBackup)) { + _SERR("Failed to create System.Private.CoreLib.dll.Backup"); + return NI_ERROR_CORE_NI_FILE; + } + copySmackAndOwnership(__pm->getRuntimePath(), coreLibBackup, false); + output.close(); + } else if (rename(coreLib.c_str(), coreLibBackup.c_str())) { _SERR("Failed to rename from System.Private.CoreLib.dll to System.Private.CoreLib.dll.Backup"); return NI_ERROR_CORE_NI_FILE; } @@ -655,7 +693,7 @@ static ni_error_e createCoreLibNI(NIOption* opt) if (rename(niTmpCoreLib.c_str(), coreLib.c_str())) { _SERR("Failed to rename from System.Private.CoreLib.ni.dll.tmp to Private.CoreLib.dll"); return NI_ERROR_CORE_NI_FILE; - } + } } else { if (rename(niCoreLib.c_str(), coreLib.c_str())) { _SERR("Failed to rename from System.Private.CoreLib.ni.dll to Private.CoreLib.dll"); @@ -670,6 +708,23 @@ static ni_error_e createCoreLibNI(NIOption* opt) return NI_ERROR_NONE; } +static void renameAppNITmpPath(NIOption* opt) +{ + std::string niTmpPath = __pm->getAppRootPath() + "/bin/" + APP_NI_SUB_TMP_DIR; + std::string niPath = __pm->getAppRootPath() + "/bin/" + APP_NI_SUB_DIR; + + if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) { + niTmpPath = replaceAll(niTmpPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); + niPath = replaceAll(niPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); + } + + if (isDirectory(niTmpPath)) { + if (rename(niTmpPath.c_str(), niPath.c_str())) { + _SERR("Fail to rename from .native_image_tmp to .native_image"); + } + } +} + static ni_error_e doAOTList(std::vector& dllList, const std::string& refPaths, NIOption* opt) { ni_error_e ret = NI_ERROR_NONE; @@ -744,22 +799,27 @@ static ni_error_e doAOTList(std::vector& dllList, const std::string } } - if (ret == NI_ERROR_NONE && opt->flags & NI_FLAGS_INPUT_BUBBLE) { - for (auto &dll : dllList) { - std::string tmpFile; - std::string niFile; - if (opt->flags & NI_FLAGS_APPNI) { - niFile = getAppNIFilePath(dll, opt); - } else { - niFile = getNIFilePath(dll); - } - tmpFile = niFile + ".tmp"; + if (ret == NI_ERROR_NONE) { + if (opt->flags & NI_FLAGS_INPUT_BUBBLE) { + for (auto &dll : dllList) { + std::string tmpFile; + std::string niFile; + if (opt->flags & NI_FLAGS_APPNI) { + niFile = getAppNIFilePath(dll, opt); + } else { + niFile = getNIFilePath(dll); + } + tmpFile = niFile + ".tmp"; - if (exist(tmpFile)) { - moveFile(tmpFile, niFile); - _SOUT("Native image %s generated successfully.", niFile.c_str()); + if (exist(tmpFile)) { + moveFile(tmpFile, niFile); + _SOUT("Native image %s generated successfully.", niFile.c_str()); + } } } + if (opt->flags & NI_FLAGS_APPNI) { + renameAppNITmpPath(opt); + } } return ret; @@ -1088,8 +1148,13 @@ void removeNIUnderDirs(const std::string& rootPaths) { auto convert = [](const std::string& path, const std::string& filename) { if (isNativeImage(path)) { - if (remove(path.c_str())) { - _SERR("Failed to remove %s", path.c_str()); + std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll"); + if (exist(assemblyPath)) { + if (remove(path.c_str())) { + _SERR("Failed to remove %s", path.c_str()); + } + } else { + _SOUT("%s cannot be removed because there is no %s", path.c_str(), assemblyPath.c_str()); } } }; @@ -1152,7 +1217,7 @@ ni_error_e regenerateAppNI(NIOption* opt) if (ret != PMINFO_R_OK) return NI_ERROR_UNKNOWN; - ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, METADATA_VALUE); + ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, METADATA_VALUE_TRUE); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_metadata_filter_destroy(handle); return NI_ERROR_UNKNOWN; @@ -1172,6 +1237,7 @@ ni_error_e regenerateAppNI(NIOption* opt) static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData) { char *pkgId = NULL; + char *root = NULL; NIOption **pOpt = (NIOption**)userData; int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId); @@ -1180,6 +1246,18 @@ static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData) return -1; } + ret = pkgmgrinfo_appinfo_get_root_path(handle, &root); + if (ret != PMINFO_R_OK) { + _SERR("Failed to get root path"); + return -1; + } + + std::string binPath = concatPath(std::string(root), "bin"); + if (exist(concatPath(binPath, PRE_COMPILED_PACKAGE_FILE))) { + _INFO("The %s is a Pre-Compiled package. So, skip the TAC", pkgId); + return 0; + } + sqlite3 *tac_db = openDB(TAC_APP_LIST_DB); if (!tac_db) { _SERR("Sqlite open error"); @@ -1221,7 +1299,7 @@ ni_error_e regenerateTACNI(NIOption* opt) return NI_ERROR_UNKNOWN; } - ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE); + ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_metadata_filter_destroy(handle); return NI_ERROR_UNKNOWN;