2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "ni_common.h"
26 std::vector<std::string> getCmdArgs(char** begin, char** end)
28 std::vector<std::string> list;
29 for (char** itr = begin+1; itr != end; itr++) {
30 if (strncmp(*itr, "--", 2) != 0)
36 static bool cmdOptionExists(char** begin, char** end, const std::string& option)
38 return std::find(begin, end, option) != end;
41 static void help(const char *argv0)
43 const char* helpDesc =
44 "%s is deprecated. Please use dotnettool instead.\n"
46 " # dotnettool --help\n\n";
47 printf(helpDesc, argv0);
50 int main(int argc, char* argv[])
56 bool rmPkgMode = false;
57 bool pkgDllMode = false;
59 NICommonOption option = {std::string(), std::string(), std::string()};
60 if (initNICommon(&option) != NI_ERROR_NONE) {
64 // Parse optional switches first.
65 if (cmdOptionExists(argv, argv+argc, "--r2r")) {
66 flags |= NI_FLAGS_ENABLER2R;
68 if (cmdOptionExists(argv, argv+argc, "--compatibility")) {
69 flags |= NI_FLAGS_COMPATIBILITY;
71 if (cmdOptionExists(argv, argv+argc, "--instrument")) {
72 flags |= NI_FLAGS_INSTRUMENT;
74 if (cmdOptionExists(argv, argv+argc, "--verbose")) {
75 flags |= NI_FLAGS_VERBOSE;
78 // The following commands are mutually exclusive.
79 if (cmdOptionExists(argv, argv+argc, "--help")) {
82 } else if (cmdOptionExists(argv, argv+argc, "--system")) {
83 createNIPlatform(flags);
85 } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
87 } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
89 } else if (cmdOptionExists(argv, argv+argc, "--dir")) {
91 } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
94 } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
96 } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
97 regenerateAppNI(flags);
99 } else if (cmdOptionExists(argv, argv+argc, "--pkg-dll")) {
106 std::vector<std::string> args = getCmdArgs(argv, argv+argc);
108 if (args.size() < 1) {
110 fprintf(stderr, "Package name is missing.\n");
112 fprintf(stderr, "DLL path is missing.\n");
118 for (const std::string pkg : args) {
119 // if there is AOTed dlls under package root, that is skiped.
120 int ret = createNIUnderPkgRoot(pkg, flags);
121 if (ret == NI_ERROR_INVALID_PACKAGE) {
122 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
124 } else if (ret != NI_ERROR_NONE) {
125 fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
129 } else if (pkgDllMode) {
130 int ret = createNIDllUnderPkgRoot(args[0], args[1], flags);
131 if (ret == NI_ERROR_INVALID_PACKAGE) {
132 fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str());
134 } else if (ret == NI_ERROR_ALREADY_EXIST) {
135 // skip for already exist case
137 } else if (ret != NI_ERROR_NONE) {
138 fprintf(stderr, "Failed to generate NI file [%s]\n", args[1].c_str());
141 } else if (rmPkgMode) {
142 for (const std::string pkg : args) {
143 int ret = removeNIUnderPkgRoot(pkg);
144 if (ret == NI_ERROR_INVALID_PACKAGE) {
145 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
147 } else if (ret != NI_ERROR_NONE) {
148 fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
152 } else if (dllMode) {
153 // donot return error code for generation failure.
154 // we have to run crossgen for all input dlls.
155 for (const std::string dll : args) {
156 int ret = createNIDll(dll, flags);
157 if (ret == NI_ERROR_ALREADY_EXIST) {
158 // skip for already exist case
159 } else if (ret != NI_ERROR_NONE) {
160 fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
163 } else if (dirMode) {
164 createNIUnderDirs(args.data(), args.size(), flags);