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[])
50 bool rmPkgMode = false;
51 bool enableR2R = false;
52 bool pkgDllMode = false;
54 NiCommonOption option = {std::string(), std::string(), std::string()};
55 if (initNICommon(&option) != NI_ERROR_NONE) {
56 fprintf(stderr, "Fail to initialize NI Common\n");
60 if (cmdOptionExists(argv, argv+argc, "--r2r")) {
64 if (cmdOptionExists(argv, argv+argc, "--help")) {
67 } else if (cmdOptionExists(argv, argv+argc, "--system")) {
68 createNiPlatform(enableR2R);
70 } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
72 } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
74 } else if (cmdOptionExists(argv, argv+argc, "--dir")) {
76 } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
79 } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
81 } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
82 regenerateAppNI(enableR2R);
84 } else if (cmdOptionExists(argv, argv+argc, "--pkg-dll")) {
91 std::vector<std::string> args = getCmdArgs(argv, argv+argc);
93 if (args.size() < 1) {
95 fprintf(stderr, "Package name is missed\n");
97 fprintf(stderr, "DLL path is missed\n");
103 for (const std::string pkg : args) {
104 // if there is AOTed dlls under package root, that is skiped.
105 int ret = createNiUnderPkgRoot(pkg, enableR2R);
106 if (ret == NI_ERROR_INVALID_PACKAGE) {
107 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
109 } else if (ret != NI_ERROR_NONE) {
110 fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
114 } else if (pkgDllMode) {
115 int ret = createNiDllUnderPkgRoot(args[0], args[1], enableR2R);
116 if (ret == NI_ERROR_INVALID_PACKAGE) {
117 fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str());
119 } else if (ret == NI_ERROR_ALREADY_EXIST) {
120 // skip for already exist case
122 } else if (ret != NI_ERROR_NONE) {
123 fprintf(stderr, "Failed to generate NI file [%s]\n", args[1].c_str());
126 } else if (rmPkgMode) {
127 for (const std::string pkg : args) {
128 int ret = removeNiUnderPkgRoot(pkg);
129 if (ret == NI_ERROR_INVALID_PACKAGE) {
130 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
132 } else if (ret != NI_ERROR_NONE) {
133 fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
137 } else if (dllMode) {
138 // donot return error code for generation failure.
139 // we have to run crossgen for all input dlls.
140 for (const std::string dll : args) {
141 int ret = createNiDll(dll, enableR2R);
142 if (ret == NI_ERROR_ALREADY_EXIST) {
143 // skip for already exist case
144 } else if (ret != NI_ERROR_NONE) {
145 fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
148 } else if (dirMode) {
149 createNiUnderDirs(args.data(), args.size(), enableR2R);