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 " --ibc-dir - Specify a directory containing IBC files\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 " --r2r - Generate a Ready-To-Run image (disable: /FragileNonVersionable)\n"
60 " --compatibility - Compatibility mode for older versions of crossgen\n"
61 " (replaces /r with /Trusted_Platform_Assemblies)\n"
62 " --verbose - Display verbose information\n"
63 " --instrument - Generate an instrumented image for profiling (enable: /Tuning)\n"
65 "Usage: dotnettool [options] [command] [arguments]\n"
68 "1. Create native image for dlls and exes under platform directories\n"
69 " # dotnettool --ni-system\n"
70 "2. Create native image for dll\n"
71 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
72 "3. Create native image under the package's bin and lib directory\n"
73 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
74 "4. Regenerate native images for all installed .net packages with ready-to-run option\n"
75 " # dotnettool --r2r --ni-regen-all-app\n"
76 "5. Create native image for dll based on the IBC data\n"
77 " # dotnettool --ibc-dir /tmp/ibcdata/ --ni-dll /usr/bin/Tizen.Runtime.dll\n"
78 "6. Remove profile for package\n"
79 " # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
83 int main(int argc, char* argv[])
91 gettimeofday(&tv, NULL);
92 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
99 //sh-3.2# dotnettool --[r2r|compatibility|instrument|verbose]
101 std::vector<std::string> args;
102 for (char** it = argv; it != argv+argc; it++) {
103 if (!strncmp(*it, "-?", 2) || !strncmp(*it, "-h", 2) || !strncmp(*it, "--help", 6)) {
106 } else if (!strncmp(*it, "--r2r", 5)) {
107 flags |= NI_FLAGS_ENABLER2R;
108 } else if (!strncmp(*it, "--compatibility", 15)) {
109 flags |= NI_FLAGS_COMPATIBILITY;
110 } else if (!strncmp(*it, "--instrument", 12)) {
111 flags |= NI_FLAGS_INSTRUMENT;
112 } else if (!strncmp(*it, "--verbose", 9)) {
113 flags |= NI_FLAGS_VERBOSE;
119 //sh-3.2# dotnettool --ibc-dir [ibcDirectory]
120 for (auto it = args.begin(); it != args.end(); ) {
121 if (*it == "--ibc-dir") {
124 std::string ibcFilePath = std::string(*it);
125 if (!isDirectory(ibcFilePath)) {
126 _SERR("IBC path is missing or not exist");
130 setenv("COMPlus_IBCFileDir", const_cast<char *>(ibcFilePath.c_str()), 1);
131 setenv("COMPlus_UseIBCFile", const_cast<char *>("1"), 1);
138 if (initNICommon() != NI_ERROR_NONE) {
142 std::vector<std::string>::iterator it = args.begin();
143 std::string cmd = std::string(*it);
146 //sh-3.2# dotnettool --ni-system
147 if (cmd == "--ni-system") {
148 int ret = createNIPlatform(flags);
149 if (ret != NI_ERROR_NONE) {
150 _SERR("Failed to generate system NI");
153 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
154 else if (cmd == "--ni-dll") {
155 if (args.size() < 1) {
156 _SERR("DLL path is missing");
158 while (it != args.end()) {
159 std::string dll = std::string(*it);
160 int ret = createNIDll(dll, flags);
161 if (ret != NI_ERROR_NONE) {
162 _SERR("Failed to generate NI file [%s]", dll.c_str());
168 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
169 else if (cmd == "--ni-pkg") {
170 if (args.size() < 1) {
171 _SERR("Package name is missing");
173 while (it != args.end()) {
174 std::string pkg = std::string(*it);
175 int ret = createNIUnderPkgRoot(pkg, flags);
176 if (ret != NI_ERROR_NONE) {
177 _SERR("Failed to generate app NI [%s]", pkg.c_str());
183 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
184 else if (cmd == "--ni-dir") {
185 if (args.size() < 1) {
186 _SERR("Directory path is missing");
188 while (it != args.end()) {
189 const std::string dir = std::string(*it);
190 int ret = createNIUnderDirs(dir, flags);
191 if (ret != NI_ERROR_NONE) {
192 _SERR("Failed to generate NI directory");
198 //sh-3.2# dotnettool --ni-reset-system
199 else if (cmd == "--ni-reset-system") {
202 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
203 else if (cmd == "--ni-reset-pkg") {
204 if (args.size() < 1) {
205 _SERR("Package name is missing");
207 while (it != args.end()) {
208 std::string pkg = std::string(*it);
209 int ret = removeNIUnderPkgRoot(pkg);
210 if (ret != NI_ERROR_NONE) {
211 _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
217 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
218 else if (cmd == "--ni-reset-dir") {
219 if (args.size() < 1) {
220 _SERR("Directory path is missing");
222 while (it != args.end()) {
223 const std::string dir = std::string(*it);
224 removeNIUnderDirs(dir);
228 //sh-3.2# dotnettool --ni-regen-all-app
229 else if (cmd == "--ni-regen-all-app") {
230 int ret = regenerateAppNI(flags);
231 if (ret != NI_ERROR_NONE) {
232 _SERR("Failed to regenerate all app NI");
235 //sh-3.2# dotnettool --tac-regen-all
236 else if (cmd == "--tac-regen-all") {
237 int ret = regenerateTACNI(flags);
238 if (ret != NI_ERROR_NONE) {
239 _SERR("Failed to regenerate all TAC");
242 //sh-3.2# dotnettool --tac-restore-db
243 else if (cmd == "--tac-restore-db") {
244 int ret = tac_restoreDB();
245 if (ret != TAC_ERROR_NONE) {
246 _SERR("Failed to restore TAC db");
248 ret = tlc_restoreDB();
249 if (ret != TAC_ERROR_NONE) {
250 _SERR("Failed to restore TLC db");
253 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
254 else if (cmd == "--tac-enable-pkg") {
255 if (args.size() < 1) {
256 _SERR("Package name is missing");
258 while (it != args.end()) {
259 std::string pkg = std::string(*it);
260 int ret = enableTACPackage(pkg);
261 if (ret != TAC_ERROR_NONE) {
262 _SERR("Failed to enable tac [%s]", pkg.c_str());
268 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
269 else if (cmd == "--tac-disable-pkg") {
270 if (args.size() < 1) {
271 _SERR("Package name is missing");
273 while (it != args.end()) {
274 std::string pkg = std::string(*it);
275 int ret = disableTACPackage(pkg);
276 if (ret != TAC_ERROR_NONE) {
277 _SERR("Failed to disable tac [%s]", pkg.c_str());
283 //sh-3.2# dotnettool --resolve-all-app
284 else if (cmd == "--resolve-all-app") {
285 int ret = resolveAllApps();
287 _SERR("Failed to remove unused multi-targeting files");
290 //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
291 else if (cmd == "--rm-app-profile") {
292 if (args.size() < 1) {
293 _SERR("Package name is missing");
295 while (it != args.end()) {
296 std::string pkg = std::string(*it);
297 if (removeAppProfileData(pkg) != NI_ERROR_NONE) {
298 _SERR("Failed to remove [%s] profile data", pkg.c_str());
303 //sh-3.2# dotnettool --rm-all-app-profile
304 else if (cmd == "--rm-all-app-profile") {
305 removeAllAppProfileData();
308 _SERR("Unknown option [%s]", cmd.c_str());
314 gettimeofday(&tv, NULL);
315 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
316 _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime));