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[])
54 bool rmPkgMode = false;
56 if (initNICommon() != NI_ERROR_NONE) {
60 NIOption* opt = getNIOption();
62 _SERR("Fail to create option structure.");
66 // Parse optional switches first.
67 if (cmdOptionExists(argv, argv+argc, "--verbose")) {
68 opt->flags |= NI_FLAGS_VERBOSE;
71 // The following commands are mutually exclusive.
72 if (cmdOptionExists(argv, argv+argc, "--help")) {
75 } else if (cmdOptionExists(argv, argv+argc, "--system")) {
76 createNIPlatform("", opt->flags);
78 } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
80 } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
82 } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
85 } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
87 } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
88 regenerateAppNI(opt->flags);
95 std::vector<std::string> args = getCmdArgs(argv, argv+argc);
97 if (args.size() < 1) {
99 _SERR("Package name is missing.");
101 _SERR("DLL path is missing.");
107 for (const std::string pkg : args) {
108 // if there is AOTed dlls under package root, that is skiped.
109 int ret = createNIUnderPkgRoot(pkg, opt->flags);
110 if (ret == NI_ERROR_INVALID_PACKAGE) {
111 _SERR("Failed to get root path from [%s]", pkg.c_str());
113 } else if (ret != NI_ERROR_NONE) {
114 _SERR("Failed to generate NI file [%s]", pkg.c_str());
118 } else if (rmPkgMode) {
119 for (const std::string pkg : args) {
120 int ret = removeNIUnderPkgRoot(pkg);
121 if (ret == NI_ERROR_INVALID_PACKAGE) {
122 _SERR("Failed to get root path from [%s]", pkg.c_str());
124 } else if (ret != NI_ERROR_NONE) {
125 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
129 } else if (dllMode) {
130 // donot return error code for generation failure.
131 // we have to run crossgen for all input dlls.
132 for (const std::string dll : args) {
133 int ret = createNIDll(dll, opt->flags);
134 if (ret == NI_ERROR_ALREADY_EXIST) {
135 // skip for already exist case
136 } else if (ret != NI_ERROR_NONE) {
137 _SERR("Failed to generate NI file [%s]", dll.c_str());