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 "profile_common.h"
21 #include "privilege_common.h"
22 #include "multi_target_resolver.h"
30 #include <app_common.h>
35 "Dotnet Tool Version: 1.0\n"
38 " -h, --help - Show this help message\n"
39 " --ni-system - Create NI under System DLLs\n"
40 " --ni-dll - Create NI for DLL\n"
41 " --ni-pkg - Create NI for package\n"
42 " (If package is installed under RO area, NI files are generated under RW area)\n"
43 " --ni-dir - Create NI for directory\n"
44 " --ni-reset-system - Remove System NI files\n"
45 " --ni-reset-pkg - Remove App NI files\n"
46 " --ni-reset-dir - Remove NI for directory\n"
47 " --ni-regen-all-app - Re-generate All App NI files\n"
48 " --tac-regen-all - Re-generate All TAC files\n"
49 " --tac-restore-db - Restore TAC Database\n"
50 " --tac-disable-pkg - Disable TAC for package\n"
51 " --tac-enable-pkg - Enable TAC for package\n"
52 " --resolve-all-app - Remove unused multi-targeting files of all apps\n"
53 " (this option is used for FOTA script or test)\n"
54 " --rm-app-profile - Remove application profile of given packages for all users\n"
55 " (this option should be run as root)\n"
56 " --rm-all-app-profile - Remove application profile of all packages for all users\n"
57 " (this option should be run as root)\n"
58 " --check-all-app-privilege - Chcek application privilege of all package\n"
59 " (this option should be run as root)\n"
62 " --mibc - Specify Mibc files. Sepatated with ':'.\n"
63 " --verbose - Display verbose information\n"
64 " --inputbubble - Compile input assemblies into one bubble with the assemblies described at --inputbubbleref option\n"
65 " Note!: If you do not have an accurate understanding of Bubble, do not use this option.\n"
66 " All assemblies in the bubble must be guaranteed to be compiled to the native image before execution.\n"
67 " If an uncompiled assembly is included in the bubble during execution, an unknown error may occur.\n"
68 " If --inputbubbleref option doesnot be set, only input files are included to bubble. \n"
69 " --inputbubbleref - Input bubble reference file(s) to be added to bubble (used with --inputbubble option)\n"
70 " --ref - Reference file(s) for compilation\n"
71 " (system paths are set automatically.)\n"
72 " --no-pipeline - Compile the dlls individually\n"
73 " --print-cmd - Print command and options\n"
74 " --skip-ro-app - Skip re-generate NI for apps installed RO area\n"
75 " (This option works with --ni-regen-all-app only)\n"
76 " --rm-origin-after-ni - Remove original dll after creating native image\n"
77 " Note!: App ATOC options(--ni-pkg, --ni-regen-all-app, --tac-regen-all) cannot be used with --rm-origin-after-ni option.\n"
78 " (Use only for assemblies that will not be AOTed again afterward.)"
80 "Usage: dotnettool [options] [command] [arguments]\n"
83 "1. Create native image for dlls and exes under platform directories\n"
84 " # dotnettool --ni-system\n"
85 "2. Create native image for dll\n"
86 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
87 "3. Create native image under the package's bin and lib directory\n"
88 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
89 "4. Regenerate native images for all installed .net packages\n"
90 " # dotnettool --ni-regen-all-app\n"
91 "5. Create native image for dll based on the Mibc data\n"
92 " # dotnettool --mibc /tmp/ibcdata/in.mibc --ni-dll /usr/bin/Tizen.Runtime.dll\n"
93 "6. Remove profile for package\n"
94 " # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
98 int main(int argc, char* argv[])
106 gettimeofday(&tv, NULL);
107 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
114 NIOption* opt = getNIOption();
115 if (opt == nullptr) {
116 _SERR("Fail to create option structure.");
120 std::vector<std::string> args;
121 for (int i = 0; i < argc; ++i) {
122 std::string arg = argv[i];
124 if ((arg == "-?") || (arg == "-h") || (arg == "--h")) {
127 } else if (arg == "--verbose") {
128 opt->flags |= NI_FLAGS_VERBOSE;
129 } else if (arg == "--inputbubble") {
130 opt->flags |= NI_FLAGS_INPUT_BUBBLE;
131 } else if (arg == "--no-pipeline") {
132 opt->flags |= NI_FLAGS_NO_PIPELINE;
133 } else if (arg == "--print-cmd") {
134 opt->flags |= NI_FLAGS_PRINT_CMD;
135 } else if (arg == "--skip-ro-app") {
136 opt->flags |= NI_FLAGS_SKIP_RO_APP;
137 } else if (arg == "--rm-origin-after-ni") {
138 opt->flags |= NI_FLAGS_RM_ORIGIN_AFTER_NI;
139 } else if (arg == "--mibc") {
142 _SOUT("File path containing Mibc files should be followed for --mibc option");
147 opt->flags |= NI_FLAGS_MIBC;
149 std::vector<std::string> paths;
150 splitPath(std::string(argv[i]), paths);
151 for (const auto &path : paths) {
152 if (!isFile(path) || isDirectory(path)) {
153 _SERR("Mibc file path is missing or does not exist");
156 opt->mibcPath.push_back(path);
158 } else if (arg == "--inputbubbleref") {
161 _SOUT("Path for references should be followed for --inputbubbleref option");
166 opt->flags |= NI_FLAGS_INPUT_BUBBLE_REF;
168 std::vector<std::string> files;
169 splitPath(std::string(argv[i]), files);
170 for (const auto &f : files) {
171 opt->inputBubbleRefFiles.push_back(f);
173 } else if (arg == "--ref") {
176 _SOUT("Path for references should be followed for --ref option");
181 std::vector<std::string> files;
182 splitPath(std::string(argv[i]), files);
183 for (const auto &f : files) {
184 opt->refFiles.push_back(f);
191 if (args.size() == 0) {
192 _SERR("The command is missing");
197 if (opt->flags & NI_FLAGS_INPUT_BUBBLE_REF && !(opt->flags & NI_FLAGS_INPUT_BUBBLE)) {
198 _SERR("--inputbubbleref option should be used with --inputbubble option");
203 if (initNICommon() != NI_ERROR_NONE) {
207 std::vector<std::string>::iterator it = args.begin();
208 std::string cmd = std::string(*it);
211 //sh-3.2# dotnettool --ni-system [AssemblyDirectory] [AssemblyDirectory] ...
212 if (cmd == "--ni-system") {
214 while (it != args.end()) {
215 const std::string dir = std::string(*it);
216 inputs = inputs + ":" + dir;
219 int ret = createNIPlatform(inputs, opt);
220 if (ret != NI_ERROR_NONE) {
221 _SERR("Failed to generate system NI");
224 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
225 else if (cmd == "--ni-dll") {
226 if (args.size() < 1) {
227 _SERR("DLL path is missing");
229 std::vector<std::string> inputs;
230 while (it != args.end()) {
231 std::string dll = std::string(*it);
232 inputs.push_back(dll);
233 opt->refFiles.push_back(dll);
234 if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
235 opt->inputBubbleRefFiles.push_back(dll);
240 for (auto &dll : inputs) {
241 int ret = createNIDll(dll, opt);
242 if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
243 _SERR("Failed to generate NI file [%s]", dll.c_str());
248 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
249 else if (cmd == "--ni-pkg") {
250 if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
251 _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
256 if (args.size() < 1) {
257 _SERR("Package name is missing");
259 while (it != args.end()) {
260 std::string pkg = std::string(*it);
261 int ret = createNIUnderPkgRoot(pkg, opt);
262 if (ret != NI_ERROR_NONE) {
263 _SERR("Failed to generate app NI [%s]", pkg.c_str());
269 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
270 else if (cmd == "--ni-dir") {
271 if (args.size() < 1) {
272 _SERR("Directory path is missing");
275 while (it != args.end()) {
277 dir += std::string(":");
279 dir += std::string(*it);
282 if (createNIUnderDirs(dir, opt) != NI_ERROR_NONE) {
283 _SERR("Failed to generate NI directory");
286 //sh-3.2# dotnettool --ni-reset-system
287 else if (cmd == "--ni-reset-system") {
290 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
291 else if (cmd == "--ni-reset-pkg") {
292 if (args.size() < 1) {
293 _SERR("Package name is missing");
295 while (it != args.end()) {
296 std::string pkg = std::string(*it);
297 int ret = removeNIUnderPkgRoot(pkg);
298 if (ret != NI_ERROR_NONE) {
299 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
305 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
306 else if (cmd == "--ni-reset-dir") {
307 if (args.size() < 1) {
308 _SERR("Directory path is missing");
310 while (it != args.end()) {
311 const std::string dir = std::string(*it);
312 removeNIUnderDirs(dir);
316 //sh-3.2# dotnettool --ni-regen-all-app
317 else if (cmd == "--ni-regen-all-app") {
318 if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
319 _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
324 int ret = regenerateAppNI(opt);
325 if (ret != NI_ERROR_NONE) {
326 _SERR("Failed to regenerate all app NI");
329 //sh-3.2# dotnettool --tac-regen-all
330 else if (cmd == "--tac-regen-all") {
331 if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
332 _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
337 int ret = regenerateTACNI(opt);
338 if (ret != NI_ERROR_NONE) {
339 _SERR("Failed to regenerate all TAC");
342 //sh-3.2# dotnettool --tac-restore-db
343 else if (cmd == "--tac-restore-db") {
344 int ret = tac_restoreDB();
345 if (ret != TAC_ERROR_NONE) {
346 _SERR("Failed to restore TAC db");
348 ret = tlc_restoreDB();
349 if (ret != TAC_ERROR_NONE) {
350 _SERR("Failed to restore TLC db");
353 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
354 else if (cmd == "--tac-enable-pkg") {
355 if (args.size() < 1) {
356 _SERR("Package name is missing");
358 while (it != args.end()) {
359 std::string pkg = std::string(*it);
360 int ret = enableTACPackage(pkg);
361 if (ret != TAC_ERROR_NONE) {
362 _SERR("Failed to enable tac [%s]", pkg.c_str());
368 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
369 else if (cmd == "--tac-disable-pkg") {
370 if (args.size() < 1) {
371 _SERR("Package name is missing");
373 while (it != args.end()) {
374 std::string pkg = std::string(*it);
375 int ret = disableTACPackage(pkg);
376 if (ret != TAC_ERROR_NONE) {
377 _SERR("Failed to disable tac [%s]", pkg.c_str());
383 //sh-3.2# dotnettool --resolve-all-app
384 else if (cmd == "--resolve-all-app") {
385 int ret = resolveAllApps();
387 _SERR("Failed to remove unused multi-targeting files");
390 //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
391 else if (cmd == "--rm-app-profile") {
392 if (args.size() < 1) {
393 _SERR("Package name is missing");
395 while (it != args.end()) {
396 std::string pkg = std::string(*it);
397 if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) {
398 _SERR("Failed to remove [%s] profile data", pkg.c_str());
403 //sh-3.2# dotnettool --rm-all-app-profile
404 else if (cmd == "--rm-all-app-profile") {
405 removeAllAppProfileData();
407 //sh-3.2# dotnettool --check-all-app-privilege
408 else if (cmd == "--check-all-app-privilege") {
409 checkAllAppPrivilege();
412 _SERR("Unknown option [%s]", cmd.c_str());
418 gettimeofday(&tv, NULL);
419 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
420 _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));