Merge pull request #62 from dotnet/generate_coreLib_ni_when_install
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / nitool.cc
index 5339bae..4ff2679 100644 (file)
@@ -41,24 +41,27 @@ static void help(const char *argv0)
 {
        const char* helpDesc =
                "Usage: %s [args] <root paths or pkg name>\n"
-               "               --help              - Display this screen\n"
-               "               --system            - Create NI under System DLLs\n"
-               "               --dll               - Create NI for DLL\n"
-               "               --pkg               - Create NI for package\n"
-               "               --dir               - Create NI for directory\n"
-               "               --r2r               - Use ready-to-run option (default: FNV)\n"
-               "               --reset-system      - Remove System NI files\n"
-               "               --reset-pkg         - Remove App NI files\n"
-               "               --regen-all-app     - Re-generate All App NI files\n"
+               "       --help              - Display this screen\n"
+               "       --system            - Create NI under System DLLs\n"
+               "       --dll               - Create NI for DLL\n"
+               "       --pkg               - Create NI for package\n"
+               "       --dir               - Create NI for directory\n"
+               "       --r2r               - Use ready-to-run option (default: FNV)\n"
+               "                             (This option should be used with other options)\n"
+               "       --reset-system      - Remove System NI files\n"
+               "       --reset-pkg         - Remove App NI files\n"
+               "       --regen-all-app     - Re-generate All App NI files\n"
                "\n"
                "Example:\n"
-               "Create native image for dlls and exes under platform directories\n"
-               "%s --system\n"
-               "Create native image for dll\n"
-               "%s --dll /usr/bin/Tizen.Runtime.dll\n"
-               "Create native image under the package's bin and lib directory\n"
-               "%s --pkg org.tizen.FormsGallery\n\n";
-       printf(helpDesc, argv0, argv0, argv0, argv0);
+               "1. Create native image for dlls and exes under platform directories\n"
+               "   # %s --system\n"
+               "2. Create native image for dll\n"
+               "   # %s --dll /usr/bin/Tizen.Runtime.dll\n"
+               "3. Create native image under the package's bin and lib directory\n"
+               "   # %s --pkg org.tizen.FormsGallery\n"
+               "4. Regenerate native images for all installed .net packages with ready-to-run option\n"
+               "   # %s --r2r --regen-all-app\n\n";
+       printf(helpDesc, argv0, argv0, argv0, argv0, argv0);
 }
 
 int main(int argc, char* argv[])
@@ -71,7 +74,7 @@ int main(int argc, char* argv[])
        bool pkgDllMode = false;
 
        NiCommonOption option = {std::string(), std::string(), std::string()};
-       if (initNICommon(&option) < 0) {
+       if (initNICommon(&option) != NI_ERROR_NONE) {
                fprintf(stderr, "Fail to initialize NI Common\n");
                return -1;
        }
@@ -120,26 +123,50 @@ int main(int argc, char* argv[])
 
        if (pkgMode) {
                for (const std::string pkg : args) {
-                       if (createNiUnderPkgRoot(pkg, enableR2R) != 0) {
+                       // if there is AOTed dlls under package root, that is skiped.
+                       int ret = createNiUnderPkgRoot(pkg, enableR2R);
+                       if (ret == NI_ERROR_INVALID_PACKAGE) {
                                fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
                                return -1;
+                       } else if (ret != NI_ERROR_NONE) {
+                               fprintf(stderr, "Failed to generate NI file [%s]\n", args[1].c_str());
+                               return -1;
                        }
                }
        } else if (pkgDllMode) {
-               if (createNiDllUnderPkgRoot(args[0], args[1], enableR2R) != 0) {
+               int ret = createNiDllUnderPkgRoot(args[0], args[1], enableR2R);
+               if (ret == NI_ERROR_INVALID_PACKAGE) {
                        fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str());
                        return -1;
+               } else if (ret == NI_ERROR_ALREADY_EXIST) {
+                       // skip for already exist case
+                       return -1;
+               } else if (ret != NI_ERROR_NONE) {
+                       fprintf(stderr, "Failed to generate NI file [%s]\n", args[1].c_str());
+                       return -1;
                }
        } else if (rmPkgMode) {
                for (const std::string pkg : args) {
-                       if (removeNiUnderPkgRoot(pkg) != 0) {
+                       int ret = removeNiUnderPkgRoot(pkg);
+                       if (ret == NI_ERROR_INVALID_PACKAGE) {
                                fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
                                return -1;
+                       } else if (ret != NI_ERROR_NONE) {
+                               fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
+                               return -1;
                        }
                }
        } else if (dllMode) {
-               for (const std::string dll : args)
-                       createNiDll(dll, enableR2R);
+               // donot return error code for generation failure.
+               // we have to run crossgen for all input dlls.
+               for (const std::string dll : args) {
+                       int ret = createNiDll(dll, enableR2R);
+                       if (ret == NI_ERROR_ALREADY_EXIST) {
+                               // skip for already exist case
+                       } else if (ret != NI_ERROR_NONE) {
+                               fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
+                       }
+               }
        } else if (dirMode) {
                createNiUnderDirs(args.data(), args.size(), enableR2R);
        }