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");
253 while (it != args.end()) {
254 const std::string dir = std::string(*it);
255 int ret = createNIUnderDirs(dir, opt);
256 if (ret != NI_ERROR_NONE) {
257 _SERR("Failed to generate NI directory");
263 //sh-3.2# dotnettool --ni-reset-system
264 else if (cmd == "--ni-reset-system") {
267 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
268 else if (cmd == "--ni-reset-pkg") {
269 if (args.size() < 1) {
270 _SERR("Package name is missing");
272 while (it != args.end()) {
273 std::string pkg = std::string(*it);
274 int ret = removeNIUnderPkgRoot(pkg);
275 if (ret != NI_ERROR_NONE) {
276 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
282 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
283 else if (cmd == "--ni-reset-dir") {
284 if (args.size() < 1) {
285 _SERR("Directory path is missing");
287 while (it != args.end()) {
288 const std::string dir = std::string(*it);
289 removeNIUnderDirs(dir);
293 //sh-3.2# dotnettool --ni-regen-all-app
294 else if (cmd == "--ni-regen-all-app") {
295 int ret = regenerateAppNI(opt);
296 if (ret != NI_ERROR_NONE) {
297 _SERR("Failed to regenerate all app NI");
300 //sh-3.2# dotnettool --tac-regen-all
301 else if (cmd == "--tac-regen-all") {
302 int ret = regenerateTACNI(opt);
303 if (ret != NI_ERROR_NONE) {
304 _SERR("Failed to regenerate all TAC");
307 //sh-3.2# dotnettool --tac-restore-db
308 else if (cmd == "--tac-restore-db") {
309 int ret = tac_restoreDB();
310 if (ret != TAC_ERROR_NONE) {
311 _SERR("Failed to restore TAC db");
313 ret = tlc_restoreDB();
314 if (ret != TAC_ERROR_NONE) {
315 _SERR("Failed to restore TLC db");
318 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
319 else if (cmd == "--tac-enable-pkg") {
320 if (args.size() < 1) {
321 _SERR("Package name is missing");
323 while (it != args.end()) {
324 std::string pkg = std::string(*it);
325 int ret = enableTACPackage(pkg);
326 if (ret != TAC_ERROR_NONE) {
327 _SERR("Failed to enable tac [%s]", pkg.c_str());
333 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
334 else if (cmd == "--tac-disable-pkg") {
335 if (args.size() < 1) {
336 _SERR("Package name is missing");
338 while (it != args.end()) {
339 std::string pkg = std::string(*it);
340 int ret = disableTACPackage(pkg);
341 if (ret != TAC_ERROR_NONE) {
342 _SERR("Failed to disable tac [%s]", pkg.c_str());
348 //sh-3.2# dotnettool --resolve-all-app
349 else if (cmd == "--resolve-all-app") {
350 int ret = resolveAllApps();
352 _SERR("Failed to remove unused multi-targeting files");
355 //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
356 else if (cmd == "--rm-app-profile") {
357 if (args.size() < 1) {
358 _SERR("Package name is missing");
360 while (it != args.end()) {
361 std::string pkg = std::string(*it);
362 if (removeAppProfileData(pkg) != NI_ERROR_NONE) {
363 _SERR("Failed to remove [%s] profile data", pkg.c_str());
368 //sh-3.2# dotnettool --rm-all-app-profile
369 else if (cmd == "--rm-all-app-profile") {
370 removeAllAppProfileData();
373 _SERR("Unknown option [%s]", cmd.c_str());
379 gettimeofday(&tv, NULL);
380 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
381 _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));