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"
28 "Dotnet Tool Version: 1.0\n"
31 " -h, --help - Show this help message\n"
32 " --ni-system - Create NI under System DLLs\n"
33 " --ni-dll - Create NI for DLL\n"
34 " --ni-pkg - Create NI for package\n"
35 " --ni-dir - Create NI for directory\n"
36 " --ni-reset-system - Remove System NI files\n"
37 " --ni-reset-pkg - Remove App NI files\n"
38 " --ni-reset-dir - Remove NI for directory\n"
39 " --ni-regen-all-app - Re-generate All App NI files\n"
40 " --tac-regen-all - Re-generate All TAC files\n"
41 " --tac-restore-db - Restore TAC Database\n"
42 " --tac-disable-pkg - Disable TAC for package\n"
43 " --tac-enable-pkg - Enable TAC for package\n"
44 " --ibc-dir - Specify a directory containing IBC files\n"
47 " --r2r - Generate a Ready-To-Run image (disable: /FragileNonVersionable)\n"
48 " --compatibility - Compatibility mode for older versions of crossgen\n"
49 " (replaces /r with /Trusted_Platform_Assemblies)\n"
50 " --verbose - Display verbose information\n"
51 " --instrument - Generate an instrumented image for profiling (enable: /Tuning)\n"
53 "Usage: dotnettool [options] [command] [arguments]\n"
56 "1. Create native image for dlls and exes under platform directories\n"
57 " # dotnettool --ni-system\n"
58 "2. Create native image for dll\n"
59 " # dotnettool --ni-dll /usr/bin/Tizen.Runtime.dll\n"
60 "3. Create native image under the package's bin and lib directory\n"
61 " # dotnettool --ni-pkg org.tizen.FormsGallery\n"
62 "4. Regenerate native images for all installed .net packages with ready-to-run option\n"
63 " # dotnettool --r2r --ni-regen-all-app\n"
64 "5. Create native image for dll based on the IBC data\n"
65 " # dotnettool --ibc-dir /tmp/ibcdata/ --ni-dll /usr/bin/Tizen.Runtime.dll\n"
69 int main(int argc, char* argv[])
77 gettimeofday(&tv, NULL);
78 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
85 //sh-3.2# dotnettool --[r2r|compatibility|instrument|verbose]
87 std::vector<std::string> args;
88 for (char** it = argv; it != argv+argc; it++) {
89 if (!strncmp(*it, "-?", 2) || !strncmp(*it, "-h", 2) || !strncmp(*it, "--help", 6)) {
92 } else if (!strncmp(*it, "--r2r", 5)) {
93 flags |= NI_FLAGS_ENABLER2R;
94 } else if (!strncmp(*it, "--compatibility", 15)) {
95 flags |= NI_FLAGS_COMPATIBILITY;
96 } else if (!strncmp(*it, "--instrument", 12)) {
97 flags |= NI_FLAGS_INSTRUMENT;
98 } else if (!strncmp(*it, "--verbose", 9)) {
99 flags |= NI_FLAGS_VERBOSE;
105 //sh-3.2# dotnettool --ibc-dir [ibcDirectory]
106 for (auto it = args.begin(); it != args.end(); ) {
107 if (*it == "--ibc-dir") {
110 std::string ibcFilePath = std::string(*it);
111 if (!isDirectory(ibcFilePath)) {
112 fprintf(stderr, "IBC path is missing or not exist\n");
116 setenv("COMPlus_IBCFileDir", const_cast<char *>(ibcFilePath.c_str()), 1);
117 setenv("COMPlus_UseIBCFile", const_cast<char *>("1"), 1);
124 if (initNICommon() != NI_ERROR_NONE) {
128 std::vector<std::string>::iterator it = args.begin();
129 std::string cmd = std::string(*it);
132 //sh-3.2# dotnettool --ni-system
133 if (cmd == "--ni-system") {
134 int ret = createNIPlatform(flags);
135 if (ret != NI_ERROR_NONE) {
136 fprintf(stderr, "Failed to generate system NI\n");
139 //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
140 else if (cmd == "--ni-dll") {
141 if (args.size() < 1) {
142 fprintf(stderr, "DLL path is missing\n");
144 while (it != args.end()) {
145 std::string dll = std::string(*it);
146 int ret = createNIDll(dll, flags);
147 if (ret != NI_ERROR_NONE) {
148 fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
154 //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
155 else if (cmd == "--ni-pkg") {
156 if (args.size() < 1) {
157 fprintf(stderr, "Package name is missing\n");
159 while (it != args.end()) {
160 std::string pkg = std::string(*it);
161 // if there is AOTed dlls under package root, that is skiped.
162 int ret = createNIUnderPkgRoot(pkg, flags);
163 if (ret != NI_ERROR_NONE) {
164 fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
170 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
171 else if (cmd == "--ni-dir") {
172 if (args.size() < 1) {
173 fprintf(stderr, "Directory path is missing\n");
175 while (it != args.end()) {
176 const std::string dir = std::string(*it);
177 int ret = createNIUnderDirs(dir, flags);
178 if (ret != NI_ERROR_NONE) {
179 fprintf(stderr, "Failed to generate NI directory\n");
185 //sh-3.2# dotnettool --ni-reset-system
186 else if (cmd == "--ni-reset-system") {
189 //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
190 else if (cmd == "--ni-reset-pkg") {
191 if (args.size() < 1) {
192 fprintf(stderr, "Package name is missing\n");
194 while (it != args.end()) {
195 std::string pkg = std::string(*it);
196 int ret = removeNIUnderPkgRoot(pkg);
197 if (ret != NI_ERROR_NONE) {
198 fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
204 //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
205 else if (cmd == "--ni-reset-dir") {
206 if (args.size() < 1) {
207 fprintf(stderr, "Directory path is missing\n");
209 while (it != args.end()) {
210 const std::string dir = std::string(*it);
211 removeNIUnderDirs(dir);
215 //sh-3.2# dotnettool --ni-regen-all-app
216 else if (cmd == "--ni-regen-all-app") {
217 int ret = regenerateAppNI(flags);
218 if (ret != NI_ERROR_NONE) {
219 fprintf(stderr, "Failed to regenerate all app NI\n");
222 //sh-3.2# dotnettool --tac-regen-all
223 else if (cmd == "--tac-regen-all") {
224 int ret = regenerateTACNI(flags);
225 if (ret != NI_ERROR_NONE) {
226 fprintf(stderr, "Failed to regenerate all TAC\n");
229 //sh-3.2# dotnettool --tac-restore-db
230 else if (cmd == "--tac-restore-db") {
231 int ret = restoreTACDB();
232 if (ret != TAC_ERROR_NONE) {
233 fprintf(stderr, "Failed to restore TAC db\n");
236 //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
237 else if (cmd == "--tac-enable-pkg") {
238 if (args.size() < 1) {
239 fprintf(stderr, "Package name is missing\n");
241 while (it != args.end()) {
242 std::string pkg = std::string(*it);
243 int ret = enableTACPackage(pkg);
244 if (ret != TAC_ERROR_NONE) {
245 fprintf(stderr, "Failed to enable tac [%s]\n", pkg.c_str());
251 //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
252 else if (cmd == "--tac-disable-pkg") {
253 if (args.size() < 1) {
254 fprintf(stderr, "Package name is missing\n");
256 while (it != args.end()) {
257 std::string pkg = std::string(*it);
258 int ret = disableTACPackage(pkg);
259 if (ret != TAC_ERROR_NONE) {
260 fprintf(stderr, "Failed to disable tac [%s]\n", pkg.c_str());
267 fprintf(stderr, "Unknown option [%s]\n", cmd.c_str());
273 gettimeofday(&tv, NULL);
274 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
275 fprintf(stdout, "\nSpend time for dotnettool is [%d]ms\n", (int)(endtime - starttime));