Merge branch 'tizen' into use_app_ni_path
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / ni_common.cc
index 4a1e284..29f0b82 100644 (file)
@@ -152,28 +152,28 @@ static bool niExist(const std::string& path)
        return false;
 }
 
-static int crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R, bool isAppNI = false)
+static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R, bool isAppNI = false)
 {
        if (!isFileExist(dllPath)) {
                fprintf(stderr, "dll file is not exist : %s\n", dllPath.c_str());
-               return -1;
+               return NI_ERROR_NO_SUCH_FILE;
        }
 
        if (!isManagedAssembly(dllPath)) {
                fprintf(stderr, "Input file is not a dll file : %s\n", dllPath.c_str());
-               return -1;
+               return NI_ERROR_INVALID_PARAMETER;
        }
 
        if (niExist(dllPath)) {
                fprintf(stderr, "Already ni file is exist for %s\n", dllPath.c_str());
-               return -1;
+               return NI_ERROR_ALREADY_EXIST;
        }
 
        std::string absDllPath = absolutePath(dllPath);
        std::string absNiPath = getNiFilePath(dllPath);
        if (absNiPath.empty()) {
                fprintf(stderr, "Fail to get ni file name\n");
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
 
        if (isAppNI) {
@@ -182,7 +182,7 @@ static int crossgen(const std::string& dllPath, const std::string& appPath, bool
 
        pid_t pid = fork();
        if (pid == -1)
-               return -1;
+               return NI_ERROR_UNKNOWN;
 
        if (pid > 0) {
                int status;
@@ -192,10 +192,10 @@ static int crossgen(const std::string& dllPath, const std::string& appPath, bool
                        // niEixst() return false for System.Private.Corelib.dll
                        if (isFileExist(absNiPath)) {
                                updateNiFileInfo(absDllPath, absNiPath);
-                               return 0;
+                               return NI_ERROR_NONE;
                        } else {
                                fprintf(stderr, "Fail to create native image for %s\n", dllPath.c_str());
-                               return -1;
+                               return NI_ERROR_NO_SUCH_FILE;
                        }
                }
        } else {
@@ -232,10 +232,10 @@ static int crossgen(const std::string& dllPath, const std::string& appPath, bool
                exit(0);
        }
 
-       return 0;
+       return NI_ERROR_NONE;
 }
 
-static int getRootPath(std::string pkgId, std::string& rootPath)
+static ni_error_e getRootPath(std::string pkgId, std::string& rootPath)
 {
        int ret = 0;
        char *path = 0;
@@ -244,32 +244,32 @@ static int getRootPath(std::string pkgId, std::string& rootPath)
 
        if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
                _ERR("Failed to get UID");
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
 
        pkgmgrinfo_pkginfo_h handle;
        if (uid == 0) {
                ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &handle);
                if (ret != PMINFO_R_OK)
-                       return -1;
+                       return NI_ERROR_UNKNOWN;
        } else {
                ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &handle);
                if (ret != PMINFO_R_OK)
-                       return -1;
+                       return NI_ERROR_UNKNOWN;
        }
 
        ret = pkgmgrinfo_pkginfo_get_root_path(handle, &path);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
        rootPath = path;
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
 
-       return 0;
+       return NI_ERROR_NONE;
 }
 
-
+// callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
 static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
 {
        char *pkgId = NULL;
@@ -318,7 +318,7 @@ static void createCoreLibNI(bool enableR2R)
        }
 }
 
-int initNICommon(NiCommonOption* option)
+ni_error_e initNICommon(NiCommonOption* option)
 {
 #if defined(__arm__)
        // get interval value
@@ -331,19 +331,19 @@ int initNICommon(NiCommonOption* option)
 
        if (initializePluginManager("normal")) {
                fprintf(stderr, "Fail to initialize plugin manager\n");
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
        if (initializePathManager(option->runtimeDir, option->tizenFXDir, option->extraDirs)) {
                fprintf(stderr, "Fail to initialize path manager\n");
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
 
        __tpa = getTPA();
 
-       return 0;
+       return NI_ERROR_NONE;
 #else
        fprintf(stderr, "crossgen supports arm architecture only. skip ni file generation\n");
-       return -1;
+       return NI_ERROR_NOT_SUPPORTED;
 #endif
 }
 
@@ -364,9 +364,15 @@ void createNiPlatform(bool enableR2R)
        createNiUnderDirs(platformDirs, 2, enableR2R);
 }
 
-int createNiDll(const std::string& dllPath, bool enableR2R)
+ni_error_e createNiDll(const std::string& dllPath, bool enableR2R)
 {
        createCoreLibNI(enableR2R);
+       // System.Private.CoreLib.dll is generated in the createCoreLibNI function.
+       // Skip if input dll is System.Private.CoreLib.dll
+       if (dllPath.find("System.Private.CoreLib.dll") != std::string::npos) {
+               return NI_ERROR_NONE;
+       }
+
        return crossgen(dllPath, std::string(), enableR2R);
 }
 
@@ -394,12 +400,12 @@ void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R,
        }
 }
 
