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"
31 "Dotnet Tool Version: 1.0\n"
34 " -h, --help - Show this help message\n"
35 " --ni-system - Create NI under System DLLs\n"
36 " --ni-dll - Create NI for DLL\n"
37 " --ni-pkg - Create NI for package\n"
38 " --ni-dir - Create NI for directory\n"
39 " --ni-reset-system - Remove System NI files\n"
40 " --ni-reset-pkg - Remove App NI files\n"
41 " --ni-reset-dir - Remove NI for directory\n"
42 " --ni-regen-all-app - Re-generate All App NI files\n"
43 " --tac-regen-all - Re-generate All TAC files\n"
44 " --tac-restore-db - Restore TAC Database\n"
45 " --tac-disable-pkg - Disable TAC for package\n"
46 " --tac-enable-pkg - Enable TAC for package\n"
47 " --ibc-dir - Specify a directory containing IBC files\n"
48 " --resolve-all-app - Remove unused multi-targeting files of all apps\n"
49 " (this option is used for FOTA script or test)\n"
52 " --r2r - Generate a Ready-To-Run image (disable: /FragileNonVersionable)\n"
53 " --compatibility - Compatibility mode for older versions of crossgen\n"
54 " (replaces /r with /Trusted_Platform_Assemblies)\n"
55 " --verbose - Display verbose information\n"
56 " --instrument - Generate an instrumented image for profiling (enable: /Tuning)\n"
58 "Usage: dotnettool [options] [command] [arguments]\n"
61 "1. Create native image for dlls and exes under platform directories\n"
62 " # dotnettool --ni-system\n"
63 "2. Create native image for dll\n"
64 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
65 "3. Create native image under the package's bin and lib directory\n"
66 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
67 "4. Regenerate native images for all installed .net packages with ready-to-run option\n"
68 " # dotnettool --r2r --ni-regen-all-app\n"
69 "5. Create native image for dll based on the IBC data\n"
70 " # dotnettool --ibc-dir /tmp/ibcdata/ --ni-dll /usr/bin/Tizen.Runtime.dll\n"
74 int main(int argc, char* argv[])
82 gettimeofday(&tv, NULL);
83 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
90 //sh-3.2# dotnettool --[r2r|compatibility|instrument|verbose]
92 std::vector<std::string> args;
93 for (char** it = argv; it != argv+argc; it++) {
94 if (!strncmp(*it, "-?", 2) || !strncmp(*it, "-h", 2) || !strncmp(*it, "--help", 6)) {
97 } else if (!strncmp(*it, "--r2r", 5)) {
98 flags |= NI_FLAGS_ENABLER2R;
99 } else if (!strncmp(*it, "--compatibility", 15)) {
100 flags |= NI_FLAGS_COMPATIBILITY;
101 } else if (!strncmp(*it, "--instrument", 12)) {
102 flags |= NI_FLAGS_INSTRUMENT;
103 } else if (!strncmp(*it, "--verbose", 9)) {
104 flags |= NI_FLAGS_VERBOSE;
110 //sh-3.2# dotnettool --ibc-dir [ibcDirectory]
111 for (auto it = args.begin(); it != args.end(); ) {
112 if (*it == "--ibc-dir") {
115 std::string ibcFilePath = std::string(*it);
116 if (!isDirectory(ibcFilePath)) {
117 fprintf(stderr, "IBC path is missing or not exist\n");
121 setenv("COMPlus_IBCFileDir", const_cast<char *>(ibcFilePath.c_str()), 1);
122 setenv("COMPlus_UseIBCFile", const_cast<char *>("1"), 1);
129 if (initNICommon() != NI_ERROR_NONE) {
133 std::vector<std::string>::iterator it = args.begin();
134 std::string cmd = std::string(*it);
137 //sh-3.2# dotnettool --ni-system
138 if (cmd == "--ni-system") {
139 int ret = createNIPlatform(flags);
140 if (ret != NI_ERROR_NONE) {
141 fprintf(stderr, "Failed to generate system NI\n");
144 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
145 else if (cmd == "--ni-dll") {
146 if (args.size() < 1) {
147 fprintf(stderr, "DLL path is missing\n");
149 while (it != args.end()) {
150 std::string dll = std::string(*it);
151 int ret = createNIDll(dll, flags);
152 if (ret != NI_ERROR_NONE) {
153 fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
159 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
160 else if (cmd == "--ni-pkg") {
161 if (args.size() < 1) {
162 fprintf(stderr, "Package name is missing\n");
164 while (it != args.end()) {
165 std::string pkg = std::string(*it);
166 // if there is AOTed dlls under package root, that is skiped.
167 int ret = createNIUnderPkgRoot(pkg, flags);
168 if (ret != NI_ERROR_NONE) {
169 fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
175 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
176 else if (cmd == "--ni-dir") {
177 if (args.size() < 1) {
178 fprintf(stderr, "Directory path is missing\n");
180 while (it != args.end()) {
181 const std::string dir = std::string(*it);
182 int ret = createNIUnderDirs(dir, flags);
183 if (ret != NI_ERROR_NONE) {
184 fprintf(stderr, "Failed to generate NI directory\n");
190 //sh-3.2# dotnettool --ni-reset-system
191 else if (cmd == "--ni-reset-system") {
194 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
195 else if (cmd == "--ni-reset-pkg") {
196 if (args.size() < 1) {
197 fprintf(stderr, "Package name is missing\n");
199 while (it != args.end()) {
200 std::string pkg = std::string(*it);
201 int ret = removeNIUnderPkgRoot(pkg);
202 if (ret != NI_ERROR_NONE) {
203 fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
209 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
210 else if (cmd == "--ni-reset-dir") {
211 if (args.size() < 1) {
212 fprintf(stderr, "Directory path is missing\n");
214 while (it != args.end()) {
215 const std::string dir = std::string(*it);
216 removeNIUnderDirs(dir);
220 //sh-3.2# dotnettool --ni-regen-all-app
221 else if (cmd == "--ni-regen-all-app") {
222 int ret = regenerateAppNI(flags);
223 if (ret != NI_ERROR_NONE) {
224 fprintf(stderr, "Failed to regenerate all app NI\n");
227 //sh-3.2# dotnettool --tac-regen-all
228 else if (cmd == "--tac-regen-all") {
229 int ret = regenerateTACNI(flags);
230 if (ret != NI_ERROR_NONE) {
231 fprintf(stderr, "Failed to regenerate all TAC\n");
234 //sh-3.2# dotnettool --tac-restore-db
235 else if (cmd == "--tac-restore-db") {
236 int ret = tac_restoreDB();
237 if (ret != TAC_ERROR_NONE) {
238 fprintf(stderr, "Failed to restore TAC db\n");
240 ret = tlc_restoreDB();
241 if (ret != TAC_ERROR_NONE) {
242 fprintf(stderr, "Failed to restore TLC db\n");
245 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
246 else if (cmd == "--tac-enable-pkg") {
247 if (args.size() < 1) {
248 fprintf(stderr, "Package name is missing\n");
250 while (it != args.end()) {
251 std::string pkg = std::string(*it);
252 int ret = enableTACPackage(pkg);
253 if (ret != TAC_ERROR_NONE) {
254 fprintf(stderr, "Failed to enable tac [%s]\n", pkg.c_str());
260 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
261 else if (cmd == "--tac-disable-pkg") {
262 if (args.size() < 1) {
263 fprintf(stderr, "Package name is missing\n");
265 while (it != args.end()) {
266 std::string pkg = std::string(*it);
267 int ret = disableTACPackage(pkg);
268 if (ret != TAC_ERROR_NONE) {
269 fprintf(stderr, "Failed to disable tac [%s]\n", pkg.c_str());
275 //sh-3.2# dotnettool --resolve-all-app
276 else if (cmd == "--resolve-all-app") {
277 int ret = resolveAllApps();
279 fprintf(stderr, "Failed to remove unused multi-targeting files\n");
283 fprintf(stderr, "Unknown option [%s]\n", cmd.c_str());
289 gettimeofday(&tv, NULL);
290 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
291 fprintf(stdout, "\nSpend time for dotnettool is [%d]ms\n", (int)(endtime - starttime));