Fixed the segmentation fault in dotnettool (#437)
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / dotnettool.cc
index 6697960..4343b49 100644 (file)
@@ -17,6 +17,8 @@
 #include "utils.h"
 #include "ni_common.h"
 #include "tac_common.h"
+#include "profile_common.h"
+#include "privilege_common.h"
 #include "multi_target_resolver.h"
 #include "log.h"
 
@@ -53,17 +55,27 @@ void DisplayUsage() {
                "                                   (this option should be run as root)\n"
                "       --rm-all-app-profile      - Remove application profile of all packages for all users\n"
                "                                   (this option should be run as root)\n"
+               "       --check-all-app-privilege - Chcek application privilege of all package\n"
+               "                                   (this option should be run as root)\n"
                "\n"
                "Options:\n"
-               "       --ibc-dir                 - Specify a directory containing IBC files\n"
+               "       --mibc                    - Specify Mibc files. Sepatated with ':'.\n"
                "       --verbose                 - Display verbose information\n"
-               "       --inputbubble             - Use inputbubble (run with --crossgen2 option)\n"
-               "       --inputbubbleref          - Path of references for inputbubble\n"
-               "                                   (If not set, all references are included to inputbubble.)\n"
-               "       --ref                     - Path of references\n"
-               "                                   (If not set, default system paths are used.)\n"
-               "       --no-pipeline             - Compile the dlls individually (run with --crossgen2 option)\n"
+               "       --inputbubble             - Compile input assemblies into one bubble with the assemblies described at --inputbubbleref option\n"
+               "                                   Note!: If you do not have an accurate understanding of Bubble, do not use this option.\n"
+               "                                          All assemblies in the bubble must be guaranteed to be compiled to the native image before execution.\n"
+               "                                          If an uncompiled assembly is included in the bubble during execution, an unknown error may occur.\n"
+               "                                          If --inputbubbleref option doesnot be set, only input files are included to bubble. \n"
+               "       --inputbubbleref          - Input bubble reference file(s) to be added to bubble (used with --inputbubble option)\n"
+               "       --ref                     - Reference file(s) for compilation\n"
+               "                                   (system paths are set automatically.)\n"
+               "       --no-pipeline             - Compile the dlls individually\n"
                "       --print-cmd               - Print command and options\n"
+               "       --skip-ro-app             - Skip re-generate NI for apps installed RO area\n"
+               "                                   (This option works with --ni-regen-all-app only)\n"
+               "       --rm-origin-after-ni      - Remove original dll after creating native image\n"
+               "                                   Note!: App ATOC options(--ni-pkg, --ni-regen-all-app, --tac-regen-all) cannot be used with --rm-origin-after-ni option.\n"
+               "                                   (Use only for assemblies that will not be AOTed again afterward.)"
                "\n"
                "Usage: dotnettool [options] [command] [arguments]\n"
                "\n"
@@ -76,8 +88,8 @@ void DisplayUsage() {
                "   # dotnettool --ni-pkg org.tizen.FormsGallery\n"
                "4. Regenerate native images for all installed .net packages\n"
                "   # dotnettool --ni-regen-all-app\n"
-               "5. Create native image for dll based on the IBC data\n"
-               "   # dotnettool --ibc-dir /tmp/ibcdata/ --ni-dll /usr/bin/Tizen.Runtime.dll\n"
+               "5. Create native image for dll based on the Mibc data\n"
+               "   # dotnettool --mibc /tmp/ibcdata/in.mibc --ni-dll /usr/bin/Tizen.Runtime.dll\n"
                "6. Remove profile for package\n"
                "   # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
                "\n");
@@ -120,10 +132,14 @@ int main(int argc, char* argv[])
                        opt->flags |= NI_FLAGS_NO_PIPELINE;
                } else if (arg == "--print-cmd") {
                        opt->flags |= NI_FLAGS_PRINT_CMD;
-               } else if (arg == "--ibc-dir") {
+               } else if (arg == "--skip-ro-app") {
+                       opt->flags |= NI_FLAGS_SKIP_RO_APP;
+               }  else if (arg == "--rm-origin-after-ni") {
+                       opt->flags |= NI_FLAGS_RM_ORIGIN_AFTER_NI;
+               } else if (arg == "--mibc") {
                        ++i;
                        if (i >= argc) {
-                               _SOUT("Directory path containing IBC files should be followed for --ibc-dir option");
+                               _SOUT("File path containing Mibc files should be followed for --mibc option");
                                DisplayUsage();
                                return 0;
                        }
@@ -133,8 +149,8 @@ int main(int argc, char* argv[])
                        std::vector<std::string> paths;
                        splitPath(std::string(argv[i]), paths);
                        for (const auto &path : paths) {
-                               if (!isDirectory(path)) {
-                                       _SERR("mibc path is missing or not exist");
+                               if (!isFile(path) || isDirectory(path)) {
+                                       _SERR("Mibc file path is missing or does not exist");
                                        return -1;
                                }
                                opt->mibcPath.push_back(path);
@@ -149,14 +165,10 @@ int main(int argc, char* argv[])
 
                        opt->flags |= NI_FLAGS_INPUT_BUBBLE_REF;
 
-                       std::vector<std::string> paths;
-                       splitPath(std::string(argv[i]), paths);
-                       for (const auto &path : paths) {
-                               if (!isDirectory(path)) {
-                                       _SERR("intpubbubbleref path is missing or not exist");
-                                       return -1;
-                               }
-                               opt->inputBubbleRefPath.push_back(path);
+                       std::vector<std::string> files;
+                       splitPath(std::string(argv[i]), files);
+                       for (const auto &f : files) {
+                               opt->inputBubbleRefFiles.push_back(f);
                        }
                } else if (arg == "--ref") {
                        ++i;
@@ -166,22 +178,28 @@ int main(int argc, char* argv[])
                                return 0;
                        }
 
-                       opt->flags |= NI_FLAGS_REF;
-
-                       std::vector<std::string> paths;
-                       splitPath(std::string(argv[i]), paths);
-                       for (const auto &path : paths) {
-                               if (!isDirectory(path)) {
-                                       _SERR("ref path is missing or not exist");
-                                       return -1;
-                               }
-                               opt->refPath.push_back(path);
+                       std::vector<std::string> files;
+                       splitPath(std::string(argv[i]), files);
+                       for (const auto &f : files) {
+                               opt->refFiles.push_back(f);
                        }
                } else {
                        args.push_back(arg);
                }
        }
 
+       if (args.size() == 0) {
+               _SERR("The command is missing");
+               DisplayUsage();
+               return -1;
+       }
+
+       if (opt->flags & NI_FLAGS_INPUT_BUBBLE_REF && !(opt->flags & NI_FLAGS_INPUT_BUBBLE)) {
+               _SERR("--inputbubbleref option should be used with --inputbubble option");
+               DisplayUsage();
+               return -1;
+       }
+
        if (initNICommon() != NI_ERROR_NONE) {
                return -1;
        }
@@ -190,9 +208,15 @@ int main(int argc, char* argv[])
        std::string cmd = std::string(*it);
        it = args.erase(it);
 
-       //sh-3.2# dotnettool --ni-system
+       //sh-3.2# dotnettool --ni-system [AssemblyDirectory] [AssemblyDirectory] ...
        if (cmd == "--ni-system") {
-               int ret = createNIPlatform(opt);
+               std::string inputs;
+               while (it != args.end()) {
+                       const std::string dir = std::string(*it);
+                       inputs = inputs + ":" + dir;
+                       it = args.erase(it);
+               }
+               int ret = createNIPlatform(inputs, opt);
                if (ret != NI_ERROR_NONE) {
                        _SERR("Failed to generate system NI");
                }
@@ -202,18 +226,33 @@ int main(int argc, char* argv[])
                if (args.size() < 1) {
                        _SERR("DLL path is missing");
                }
+               std::vector<std::string> inputs;
                while (it != args.end()) {
                        std::string dll = std::string(*it);
+                       inputs.push_back(dll);
+                       opt->refFiles.push_back(dll);
+                       if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
+                               opt->inputBubbleRefFiles.push_back(dll);
+                       }
+                       it = args.erase(it);
+               }
+
+               for (auto &dll : inputs) {
                        int ret = createNIDll(dll, opt);
-                       if (ret != NI_ERROR_NONE) {
+                       if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
                                _SERR("Failed to generate NI file [%s]", dll.c_str());
                                break;
                        }
-                       it = args.erase(it);
                }
        }
        //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
        else if (cmd == "--ni-pkg") {
+               if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+                       DisplayUsage();
+                       return -1;
+               }
+
                if (args.size() < 1) {
                        _SERR("Package name is missing");
                }
@@ -232,15 +271,17 @@ int main(int argc, char* argv[])
                if (args.size() < 1) {
                        _SERR("Directory path is missing");
                }
+               std::string dir;
                while (it != args.end()) {
-                       const std::string dir = std::string(*it);
-                       int ret = createNIUnderDirs(dir, opt);
-                       if (ret != NI_ERROR_NONE) {
-                               _SERR("Failed to generate NI directory");
-                               break;
+                       if (!dir.empty()) {
+                               dir += std::string(":");
                        }
+                       dir += std::string(*it);
                        it = args.erase(it);
                }
+               if (createNIUnderDirs(dir, opt) != NI_ERROR_NONE) {
+                       _SERR("Failed to generate NI directory");
+               }
        }
        //sh-3.2# dotnettool --ni-reset-system
        else if (cmd == "--ni-reset-system") {
@@ -274,6 +315,12 @@ int main(int argc, char* argv[])
        }
        //sh-3.2# dotnettool --ni-regen-all-app
        else if (cmd == "--ni-regen-all-app") {
+               if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+                       DisplayUsage();
+                       return -1;
+               }
+
                int ret = regenerateAppNI(opt);
                if (ret != NI_ERROR_NONE) {
                        _SERR("Failed to regenerate all app NI");
@@ -281,6 +328,12 @@ int main(int argc, char* argv[])
        }
        //sh-3.2# dotnettool --tac-regen-all
        else if (cmd == "--tac-regen-all") {
+               if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+                       DisplayUsage();
+                       return -1;
+               }
+
                int ret = regenerateTACNI(opt);
                if (ret != NI_ERROR_NONE) {
                        _SERR("Failed to regenerate all TAC");
@@ -341,7 +394,7 @@ int main(int argc, char* argv[])
                }
                while (it != args.end()) {
                        std::string pkg = std::string(*it);
-                       if (removeAppProfileData(pkg) != NI_ERROR_NONE) {
+                       if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) {
                                _SERR("Failed to remove [%s] profile data", pkg.c_str());
                        }
                        it = args.erase(it);
@@ -351,6 +404,10 @@ int main(int argc, char* argv[])
        else if (cmd == "--rm-all-app-profile") {
                removeAllAppProfileData();
        }
+       //sh-3.2# dotnettool --check-all-app-privilege
+       else if (cmd == "--check-all-app-privilege") {
+               checkAllAppPrivilege();
+       }
        else {
                _SERR("Unknown option [%s]", cmd.c_str());
                DisplayUsage();