Change the location and value for generating vconf of runtime_version (#478)
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / multi_target_resolver.cc
index 317aae4..839f6a0 100644 (file)
 
 static const char* __TIZEN_RID_VERSION_KEY = "db/dotnet/tizen_rid_version";
 static const char* __TIZEN_TFM_SUPPORT_KEY = "db/dotnet/tizen_tfm_support";
+static const char* __DOTNET_RUNTIME_VERSION_KEY = "db/dotnet/runtime_version";
+static std::vector<std::string> platform_version_list;
+/*
+Priority | RID                 | TFM
+---------|---------------------|-----------------------
+1        | tizen.X.Y.Z-{arch}  | netX.Y-tizenX.Y ~ 6.5
+2        | tizen.X.Y.Z         | netX.Y-tizen
+3        | tizen-{arch}, tizen | netX.Y
+4        | linux-{arch}, linux | tizen90 ~ 40
+5        | unix-{arch}, unix   | net5.0
+6        | any                 | netcoreapp3.1 ~ 1.0
+7        | base                | netstandard2.1 ~ 1.0
+*/
+
+static int convertStrVersionToInt(const std::string& version)
+{
+       int ret = 0;
+       for (unsigned int i = 0; i < version.length(); i++) {
+               if (std::isdigit(int(version[i]))) {
+                       ret = ret * 10 + (int(version[i]) - '0');
+               }
+       }
+       return ret;
+}
 
 static std::vector<std::string> getRidFallbackGraph()
 {
        std::vector<std::string> RID_FALLBACK_GRAPH;
-       char* tizen_rid = vconf_get_str(__TIZEN_RID_VERSION_KEY);
-       if (tizen_rid) {
-               std::vector<std::string> version;
-               splitPath(tizen_rid, version);
-               std::reverse(std::begin(version), std::end(version));
-               for (unsigned int i = 0; i < version.size(); i++) {
-                       RID_FALLBACK_GRAPH.push_back(std::string("tizen." + version[i] + "-" + ARCHITECTURE_IDENTIFIER));
-                       RID_FALLBACK_GRAPH.push_back(std::string("tizen." + version[i]));
+       char* tizen_rid_version = vconf_get_str(__TIZEN_RID_VERSION_KEY);
+       if (tizen_rid_version) {
+               std::vector<std::string> rid_version;
+               splitPath(tizen_rid_version, rid_version);
+               std::reverse(std::begin(rid_version), std::end(rid_version));
+               for (auto& ridVersion : rid_version) {
+                       //.NET 6.0 is supported from Tizen 6.5.0
+                       if (convertStrVersionToInt(ridVersion) >= 650) {
+                               platform_version_list.push_back(ridVersion.substr(0, ridVersion.rfind('.')));
+                       }
+                       RID_FALLBACK_GRAPH.push_back(std::string("tizen." + ridVersion + "-" + ARCHITECTURE_IDENTIFIER));
+                       RID_FALLBACK_GRAPH.push_back(std::string("tizen." + ridVersion));
                }
-               free(tizen_rid);
+               free(tizen_rid_version);
        }
 
        std::vector<std::string> RID_FALLBACK_OS = {"tizen", "linux", "unix"};
-       for (unsigned int i = 0; i < RID_FALLBACK_OS.size(); i++) {
-               RID_FALLBACK_GRAPH.push_back(std::string(RID_FALLBACK_OS[i] + "-" + ARCHITECTURE_IDENTIFIER));
-               RID_FALLBACK_GRAPH.push_back(std::string(RID_FALLBACK_OS[i]));
+       for (auto& os : RID_FALLBACK_OS) {
+               RID_FALLBACK_GRAPH.push_back(std::string(os + "-" + ARCHITECTURE_IDENTIFIER));
+               RID_FALLBACK_GRAPH.push_back(std::string(os));
        }
        RID_FALLBACK_GRAPH.push_back("any");
        RID_FALLBACK_GRAPH.push_back("base");
@@ -54,14 +82,38 @@ static std::vector<std::string> getRidFallbackGraph()
 
 static std::vector<std::string> getTfmFallbackGraph()
 {
-       std::vector<std::string> tfmList;
+       std::vector<std::string> tfm_list;
+       char* dotnet_runtime_version = vconf_get_str(__DOTNET_RUNTIME_VERSION_KEY);
+       if (dotnet_runtime_version) {
+               std::vector<std::string> dotnet_version;
+               splitPath(dotnet_runtime_version, dotnet_version);
+               for (auto& dotnetVersion : dotnet_version) {
+                       for (auto& platformVersion : platform_version_list) {
+                               tfm_list.push_back(std::string("net" + dotnetVersion + "-tizen" + platformVersion));
+                       }
+                       tfm_list.push_back(std::string("net" + dotnetVersion + "-tizen"));
+                       tfm_list.push_back(std::string("net" + dotnetVersion));
+               }
+               free(dotnet_runtime_version);
+       }
+
        char* tizen_tfm = vconf_get_str(__TIZEN_TFM_SUPPORT_KEY);
        if (tizen_tfm) {
-               splitPath(tizen_tfm, tfmList);
+               splitPath(tizen_tfm, tfm_list);
                free(tizen_tfm);
        }
+       tfm_list.push_back("net5.0");
+
+       std::vector<std::string> netcoreapp_version = {"3.1", "3.0", "2.2", "2.1", "2.0", "1.1", "1.0"};
+       for (auto& version : netcoreapp_version) {
+               tfm_list.push_back(std::string("netcoreapp" + version));
+       }
+       std::vector<std::string> netstandard_version = {"2.1", "2.0", "1.6", "1.5", "1.4", "1.3", "1.2", "1.1", "1.0"};
+       for (auto& version : netstandard_version) {
+               tfm_list.push_back(std::string("netstandard" + version));
+       }
 
-       return tfmList;
+       return tfm_list;
 }
 
 // move all files under a certain directory to another directory
@@ -128,9 +180,9 @@ int resolvePlatformSpecificFiles(const std::string& rootPath)
                                                _ERR("Failed to copy files from tfm path");
                                                return -1;
                                        }
+                                       break;
                                }
                        }
-
                        break;
                }
        }
@@ -152,12 +204,12 @@ static int appResolveCb(pkgmgrinfo_appinfo_h handle, void *user_data)
 
        ret = pkgmgrinfo_appinfo_get_root_path(handle, &rootPath);
        if (ret != PMINFO_R_OK) {
-               fprintf(stderr, "Failed to get root path");
+               _SERR("Failed to get root path");
                return -1;
        }
 
        if (resolvePlatformSpecificFiles(rootPath) != 0) {
-               fprintf(stderr, "Failed to resolve platform specific resources (%s)\n", rootPath);
+               _SERR("Failed to resolve platform specific resources (%s)", rootPath);
                return -1;
        }
 
@@ -189,4 +241,3 @@ int resolveAllApps()
 
        return 0;
 }
-