From 75579551a0e681b4ff298696a0e7343c7f3a57e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=A1=B0=EC=9B=85=EC=84=9D/Common=20Platform=20Lab=28SR=29?= =?utf8?q?/Principal=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 23 Jul 2021 13:08:27 +0900 Subject: [PATCH] Skip app ni regeneration if app ni already exist (#344) To avoid multiple NI file generation for --ni-pkg, skip app ni regeneration if app ni already exist --- NativeLauncher/tool/ni_common.cc | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 51a04b3..80af20e 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -150,8 +150,8 @@ static std::string getAppNIFilePath(const std::string& absDllPath, DWORD flags) if (flags & NI_FLAGS_APP_UNDER_RO_AREA) { niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); - _SERR("App is installed in RO area. So, create NI files in RW area(%s).", niDirPath.c_str()); - _ERR("App is installed in RO area. So, create NI files in RW area(%s).", niDirPath.c_str()); + _SERR("App is installed in RO area. Change NI path to RW area(%s).", niDirPath.c_str()); + _ERR("App is installed in RO area. Change NI path to RW area(%s).", niDirPath.c_str()); } if (!isDirectory(niDirPath)) { @@ -164,21 +164,20 @@ static std::string getAppNIFilePath(const std::string& absDllPath, DWORD flags) return getNIFilePath(concatPath(niDirPath, getFileName(absDllPath))); } -static bool checkNIExistence(const std::string& path) +static bool checkNIExistence(const std::string& absDllPath, const std::string& absNIPath) { - std::string f = getNIFilePath(path); - if (f.empty()) { + if (absNIPath.empty()) { return false; } - if (isFile(f)) { + if (isFile(absNIPath)) { return true; } // native image of System.Private.CoreLib.dll should have to overwrite // original file to support new coreclr - if (path.find("System.Private.CoreLib.dll") != std::string::npos) { - std::string coreLibBackup = path + ".Backup"; + if (absDllPath.find("System.Private.CoreLib.dll") != std::string::npos) { + std::string coreLibBackup = absDllPath + ".Backup"; if (isFile(coreLibBackup)) { return true; } @@ -288,11 +287,6 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat return NI_ERROR_INVALID_PARAMETER; } - if (checkNIExistence(dllPath)) { - //_SERR("Already ni file is exist for %s", dllPath.c_str()); - return NI_ERROR_ALREADY_EXIST; - } - std::string absDllPath = getAbsolutePath(dllPath); std::string absNIPath; @@ -308,6 +302,11 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat return NI_ERROR_UNKNOWN; } + if (checkNIExistence(absDllPath, absNIPath)) { + //_SERR("Already ni file is exist for %s", absNIPath.c_str()); + return NI_ERROR_ALREADY_EXIST; + } + #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT uintptr_t baseAddr = 0; @@ -429,6 +428,11 @@ 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; + } + if (createNIUnderPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) { _SERR("Failed to generate NI file [%s]", pkgId); return -1; @@ -651,11 +655,6 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags) flags |= NI_FLAGS_APP_UNDER_RO_AREA; } else { flags &= ~NI_FLAGS_APP_UNDER_RO_AREA; - ni_error_e err = removeNIUnderPkgRoot(pkgId); - if (err != NI_ERROR_NONE) { - _SERR("Failed to remove previous dlls from [%s]", pkgId.c_str()); - return err; - } } // create native image under bin and lib directory @@ -724,13 +723,15 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId) std::vector paths; splitPath(appNIPaths, paths); for (const auto &path : paths) { - // Only the native image inside the TAC should be removed. - if (strstr(path.c_str(), TAC_SYMLINK_SUB_DIR) != NULL) { - removeNIUnderDirs(path); - } else { - if (isDirectory(path)) { - if (!removeAll(path.c_str())) { - _SERR("Failed to remove app ni dir [%s]", path.c_str()); + if (!isReadOnlyArea(path)) { + // Only the native image inside the TAC should be removed. + if (strstr(path.c_str(), TAC_SYMLINK_SUB_DIR) != NULL) { + removeNIUnderDirs(path); + } else { + if (isDirectory(path)) { + if (!removeAll(path.c_str())) { + _SERR("Failed to remove app ni dir [%s]", path.c_str()); + } } } } -- 2.7.4