Fix app's native image existence checking code. (#376)
authorWoongsuk Cho <ws77.cho@samsung.com>
Wed, 9 Feb 2022 05:38:17 +0000 (14:38 +0900)
committerHyungju Lee <leee.lee@samsung.com>
Tue, 15 Feb 2022 00:51:16 +0000 (09:51 +0900)
The directory ".native_image" was not considered for app's native image existence cheching.

NativeLauncher/tool/ni_common.cc

index c4b535a..7c146b7 100644 (file)
@@ -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<std::str
        return NI_ERROR_NONE;
 }
 
+/*
+ * Get the list of managed files in the specific directory of Application
+ * Absolute paths of managed files are stored at the result list.
+ * If native image already exist in the .native_image directory, managed file is ignored.
+ *
+ */
+static ni_error_e getAppTargetDllList(const std::string& path, std::vector<std::string>& 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<const char*>& args, const std::vector<std::string>& 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) {