[Refactoring] Code cleanup and remove duplicate methods
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / dotnettool.cc
index 7844988..eac0f2a 100644 (file)
@@ -74,8 +74,10 @@ void DisplayUsage() {
                "       --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!: --ni-pkg option doesnot support --rm-origin-after-ni option.\n"
-               "                                   (Use only for assemblies that will not be AOTed again afterward.)"
+               "                                   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"
+               "       --set-priority            - Sets the priority of the process to the specified values from -20(highest priority) to 19(lowest priority).(default : 0)\n"
+
                "\n"
                "Usage: dotnettool [options] [command] [arguments]\n"
                "\n"
@@ -136,6 +138,23 @@ int main(int argc, char* argv[])
                        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 == "--set-priority") {
+                       ++i;
+                       if (i >= argc) {
+                               _SOUT("Priority value(-20 ~ 19) should be followed for --set-priority option");
+                               DisplayUsage();
+                               return 0;
+                       }
+
+                       opt->flags |= NI_FLAGS_SET_PRIORITY;
+                       try {
+                               opt->priority = std::stoi(argv[i]);
+                               setPriority(opt);
+                       } catch (...) {
+                               _SERR("Invalid argument: %s", argv[i]);
+                               DisplayUsage();
+                               return 0;
+                       }
                } else if (arg == "--mibc") {
                        ++i;
                        if (i >= argc) {
@@ -188,6 +207,12 @@ int main(int argc, char* argv[])
                }
        }
 
+       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();
@@ -242,7 +267,7 @@ int main(int argc, char* argv[])
        //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
        else if (cmd == "--ni-pkg") {
                if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
-                       _SERR("--ni-pkg option doesnot support --rm-origin-after-ni option");
+                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
                        DisplayUsage();
                        return -1;
                }
@@ -309,6 +334,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");
@@ -316,6 +347,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");
@@ -364,10 +401,7 @@ int main(int argc, char* argv[])
        }
        //sh-3.2# dotnettool --resolve-all-app
        else if (cmd == "--resolve-all-app") {
-               int ret = resolveAllApps();
-               if (ret != 0) {
-                       _SERR("Failed to remove unused multi-targeting files");
-               }
+               resolveAllApps();
        }
        //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
        else if (cmd == "--rm-app-profile") {
@@ -399,7 +433,9 @@ int main(int argc, char* argv[])
 
        gettimeofday(&tv, NULL);
        endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-       _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));
+       int ms = (int)(endtime - starttime);
+       float sec = (float)(ms/1000);
+       _SOUT("\nSpend time for dotnettool is [%d]ms, [%.3f]sec", ms, sec);
 
        return 0;
 }