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 void help(const char *argv0)
38 const char* helpDesc =
39 "%s is deprecated. Please use dotnettool instead.\n"
41 " # dotnettool --help\n\n";
42 printf(helpDesc, argv0);
45 int main(int argc, char* argv[])
51 bool rmPkgMode = false;
52 bool pkgDllMode = false;
54 NiCommonOption option = {std::string(), std::string(), std::string()};
55 if (initNICommon(&option) != NI_ERROR_NONE) {
59 // Parse optional switches first.
60 if (cmdOptionExists(argv, argv+argc, "--r2r")) {
61 flags |= NI_FLAGS_ENABLER2R;
63 if (cmdOptionExists(argv, argv+argc, "--compatibility")) {
64 flags |= NI_FLAGS_COMPATIBILITY;
66 if (cmdOptionExists(argv, argv+argc, "--instrument")) {
67 flags |= NI_FLAGS_INSTRUMENT;
69 if (cmdOptionExists(argv, argv+argc, "--verbose")) {
70 flags |= NI_FLAGS_VERBOSE;
73 // The following commands are mutually exclusive.
74 if (cmdOptionExists(argv, argv+argc, "--help")) {
77 } else if (cmdOptionExists(argv, argv+argc, "--system")) {
78 createNiPlatform(flags);
80 } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
82 } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
84 } else if (cmdOptionExists(argv, argv+argc, "--dir")) {
86 } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
89 } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
91 } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
92 regenerateAppNI(flags);
94 } else if (cmdOptionExists(argv, argv+argc, "--pkg-dll")) {
101 std::vector<std::string> args = getCmdArgs(argv, argv+argc);
103 if (args.size() < 1) {
105 fprintf(stderr, "Package name is missing.\n");
107 fprintf(stderr, "DLL path is missing.\n");
113 for (const std::string pkg : args) {
114 // if there is AOTed dlls under package root, that is skiped.
115 int ret = createNiUnderPkgRoot(pkg, flags);
116 if (ret == NI_ERROR_INVALID_PACKAGE) {
117 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
119 } else if (ret != NI_ERROR_NONE) {
120 fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
124 } else if (pkgDllMode) {
125 int ret = createNiDllUnderPkgRoot(args[0], args[1], flags);
126 if (ret == NI_ERROR_INVALID_PACKAGE) {
127 fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str());
129 } else if (ret == NI_ERROR_ALREADY_EXIST) {
130 // skip for already exist case
132 } else if (ret != NI_ERROR_NONE) {
133 fprintf(stderr, "Failed to generate NI file [%s]\n", args[1].c_str());
136 } else if (rmPkgMode) {
137 for (const std::string pkg : args) {
138 int ret = removeNiUnderPkgRoot(pkg);
139 if (ret == NI_ERROR_INVALID_PACKAGE) {
140 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
142 } else if (ret != NI_ERROR_NONE) {
143 fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
147 } else if (dllMode) {
148 // donot return error code for generation failure.
149 // we have to run crossgen for all input dlls.
150 for (const std::string dll : args) {
151 int ret = createNiDll(dll, flags);
152 if (ret == NI_ERROR_ALREADY_EXIST) {
153 // skip for already exist case
154 } else if (ret != NI_ERROR_NONE) {
155 fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
158 } else if (dirMode) {
159 createNiUnderDirs(args.data(), args.size(), flags);