From 2a82282f990eed71d26a547519d0656fd9351dde Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Wed, 9 Feb 2022 14:38:17 +0900 Subject: [PATCH] Fix app's native image existence checking code. (#376) The directory ".native_image" was not considered for app's native image existence cheching. --- NativeLauncher/tool/ni_common.cc | 76 +++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index c4b535a..7c146b7 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -111,23 +111,6 @@ static void waitInterval() } } -static std::string getNIFilePath(const std::string& dllPath) -{ - size_t index = dllPath.find_last_of("."); - if (index == std::string::npos) { - _SERR("File doesnot contain extension. fail to get NI file name"); - return ""; - } - std::string fName = dllPath.substr(0, index); - std::string fExt = dllPath.substr(index, dllPath.length()); - - // crossgen generate file with lower case extension only - std::transform(fExt.begin(), fExt.end(), fExt.begin(), ::tolower); - std::string niPath = fName + ".ni" + fExt; - - return niPath; -} - /** * @brief create the directory including parents directory, and * copy ownership and smack labels to the created directory. @@ -169,6 +152,23 @@ static bool createDirsAndCopyOwnerShip(std::string& target_path, const std::stri return true; } +static std::string getNIFilePath(const std::string& dllPath) +{ + size_t index = dllPath.find_last_of("."); + if (index == std::string::npos) { + _SERR("File doesnot contain extension. fail to get NI file name"); + return ""; + } + std::string fName = dllPath.substr(0, index); + std::string fExt = dllPath.substr(index, dllPath.length()); + + // crossgen generate file with lower case extension only + std::transform(fExt.begin(), fExt.end(), fExt.begin(), ::tolower); + std::string niPath = fName + ".ni" + fExt; + + return niPath; +} + static std::string getAppNIFilePath(const std::string& absDllPath, NIOption* opt) { std::string niDirPath; @@ -213,6 +213,20 @@ static bool checkNIExistence(const std::string& absDllPath) return false; } +static bool checkAppNIExistence(const std::string& absDllPath, NIOption* opt) +{ + std::string absNIPath = getAppNIFilePath(absDllPath, opt); + if (absNIPath.empty()) { + return false; + } + + if (isFile(absNIPath)) { + return true; + } + + return false; +} + static bool checkDllExistInDir(const std::string& path) { bool ret = false; @@ -249,6 +263,29 @@ static ni_error_e getTargetDllList(const std::string& path, std::vector& fileList, NIOption *opt) +{ + if (!isDirectory(path)) { + return NI_ERROR_INVALID_PARAMETER; + } + + auto func = [&fileList, opt](const std::string& f_path, const std::string& f_name) { + if (isManagedAssembly(f_path) && !checkAppNIExistence(f_path, opt)) { + fileList.push_back(getAbsolutePath(f_path)); + } + }; + + scanFilesInDirectory(path, func, 0); + + return NI_ERROR_NONE; +} + static void makeArgs(std::vector& args, const std::vector& refPaths, NIOption* opt) { args.push_back(CORERUN_CMD.c_str()); @@ -769,6 +806,11 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, NIOption* opt) if (ret != NI_ERROR_NONE) { return ret; } + } else if (opt->flags & NI_FLAGS_APPNI) { + ret = getAppTargetDllList(path, fileList, opt); + if (ret != NI_ERROR_NONE) { + return ret; + } } else { ret = getTargetDllList(path, fileList); if (ret != NI_ERROR_NONE) { -- 2.7.4