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[])
55 bool rmPkgMode = false;
57 if (initNICommon() != NI_ERROR_NONE) {
61 // Parse optional switches first.
62 if (cmdOptionExists(argv, argv+argc, "--r2r")) {
63 flags |= NI_FLAGS_ENABLER2R;
65 if (cmdOptionExists(argv, argv+argc, "--compatibility")) {
66 flags |= NI_FLAGS_COMPATIBILITY;
68 if (cmdOptionExists(argv, argv+argc, "--instrument")) {
69 flags |= NI_FLAGS_INSTRUMENT;
71 if (cmdOptionExists(argv, argv+argc, "--verbose")) {
72 flags |= NI_FLAGS_VERBOSE;
75 // The following commands are mutually exclusive.
76 if (cmdOptionExists(argv, argv+argc, "--help")) {
79 } else if (cmdOptionExists(argv, argv+argc, "--system")) {
80 createNIPlatform(flags);
82 } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
84 } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
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);
99 std::vector<std::string> args = getCmdArgs(argv, argv+argc);
101 if (args.size() < 1) {
103 _SERR("Package name is missing.");
105 _SERR("DLL path is missing.");
111 for (const std::string pkg : args) {
112 // if there is AOTed dlls under package root, that is skiped.
113 int ret = createNIUnderPkgRoot(pkg, flags);
114 if (ret == NI_ERROR_INVALID_PACKAGE) {
115 _SERR("Failed to get root path from [%s]", pkg.c_str());
117 } else if (ret != NI_ERROR_NONE) {
118 _SERR("Failed to generate NI file [%s]", pkg.c_str());
122 } else if (rmPkgMode) {
123 for (const std::string pkg : args) {
124 int ret = removeNIUnderPkgRoot(pkg);
125 if (ret == NI_ERROR_INVALID_PACKAGE) {
126 _SERR("Failed to get root path from [%s]", pkg.c_str());
128 } else if (ret != NI_ERROR_NONE) {
129 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
133 } else if (dllMode) {
134 // donot return error code for generation failure.
135 // we have to run crossgen for all input dlls.
136 for (const std::string dll : args) {
137 int ret = createNIDll(dll, flags);
138 if (ret == NI_ERROR_ALREADY_EXIST) {
139 // skip for already exist case
140 } else if (ret != NI_ERROR_NONE) {
141 _SERR("Failed to generate NI file [%s]", dll.c_str());