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 "Usage: %s [args] <root paths or pkg name>\n"
40 " --help - Display this screen\n"
41 " --system - Create NI under System DLLs\n"
42 " --dll - Create NI for DLL\n"
43 " --pkg - Create NI for package\n"
44 " --dir - Create NI for directory\n"
45 " --r2r - Use ready-to-run option (default: FNV)\n"
46 " (This option should be used with other options)\n"
47 " --reset-system - Remove System NI files\n"
48 " --reset-pkg - Remove App NI files\n"
49 " --regen-all-app - Re-generate All App NI files\n"
52 "1. Create native image for dlls and exes under platform directories\n"
54 "2. Create native image for dll\n"
55 " # %s --dll /usr/bin/Tizen.Runtime.dll\n"
56 "3. Create native image under the package's bin and lib directory\n"
57 " # %s --pkg org.tizen.FormsGallery\n"
58 "4. Regenerate native images for all installed .net packages with ready-to-run option\n"
59 " # %s --r2r --regen-all-app\n\n";
60 printf(helpDesc, argv0, argv0, argv0, argv0, argv0);
63 int main(int argc, char* argv[])
68 bool rmPkgMode = false;
69 bool enableR2R = false;
70 bool pkgDllMode = false;
72 NiCommonOption option = {std::string(), std::string(), std::string()};
73 if (initNICommon(&option) < 0) {
74 fprintf(stderr, "Fail to initialize NI Common\n");
78 if (cmdOptionExists(argv, argv+argc, "--r2r")) {
82 if (cmdOptionExists(argv, argv+argc, "--help")) {
85 } else if (cmdOptionExists(argv, argv+argc, "--system")) {
86 createNiPlatform(enableR2R);
88 } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
90 } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
92 } else if (cmdOptionExists(argv, argv+argc, "--dir")) {
94 } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
97 } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
99 } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
100 regenerateAppNI(enableR2R);
102 } else if (cmdOptionExists(argv, argv+argc, "--pkg-dll")) {
109 std::vector<std::string> args = getCmdArgs(argv, argv+argc);
111 if (args.size() < 1) {
113 fprintf(stderr, "Package name is missed\n");
115 fprintf(stderr, "DLL path is missed\n");
121 for (const std::string pkg : args) {
122 if (createNiUnderPkgRoot(pkg, enableR2R) != 0) {
123 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
127 } else if (pkgDllMode) {
128 if (createNiDllUnderPkgRoot(args[0], args[1], enableR2R) != 0) {
129 fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str());
132 } else if (rmPkgMode) {
133 for (const std::string pkg : args) {
134 if (removeNiUnderPkgRoot(pkg) != 0) {
135 fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
139 } else if (dllMode) {
140 for (const std::string dll : args) {
141 if (createNiDll(dll, enableR2R) != 0) {
142 fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
145 } else if (dirMode) {
146 createNiUnderDirs(args.data(), args.size(), enableR2R);