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 " --mibc - Specify Mibc files. Sepatated with ':'.\n"
59 " --verbose - Display verbose information\n"
60 " --inputbubble - Compile input assemblies into one bubble with the assemblies described at --inputbubbleref option\n"
61 " Note!: If you do not have an accurate understanding of Bubble, do not use this option.\n"
62 " All assemblies in the bubble must be guaranteed to be compiled to the native image before execution.\n"
63 " If an uncompiled assembly is included in the bubble during execution, an unknown error may occur.\n"
64 " If --inputbubbleref option doesnot be set, only input files are included to bubble. \n"
65 " --inputbubbleref - Input bubble reference file(s) to be added to bubble (used with --inputbubble option)\n"
66 " --ref - Reference file(s) for compilation\n"
67 " (system paths are set automatically.)\n"
68 " --no-pipeline - Compile the dlls individually\n"
69 " --print-cmd - Print command and options\n"
70 " --skip-ro-app - Skip re-generate NI for apps installed RO area\n"
71 " (This option works with --ni-regen-all-app only)\n"
73 "Usage: dotnettool [options] [command] [arguments]\n"
76 "1. Create native image for dlls and exes under platform directories\n"
77 " # dotnettool --ni-system\n"
78 "2. Create native image for dll\n"
79 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
80 "3. Create native image under the package's bin and lib directory\n"
81 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
82 "4. Regenerate native images for all installed .net packages\n"
83 " # dotnettool --ni-regen-all-app\n"
84 "5. Create native image for dll based on the Mibc data\n"
85 " # dotnettool --mibc /tmp/ibcdata/in.mibc --ni-dll /usr/bin/Tizen.Runtime.dll\n"
86 "6. Remove profile for package\n"
87 " # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
91 int main(int argc, char* argv[])
99 gettimeofday(&tv, NULL);
100 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
107 NIOption* opt = getNIOption();
108 if (opt == nullptr) {
109 _SERR("Fail to create option structure.");
113 std::vector<std::string> args;
114 for (int i = 0; i < argc; ++i) {
115 std::string arg = argv[i];
117 if ((arg == "-?") || (arg == "-h") || (arg == "--h")) {
120 } else if (arg == "--verbose") {
121 opt->flags |= NI_FLAGS_VERBOSE;
122 } else if (arg == "--inputbubble") {
123 opt->flags |= NI_FLAGS_INPUT_BUBBLE;
124 } else if (arg == "--no-pipeline") {
125 opt->flags |= NI_FLAGS_NO_PIPELINE;
126 } else if (arg == "--print-cmd") {
127 opt->flags |= NI_FLAGS_PRINT_CMD;
128 } else if (arg == "--skip-ro-app") {
129 opt->flags |= NI_FLAGS_SKIP_RO_APP;
130 } else if (arg == "--mibc") {
133 _SOUT("File path containing Mibc files should be followed for --mibc option");
138 opt->flags |= NI_FLAGS_MIBC;
140 std::vector<std::string> paths;
141 splitPath(std::string(argv[i]), paths);
142 for (const auto &path : paths) {
143 if (!isFile(path) || isDirectory(path)) {
144 _SERR("Mibc file path is missing or does not exist");
147 opt->mibcPath.push_back(path);
149 } else if (arg == "--inputbubbleref") {
152 _SOUT("Path for references should be followed for --inputbubbleref option");
157 opt->flags |= NI_FLAGS_INPUT_BUBBLE_REF;
159 std::vector<std::string> files;
160 splitPath(std::string(argv[i]), files);
161 for (const auto &f : files) {
162 opt->inputBubbleRefFiles.push_back(f);
164 } else if (arg == "--ref") {
167 _SOUT("Path for references should be followed for --ref option");
172 std::vector<std::string> files;
173 splitPath(std::string(argv[i]), files);
174 for (const auto &f : files) {
175 opt->refFiles.push_back(f);
182 if (opt->flags & NI_FLAGS_INPUT_BUBBLE_REF && !(opt->flags & NI_FLAGS_INPUT_BUBBLE)) {
183 _SERR("--inputbubbleref option should be used with --inputbubble option");
188 if (initNICommon() != NI_ERROR_NONE) {
192 std::vector<std::string>::iterator it = args.begin();
193 std::string cmd = std::string(*it);
196 //sh-3.2# dotnettool --ni-system [AssemblyDirectory] [AssemblyDirectory] ...
197 if (cmd == "--ni-system") {
199 while (it != args.end()) {
200 const std::string dir = std::string(*it);
201 inputs = inputs + ":" + dir;
204 int ret = createNIPlatform(inputs, opt);
205 if (ret != NI_ERROR_NONE) {
206 _SERR("Failed to generate system NI");
209 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
210 else if (cmd == "--ni-dll") {
211 if (args.size() < 1) {
212 _SERR("DLL path is missing");
214 std::vector<std::string> inputs;
215 while (it != args.end()) {
216 std::string dll = std::string(*it);
217 inputs.push_back(dll);
218 opt->refFiles.push_back(dll);
219 if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
220 opt->inputBubbleRefFiles.push_back(dll);
225 for (auto &dll : inputs) {
226 int ret = createNIDll(dll, opt);
227 if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
228 _SERR("Failed to generate NI file [%s]", dll.c_str());
233 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
234 else if (cmd == "--ni-pkg") {
235 if (args.size() < 1) {
236 _SERR("Package name is missing");
238 while (it != args.end()) {
239 std::string pkg = std::string(*it);
240 int ret = createNIUnderPkgRoot(pkg, opt);
241 if (ret != NI_ERROR_NONE) {
242 _SERR("Failed to generate app NI [%s]", pkg.c_str());
248 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
249 else if (cmd == "--ni-dir") {
250 if (args.size() < 1) {
251 _SERR("Directory path is missing");
254 while (it != args.end()) {
256 dir += std::string(":");
258 dir += std::string(*it);
261 if (createNIUnderDirs(dir, opt) != NI_ERROR_NONE) {
262 _SERR("Failed to generate NI directory");
265 //sh-3.2# dotnettool --ni-reset-system
266 else if (cmd == "--ni-reset-system") {
269 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
270 else if (cmd == "--ni-reset-pkg") {
271 if (args.size() < 1) {
272 _SERR("Package name is missing");
274 while (it != args.end()) {
275 std::string pkg = std::string(*it);
276 int ret = removeNIUnderPkgRoot(pkg);
277 if (ret != NI_ERROR_NONE) {
278 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
284 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
285 else if (cmd == "--ni-reset-dir") {
286 if (args.size() < 1) {
287 _SERR("Directory path is missing");
289 while (it != args.end()) {
290 const std::string dir = std::string(*it);
291 removeNIUnderDirs(dir);
295 //sh-3.2# dotnettool --ni-regen-all-app
296 else if (cmd == "--ni-regen-all-app") {
297 int ret = regenerateAppNI(opt);
298 if (ret != NI_ERROR_NONE) {
299 _SERR("Failed to regenerate all app NI");
302 //sh-3.2# dotnettool --tac-regen-all
303 else if (cmd == "--tac-regen-all") {
304 int ret = regenerateTACNI(opt);
305 if (ret != NI_ERROR_NONE) {
306 _SERR("Failed to regenerate all TAC");
309 //sh-3.2# dotnettool --tac-restore-db
310 else if (cmd == "--tac-restore-db") {
311 int ret = tac_restoreDB();
312 if (ret != TAC_ERROR_NONE) {
313 _SERR("Failed to restore TAC db");
315 ret = tlc_restoreDB();
316 if (ret != TAC_ERROR_NONE) {
317 _SERR("Failed to restore TLC db");
320 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
321 else if (cmd == "--tac-enable-pkg") {
322 if (args.size() < 1) {
323 _SERR("Package name is missing");
325 while (it != args.end()) {
326 std::string pkg = std::string(*it);
327 int ret = enableTACPackage(pkg);
328 if (ret != TAC_ERROR_NONE) {
329 _SERR("Failed to enable tac [%s]", pkg.c_str());
335 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
336 else if (cmd == "--tac-disable-pkg") {
337 if (args.size() < 1) {
338 _SERR("Package name is missing");
340 while (it != args.end()) {
341 std::string pkg = std::string(*it);
342 int ret = disableTACPackage(pkg);
343 if (ret != TAC_ERROR_NONE) {
344 _SERR("Failed to disable tac [%s]", pkg.c_str());
350 //sh-3.2# dotnettool --resolve-all-app
351 else if (cmd == "--resolve-all-app") {
352 int ret = resolveAllApps();
354 _SERR("Failed to remove unused multi-targeting files");
357 //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
358 else if (cmd == "--rm-app-profile") {
359 if (args.size() < 1) {
360 _SERR("Package name is missing");
362 while (it != args.end()) {
363 std::string pkg = std::string(*it);
364 if (removeAppProfileData(pkg) != NI_ERROR_NONE) {
365 _SERR("Failed to remove [%s] profile data", pkg.c_str());
370 //sh-3.2# dotnettool --rm-all-app-profile
371 else if (cmd == "--rm-all-app-profile") {
372 removeAllAppProfileData();
375 _SERR("Unknown option [%s]", cmd.c_str());
381 gettimeofday(&tv, NULL);
382 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
383 _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));