Fix build error for upgrading toolchain
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / nitool.cc
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "common.h"
18
19 #include <cstdio>
20 #include <cstring>
21
22 #include <algorithm>
23 #include <vector>
24
25 std::vector<const char*> get_cmd_args(char** begin, char** end)
26 {
27   for (char** itr = end-1; itr != begin-1; --itr)
28   {
29     if (itr != end && strncmp(*itr, "--", 2) == 0)
30     {
31       itr++;
32       int len = end - itr;
33       return std::vector<const char*>(len, *itr);
34     }
35   }
36   return std::vector<const char*>(end-begin-1, *(begin+1));
37 }
38
39 bool cmd_option_exists(char** begin, char** end, const std::string& option)
40 {
41   return std::find(begin, end, option) != end;
42 }
43
44 static void help(const char *argv0)
45 {
46   const char* helpdesc = 
47     "Usage: %s [args] <root paths or pkg name>\n"
48     "      --help       - Display this screen\n"
49     "      --system     - Create NI under System DLLs\n"
50     "      --dll        - Create NI for DLL\n"
51     "      --pkg        - Create NI for package\n"
52     "\n"
53     "Example:\n"
54     "Create native image for dlls and exes under platform directories\n"
55     "%s --system\n"
56     "Create native image for dll\n"
57     "%s --dll /usr/bin/Tizen.Runtime.Coreclr.dll\n"
58     "Create native image under the package's bin and lib directory\n"
59     "%s --pkg org.tizen.FormsGallery\n\n";
60   printf(helpdesc, argv0, argv0, argv0, argv0);
61 }
62
63 int main(int argc, char* argv[])
64 {
65   bool pkg_mode = false;
66   bool dll_mode = false;
67
68   if (cmd_option_exists(argv, argv+argc, "--help"))
69   {
70     help(argv[0]);
71     return 0;
72   }
73
74   if (cmd_option_exists(argv, argv+argc, "--system"))
75   {
76     create_ni_platform();
77     return 0;
78   }
79
80   if (cmd_option_exists(argv, argv+argc, "--dll"))
81   {
82     dll_mode = true;
83   }
84
85   if (cmd_option_exists(argv, argv+argc, "--pkg"))
86   {
87     pkg_mode = true;
88   }
89
90   std::vector<const char*> args = get_cmd_args(argv, argv+argc);
91
92   if (args.size() < 1)
93   {
94     if (pkg_mode)
95       fprintf(stderr, "Package name is missed\n");
96     else if (dll_mode)
97       fprintf(stderr, "DLL path is missed\n");
98     help(argv[0]);
99     return 1;
100   }
101
102   if (pkg_mode)
103   {
104     for (const char* pkg : args)
105     {
106       if (create_ni_under_pkg_root(pkg) != 0)
107       {
108         fprintf(stderr, "Failed to get root path from [%s]\n", pkg);
109         return 1;
110       }
111     }
112   }
113   else if (dll_mode)
114   {
115     for (const char* dll : args)
116     {
117       create_ni_select(dll);
118     }
119   }
120   else
121   {
122     create_ni_under_dirs(args.data(), args.size());
123   }
124
125   return 0;
126 }