add nitool option to generate ni for directory 72/177172/1
authorCho Woong Suk <ws77.cho@samsung.com>
Thu, 26 Apr 2018 05:31:38 +0000 (14:31 +0900)
committerCho Woong Suk <ws77.cho@samsung.com>
Thu, 26 Apr 2018 05:31:38 +0000 (14:31 +0900)
Change-Id: I22f41e6fbb80e91044c144dd27747a969d27dce4

NativeLauncher/installer-plugin/common.cc
NativeLauncher/installer-plugin/common.h
NativeLauncher/installer-plugin/nitool.cc

index 7d826db..eedb0bc 100644 (file)
@@ -297,7 +297,7 @@ void createNiPlatform()
 
        createNiUnderDirs(platformDirs, 3, [](const char* ni) {
                smack_(ni, "_");
-       });
+       }, false);
 }
 
 void createNiSelect(const char* dllPath)
@@ -317,13 +317,15 @@ void createNiSelect(const char* dllPath)
                                }
                                smack_(niPath.c_str(), "_");
                        }
-               }
-               else
+               } else {
                        printf("Already [%s] file is exist\n", niPath.c_str());
+               }
+       } else {
+               printf("Failed to find dll : %s", dllPath);
        }
 }
 
-void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb)
+void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb, bool update)
 {
        std::string appPaths;
        for (int i = 0; i < count; i++) {
@@ -334,38 +336,48 @@ void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[]
        if (appPaths.back() == ':')
                appPaths.pop_back();
 
-       auto convert = [&appPaths, ignores, igcount, &cb](const char* path, const char* name) {
+       auto convert = [&appPaths, ignores, igcount, &cb, update](const char* path, const char* name) {
                for (int i = 0; i < igcount; i++) {
                        if (strcmp(path, ignores[i]) == 0)
                                return;
                }
-               std::string ni;
-               if (isManagedAssembly(path) && !isNativeImage(path) && !niExist(path, ni)) {
+               std::string niPath;
+               if (isManagedAssembly(path) && !isNativeImage(path)) {
+                       if (niExist(path, niPath)) {
+                               if (update && !niPath.empty()) {
+                                       _INFO("override [%s] file", niPath.c_str());
+                               } else {
+                                       _INFO("Already [%s] file is exist", niPath.c_str());
+                                       return;
+                               }
+                       }
                        crossgen(path, appPaths.c_str());
-                       if (niExist(path, ni)) {
+                       if (niExist(path, niPath)) {
                                // change owner and groups for generated ni file.
                                struct stat info;
                                if (!stat(path, &info)) {
-                                       if (chown(ni.c_str(), info.st_uid, info.st_gid) == -1)
+                                       if (chown(niPath.c_str(), info.st_uid, info.st_gid) == -1)
                                                _ERR("Failed to change owner and group name");
                                }
 
                                if (cb != nullptr)
-                                       cb(ni.c_str());
+                                       cb(niPath.c_str());
+                       } else {
+                               _INFO("Failed to create native image for %s", path);
                        }
                }
        };
 
        for (int i = 0; i < count; i++)
-               scanFilesInDir(rootPaths[i], convert, -1);
+               scanFilesInDir(rootPaths[i], convert, 1);
 }
-void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb)
+void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb, bool update)
 {
-       createNiUnderDirs(rootPaths, count, nullptr, 0, cb);
+       createNiUnderDirs(rootPaths, count, nullptr, 0, cb, update);
 }
-void createNiUnderDirs(const char* rootPaths[], int count)
+void createNiUnderDirs(const char* rootPaths[], int count, bool update)
 {
-       createNiUnderDirs(rootPaths, count, nullptr);
+       createNiUnderDirs(rootPaths, count, nullptr, update);
 }
 
 int removeNiUnderPkgRoot(const char* pkgName)
@@ -425,7 +437,7 @@ int createNiUnderPkgRoot(const char* pkgName)
                                _INFO("sleep %d usec", interval);
                                usleep(interval);
                        }
-       });
+       }, true);
 
        return 0;
 }
index 941f5b1..8914e4b 100644 (file)
@@ -20,9 +20,9 @@
 #include <functional>
 
 typedef std::function<void (const char*)> afterCreate;
-void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb);
-void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb);
-void createNiUnderDirs(const char* rootPaths[], int count);
+void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb, bool update);
+void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb, bool update);
+void createNiUnderDirs(const char* rootPaths[], int count, bool update);
 int createNiUnderPkgRoot(const char* pkgName);
 void createNiPlatform();
 void createNiSelect(const char* dllPath);
index 081d638..9cd390c 100644 (file)
@@ -45,6 +45,7 @@ static void help(const char *argv0)
                "               --system                - Create NI under System DLLs\n"
                "               --dll                   - Create NI for DLL\n"
                "               --pkg                   - Create NI for package\n"
+               "               --dir                   - Create NI for directory\n"
                "               --reset-system  - Remove System NI files\n"
                "               --reset-pkg             - Remove App NI files\n"
                "\n"
@@ -62,6 +63,7 @@ int main(int argc, char* argv[])
 {
        bool pkgMode = false;
        bool dllMode = false;
+       bool dirMode = false;
        bool rmPkgMode = false;
 
        if (cmdOptionExists(argv, argv+argc, "--help")) {
@@ -74,6 +76,8 @@ int main(int argc, char* argv[])
                dllMode = true;
        } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
                pkgMode = true;
+       } else if (cmdOptionExists(argv, argv+argc, "--dir")) {
+               dirMode = true;
        } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
                removeNiPlatform();
                return 0;
@@ -112,8 +116,8 @@ int main(int argc, char* argv[])
        } else if (dllMode) {
                for (const char* dll : args)
                        createNiSelect(dll);
-       } else {
-               createNiUnderDirs(args.data(), args.size());
+       } else if (dirMode) {
+               createNiUnderDirs(args.data(), args.size(), false);
        }
 
        return 0;