2 * Copyright (c) 2019 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"
19 #include "tac_common.h"
20 #include "multi_target_resolver.h"
28 #include <app_common.h>
33 "Dotnet Tool Version: 1.0\n"
36 " -h, --help - Show this help message\n"
37 " --ni-system - Create NI under System DLLs\n"
38 " --ni-dll - Create NI for DLL\n"
39 " --ni-pkg - Create NI for package\n"
40 " (If package is installed under RO area, NI files are generated under RW area)\n"
41 " --ni-dir - Create NI for directory\n"
42 " --ni-reset-system - Remove System NI files\n"
43 " --ni-reset-pkg - Remove App NI files\n"
44 " --ni-reset-dir - Remove NI for directory\n"
45 " --ni-regen-all-app - Re-generate All App NI files\n"
46 " --tac-regen-all - Re-generate All TAC files\n"
47 " --tac-restore-db - Restore TAC Database\n"
48 " --tac-disable-pkg - Disable TAC for package\n"
49 " --tac-enable-pkg - Enable TAC for package\n"
50 " --resolve-all-app - Remove unused multi-targeting files of all apps\n"
51 " (this option is used for FOTA script or test)\n"
52 " --rm-app-profile - Remove application profile of given packages for all users\n"
53 " (this option should be run as root)\n"
54 " --rm-all-app-profile - Remove application profile of all packages for all users\n"
55 " (this option should be run as root)\n"
58 " --ibc-dir - Specify a directory containing IBC files\n"
59 " --verbose - Display verbose information\n"
60 " --inputbubble - Use inputbubble\n"
61 " --inputbubbleref - Path of references for inputbubble (used with --inputbubble option)\n"
62 " (If not set, all references are included to inputbubble.)\n"
63 " --ref - Path of references\n"
64 " (If not set, default system paths are used.)\n"
65 " --no-pipeline - Compile the dlls individually\n"
66 " --print-cmd - Print command and options\n"
68 "Usage: dotnettool [options] [command] [arguments]\n"
71 "1. Create native image for dlls and exes under platform directories\n"
72 " # dotnettool --ni-system\n"
73 "2. Create native image for dll\n"
74 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
75 "3. Create native image under the package's bin and lib directory\n"
76 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
77 "4. Regenerate native images for all installed .net packages\n"
78 " # dotnettool --ni-regen-all-app\n"
79 "5. Create native image for dll based on the IBC data\n"
80 " # dotnettool --ibc-dir /tmp/ibcdata/ --ni-dll /usr/bin/Tizen.Runtime.dll\n"
81 "6. Remove profile for package\n"
82 " # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
86 int main(int argc, char* argv[])
94 gettimeofday(&tv, NULL);
95 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
102 NIOption* opt = getNIOption();
103 if (opt == nullptr) {
104 _SERR("Fail to create option structure.");
108 std::vector<std::string> args;
109 for (int i = 0; i < argc; ++i) {
110 std::string arg = argv[i];
112 if ((arg == "-?") || (arg == "-h") || (arg == "--h")) {
115 } else if (arg == "--verbose") {
116 opt->flags |= NI_FLAGS_VERBOSE;
117 } else if (arg == "--inputbubble") {
118 opt->flags |= NI_FLAGS_INPUT_BUBBLE;
119 } else if (arg == "--no-pipeline") {
120 opt->flags |= NI_FLAGS_NO_PIPELINE;
121 } else if (arg == "--print-cmd") {
122 opt->flags |= NI_FLAGS_PRINT_CMD;
123 } else if (arg == "--ibc-dir") {
126 _SOUT("Directory path containing IBC files should be followed for --ibc-dir option");
131 opt->flags |= NI_FLAGS_MIBC;
133 std::vector<std::string> paths;
134 splitPath(std::string(argv[i]), paths);
135 for (const auto &path : paths) {
136 if (!isDirectory(path)) {
137 _SERR("mibc path is missing or not exist");
140 opt->mibcPath.push_back(path);
142 } else if (arg == "--inputbubbleref") {
145 _SOUT("Path for references should be followed for --inputbubbleref option");
150 opt->flags |= NI_FLAGS_INPUT_BUBBLE_REF;
152 std::vector<std::string> paths;
153 splitPath(std::string(argv[i]), paths);
154 for (const auto &path : paths) {
155 if (!isDirectory(path)) {
156 _SERR("intpubbubbleref path is missing or not exist");
159 opt->inputBubbleRefPath.push_back(path);
161 } else if (arg == "--ref") {
164 _SOUT("Path for references should be followed for --ref option");
169 opt->flags |= NI_FLAGS_REF;
171 std::vector<std::string> paths;
172 splitPath(std::string(argv[i]), paths);
173 for (const auto &path : paths) {
174 if (!isDirectory(path)) {
175 _SERR("ref path is missing or not exist");
178 opt->refPath.push_back(path);
185 if (opt->flags & NI_FLAGS_INPUT_BUBBLE_REF && !(opt->flags & NI_FLAGS_INPUT_BUBBLE)) {
186 _SERR("--inputbubbleref option should be used with --inputbubble option");
191 if (initNICommon() != NI_ERROR_NONE) {
195 std::vector<std::string>::iterator it = args.begin();
196 std::string cmd = std::string(*it);
199 //sh-3.2# dotnettool --ni-system
200 if (cmd == "--ni-system") {
201 int ret = createNIPlatform(opt);
202 if (ret != NI_ERROR_NONE) {
203 _SERR("Failed to generate system NI");
206 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
207 else if (cmd == "--ni-dll") {
208 if (args.size() < 1) {
209 _SERR("DLL path is missing");
211 while (it != args.end()) {
212 std::string dll = std::string(*it);
213 int ret = createNIDll(dll, opt);
214 if (ret != NI_ERROR_NONE) {
215 _SERR("Failed to generate NI file [%s]", dll.c_str());
221 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
222 else if (cmd == "--ni-pkg") {
223 if (args.size() < 1) {
224 _SERR("Package name is missing");
226 while (it != args.end()) {
227 std::string pkg = std::string(*it);
228 int ret = createNIUnderPkgRoot(pkg, opt);
229 if (ret != NI_ERROR_NONE) {
230 _SERR("Failed to generate app NI [%s]", pkg.c_str());
236 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
237 else if (cmd == "--ni-dir") {
238 if (args.size() < 1) {
239 _SERR("Directory path is missing");
241 while (it != args.end()) {
242 const std::string dir = std::string(*it);
243 int ret = createNIUnderDirs(dir, opt);
244 if (ret != NI_ERROR_NONE) {
245 _SERR("Failed to generate NI directory");
251 //sh-3.2# dotnettool --ni-reset-system
252 else if (cmd == "--ni-reset-system") {
255 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
256 else if (cmd == "--ni-reset-pkg") {
257 if (args.size() < 1) {
258 _SERR("Package name is missing");
260 while (it != args.end()) {
261 std::string pkg = std::string(*it);
262 int ret = removeNIUnderPkgRoot(pkg);
263 if (ret != NI_ERROR_NONE) {
264 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
270 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
271 else if (cmd == "--ni-reset-dir") {
272 if (args.size() < 1) {
273 _SERR("Directory path is missing");
275 while (it != args.end()) {
276 const std::string dir = std::string(*it);
277 removeNIUnderDirs(dir);
281 //sh-3.2# dotnettool --ni-regen-all-app
282 else if (cmd == "--ni-regen-all-app") {
283 int ret = regenerateAppNI(opt);
284 if (ret != NI_ERROR_NONE) {
285 _SERR("Failed to regenerate all app NI");
288 //sh-3.2# dotnettool --tac-regen-all
289 else if (cmd == "--tac-regen-all") {
290 int ret = regenerateTACNI(opt);
291 if (ret != NI_ERROR_NONE) {
292 _SERR("Failed to regenerate all TAC");
295 //sh-3.2# dotnettool --tac-restore-db
296 else if (cmd == "--tac-restore-db") {
297 int ret = tac_restoreDB();
298 if (ret != TAC_ERROR_NONE) {
299 _SERR("Failed to restore TAC db");
301 ret = tlc_restoreDB();
302 if (ret != TAC_ERROR_NONE) {
303 _SERR("Failed to restore TLC db");
306 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
307 else if (cmd == "--tac-enable-pkg") {
308 if (args.size() < 1) {
309 _SERR("Package name is missing");
311 while (it != args.end()) {
312 std::string pkg = std::string(*it);
313 int ret = enableTACPackage(pkg);
314 if (ret != TAC_ERROR_NONE) {
315 _SERR("Failed to enable tac [%s]", pkg.c_str());
321 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
322 else if (cmd == "--tac-disable-pkg") {
323 if (args.size() < 1) {
324 _SERR("Package name is missing");
326 while (it != args.end()) {
327 std::string pkg = std::string(*it);
328 int ret = disableTACPackage(pkg);
329 if (ret != TAC_ERROR_NONE) {
330 _SERR("Failed to disable tac [%s]", pkg.c_str());
336 //sh-3.2# dotnettool --resolve-all-app
337 else if (cmd == "--resolve-all-app") {
338 int ret = resolveAllApps();
340 _SERR("Failed to remove unused multi-targeting files");
343 //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
344 else if (cmd == "--rm-app-profile") {
345 if (args.size() < 1) {
346 _SERR("Package name is missing");
348 while (it != args.end()) {
349 std::string pkg = std::string(*it);
350 if (removeAppProfileData(pkg) != NI_ERROR_NONE) {
351 _SERR("Failed to remove [%s] profile data", pkg.c_str());
356 //sh-3.2# dotnettool --rm-all-app-profile
357 else if (cmd == "--rm-all-app-profile") {
358 removeAllAppProfileData();
361 _SERR("Unknown option [%s]", cmd.c_str());
367 gettimeofday(&tv, NULL);
368 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
369 _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));