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 "multi_target_resolver.h"
29 #include <app_common.h>
34 "Dotnet Tool Version: 1.0\n"
37 " -h, --help - Show this help message\n"
38 " --ni-system - Create NI under System DLLs\n"
39 " --ni-dll - Create NI for DLL\n"
40 " --ni-pkg - Create NI for package\n"
41 " (If package is installed under RO area, NI files are generated under RW area)\n"
42 " --ni-dir - Create NI for directory\n"
43 " --ni-reset-system - Remove System NI files\n"
44 " --ni-reset-pkg - Remove App NI files\n"
45 " --ni-reset-dir - Remove NI for directory\n"
46 " --ni-regen-all-app - Re-generate All App NI files\n"
47 " --tac-regen-all - Re-generate All TAC files\n"
48 " --tac-restore-db - Restore TAC Database\n"
49 " --tac-disable-pkg - Disable TAC for package\n"
50 " --tac-enable-pkg - Enable TAC for package\n"
51 " --resolve-all-app - Remove unused multi-targeting files of all apps\n"
52 " (this option is used for FOTA script or test)\n"
53 " --rm-app-profile - Remove application profile of given packages for all users\n"
54 " (this option should be run as root)\n"
55 " --rm-all-app-profile - Remove application profile of all packages for all users\n"
56 " (this option should be run as root)\n"
59 " --mibc - Specify Mibc files. Sepatated with ':'.\n"
60 " --verbose - Display verbose information\n"
61 " --inputbubble - Compile input assemblies into one bubble with the assemblies described at --inputbubbleref option\n"
62 " Note!: If you do not have an accurate understanding of Bubble, do not use this option.\n"
63 " All assemblies in the bubble must be guaranteed to be compiled to the native image before execution.\n"
64 " If an uncompiled assembly is included in the bubble during execution, an unknown error may occur.\n"
65 " If --inputbubbleref option doesnot be set, only input files are included to bubble. \n"
66 " --inputbubbleref - Input bubble reference file(s) to be added to bubble (used with --inputbubble option)\n"
67 " --ref - Reference file(s) for compilation\n"
68 " (system paths are set automatically.)\n"
69 " --no-pipeline - Compile the dlls individually\n"
70 " --print-cmd - Print command and options\n"
71 " --skip-ro-app - Skip re-generate NI for apps installed RO area\n"
72 " (This option works with --ni-regen-all-app only)\n"
74 "Usage: dotnettool [options] [command] [arguments]\n"
77 "1. Create native image for dlls and exes under platform directories\n"
78 " # dotnettool --ni-system\n"
79 "2. Create native image for dll\n"
80 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
81 "3. Create native image under the package's bin and lib directory\n"
82 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
83 "4. Regenerate native images for all installed .net packages\n"
84 " # dotnettool --ni-regen-all-app\n"
85 "5. Create native image for dll based on the Mibc data\n"
86 " # dotnettool --mibc /tmp/ibcdata/in.mibc --ni-dll /usr/bin/Tizen.Runtime.dll\n"
87 "6. Remove profile for package\n"
88 " # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
92 int main(int argc, char* argv[])
100 gettimeofday(&tv, NULL);
101 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
108 NIOption* opt = getNIOption();
109 if (opt == nullptr) {
110 _SERR("Fail to create option structure.");
114 std::vector<std::string> args;
115 for (int i = 0; i < argc; ++i) {
116 std::string arg = argv[i];
118 if ((arg == "-?") || (arg == "-h") || (arg == "--h")) {
121 } else if (arg == "--verbose") {
122 opt->flags |= NI_FLAGS_VERBOSE;
123 } else if (arg == "--inputbubble") {
124 opt->flags |= NI_FLAGS_INPUT_BUBBLE;
125 } else if (arg == "--no-pipeline") {
126 opt->flags |= NI_FLAGS_NO_PIPELINE;
127 } else if (arg == "--print-cmd") {
128 opt->flags |= NI_FLAGS_PRINT_CMD;
129 } else if (arg == "--skip-ro-app") {
130 opt->flags |= NI_FLAGS_SKIP_RO_APP;
131 } else if (arg == "--mibc") {
134 _SOUT("File path containing Mibc files should be followed for --mibc option");
139 opt->flags |= NI_FLAGS_MIBC;
141 std::vector<std::string> paths;
142 splitPath(std::string(argv[i]), paths);
143 for (const auto &path : paths) {
144 if (!isFile(path) || isDirectory(path)) {
145 _SERR("Mibc file path is missing or does not exist");
148 opt->mibcPath.push_back(path);
150 } else if (arg == "--inputbubbleref") {
153 _SOUT("Path for references should be followed for --inputbubbleref option");
158 opt->flags |= NI_FLAGS_INPUT_BUBBLE_REF;
160 std::vector<std::string> files;
161 splitPath(std::string(argv[i]), files);
162 for (const auto &f : files) {
163 opt->inputBubbleRefFiles.push_back(f);
165 } else if (arg == "--ref") {
168 _SOUT("Path for references should be followed for --ref option");
173 std::vector<std::string> files;
174 splitPath(std::string(argv[i]), files);
175 for (const auto &f : files) {
176 opt->refFiles.push_back(f);
183 if (opt->flags & NI_FLAGS_INPUT_BUBBLE_REF && !(opt->flags & NI_FLAGS_INPUT_BUBBLE)) {
184 _SERR("--inputbubbleref option should be used with --inputbubble option");
189 if (initNICommon() != NI_ERROR_NONE) {
193 std::vector<std::string>::iterator it = args.begin();
194 std::string cmd = std::string(*it);
197 //sh-3.2# dotnettool --ni-system [AssemblyDirectory] [AssemblyDirectory] ...
198 if (cmd == "--ni-system") {
200 while (it != args.end()) {
201 const std::string dir = std::string(*it);
202 inputs = inputs + ":" + dir;
205 int ret = createNIPlatform(inputs, opt);
206 if (ret != NI_ERROR_NONE) {
207 _SERR("Failed to generate system NI");
210 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
211 else if (cmd == "--ni-dll") {
212 if (args.size() < 1) {
213 _SERR("DLL path is missing");
215 std::vector<std::string> inputs;
216 while (it != args.end()) {
217 std::string dll = std::string(*it);
218 inputs.push_back(dll);
219 opt->refFiles.push_back(dll);
220 if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
221 opt->inputBubbleRefFiles.push_back(dll);
226 for (auto &dll : inputs) {
227 int ret = createNIDll(dll, opt);
228 if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
229 _SERR("Failed to generate NI file [%s]", dll.c_str());
234 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
235 else if (cmd == "--ni-pkg") {
236 if (args.size() < 1) {
237 _SERR("Package name is missing");
239 while (it != args.end()) {
240 std::string pkg = std::string(*it);
241 int ret = createNIUnderPkgRoot(pkg, opt);
242 if (ret != NI_ERROR_NONE) {
243 _SERR("Failed to generate app NI [%s]", pkg.c_str());
249 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
250 else if (cmd == "--ni-dir") {
251 if (args.size() < 1) {
252 _SERR("Directory path is missing");
255 while (it != args.end()) {
257 dir += std::string(":");
259 dir += std::string(*it);
262 if (createNIUnderDirs(dir, opt) != NI_ERROR_NONE) {
263 _SERR("Failed to generate NI directory");
266 //sh-3.2# dotnettool --ni-reset-system
267 else if (cmd == "--ni-reset-system") {
270 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
271 else if (cmd == "--ni-reset-pkg") {
272 if (args.size() < 1) {
273 _SERR("Package name is missing");
275 while (it != args.end()) {
276 std::string pkg = std::string(*it);
277 int ret = removeNIUnderPkgRoot(pkg);
278 if (ret != NI_ERROR_NONE) {
279 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
285 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
286 else if (cmd == "--ni-reset-dir") {
287 if (args.size() < 1) {
288 _SERR("Directory path is missing");
290 while (it != args.end()) {
291 const std::string dir = std::string(*it);
292 removeNIUnderDirs(dir);
296 //sh-3.2# dotnettool --ni-regen-all-app
297 else if (cmd == "--ni-regen-all-app") {
298 int ret = regenerateAppNI(opt);
299 if (ret != NI_ERROR_NONE) {
300 _SERR("Failed to regenerate all app NI");
303 //sh-3.2# dotnettool --tac-regen-all
304 else if (cmd == "--tac-regen-all") {
305 int ret = regenerateTACNI(opt);
306 if (ret != NI_ERROR_NONE) {
307 _SERR("Failed to regenerate all TAC");
310 //sh-3.2# dotnettool --tac-restore-db
311 else if (cmd == "--tac-restore-db") {
312 int ret = tac_restoreDB();
313 if (ret != TAC_ERROR_NONE) {
314 _SERR("Failed to restore TAC db");
316 ret = tlc_restoreDB();
317 if (ret != TAC_ERROR_NONE) {
318 _SERR("Failed to restore TLC db");
321 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
322 else if (cmd == "--tac-enable-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 = enableTACPackage(pkg);
329 if (ret != TAC_ERROR_NONE) {
330 _SERR("Failed to enable tac [%s]", pkg.c_str());
336 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
337 else if (cmd == "--tac-disable-pkg") {
338 if (args.size() < 1) {
339 _SERR("Package name is missing");
341 while (it != args.end()) {
342 std::string pkg = std::string(*it);
343 int ret = disableTACPackage(pkg);
344 if (ret != TAC_ERROR_NONE) {
345 _SERR("Failed to disable tac [%s]", pkg.c_str());
351 //sh-3.2# dotnettool --resolve-all-app
352 else if (cmd == "--resolve-all-app") {
353 int ret = resolveAllApps();
355 _SERR("Failed to remove unused multi-targeting files");
358 //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
359 else if (cmd == "--rm-app-profile") {
360 if (args.size() < 1) {
361 _SERR("Package name is missing");
363 while (it != args.end()) {
364 std::string pkg = std::string(*it);
365 if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) {
366 _SERR("Failed to remove [%s] profile data", pkg.c_str());
371 //sh-3.2# dotnettool --rm-all-app-profile
372 else if (cmd == "--rm-all-app-profile") {
373 removeAllAppProfileData();
376 _SERR("Unknown option [%s]", cmd.c_str());
382 gettimeofday(&tv, NULL);
383 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
384 _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));