-int createNiUnderPkgRoot(const std::string& pkgName, bool enableR2R)
+ni_error_e createNiUnderPkgRoot(const std::string& pkgName, bool enableR2R)
 {
        std::string pkgRoot;
-       if (getRootPath(pkgName, pkgRoot) < 0) {
+       if (getRootPath(pkgName, pkgRoot) != NI_ERROR_NONE) {
                fprintf(stderr, "Failed to get root path from [%s]\n", pkgName.c_str());
-               return -1;
+               return NI_ERROR_INVALID_PACKAGE;
        }
 
        std::string binDir = concatPath(pkgRoot, "bin");
@@ -408,15 +414,15 @@ int createNiUnderPkgRoot(const std::string& pkgName, bool enableR2R)
 
        createNiUnderDirs(paths, 2, enableR2R, true);
 
-       return 0;
+       return NI_ERROR_NONE;
 }
 
-int createNiDllUnderPkgRoot(const std::string& pkgName, const std::string& dllPath, bool enableR2R)
+ni_error_e createNiDllUnderPkgRoot(const std::string& pkgName, const std::string& dllPath, bool enableR2R)
 {
        std::string pkgRoot;
        if (getRootPath(pkgName, pkgRoot) < 0) {
                fprintf(stderr, "Failed to get root path from [%s]\n", pkgName.c_str());
-               return -1;
+               return NI_ERROR_INVALID_PACKAGE;
        }
 
        std::string binDir = concatPath(pkgRoot, "bin");
@@ -463,12 +469,12 @@ void removeNiUnderDirs(const std::string rootPaths[], int count)
                scanFilesInDir(rootPaths[i], convert, -1);
 }
 
-int removeNiUnderPkgRoot(const std::string& pkgName)
+ni_error_e removeNiUnderPkgRoot(const std::string& pkgName)
 {
        std::string pkgRoot;
        if (getRootPath(pkgName, pkgRoot) < 0) {
                fprintf(stderr, "Failed to get root path from [%s]\n", pkgName.c_str());
-               return -1;
+               return NI_ERROR_INVALID_PACKAGE;
        }
 
        std::string binDir = concatPath(pkgRoot, "bin");
@@ -491,34 +497,34 @@ int removeNiUnderPkgRoot(const std::string& pkgName)
                }
        }
 
-       return 0;
+       return NI_ERROR_NONE;
 }
 
-int regenerateAppNI(bool enableR2R)
+ni_error_e regenerateAppNI(bool enableR2R)
 {
        int ret = 0;
        pkgmgrinfo_appinfo_metadata_filter_h handle;
 
        ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
        if (ret != PMINFO_R_OK)
-               return -1;
+               return NI_ERROR_UNKNOWN;
 
        ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, AOT_METADATA_VALUE);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
 
        ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, appAotCb, &enableR2R);
        if (ret != PMINFO_R_OK) {
                fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n");
                pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-               return -1;
+               return NI_ERROR_UNKNOWN;
        }
 
        fprintf(stderr, "Success pkgmgrinfo_appinfo_metadata_filter_foreach\n");
 
        pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-       return 0;
+       return NI_ERROR_NONE;
 }