From 918168689f9987496b2f65fc1400212f85484579 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=B5=9C=EC=A2=85=ED=97=8C/MDE=20Lab=28SR=29/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 13 Nov 2023 12:55:33 +0900 Subject: [PATCH] Refactoring the fallback graph of RID/TFM (#488) --- NativeLauncher/tool/multi_target_resolver.cc | 145 +++++++++------------------ 1 file changed, 48 insertions(+), 97 deletions(-) diff --git a/NativeLauncher/tool/multi_target_resolver.cc b/NativeLauncher/tool/multi_target_resolver.cc index 38416a6..674ef20 100644 --- a/NativeLauncher/tool/multi_target_resolver.cc +++ b/NativeLauncher/tool/multi_target_resolver.cc @@ -15,44 +15,30 @@ */ #include - #include -#include #include "log.h" #include "utils.h" #include "multi_target_resolver.h" -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 platform_version_list; +static const char* __TIZEN_RID_VERSION_KEY = "db/dotnet/tizen_rid_version"; //8.0.0:7.0.0:6.5.0:6.0.0:5.5.0:5.0.0:4.0.0 +static const char* __TIZEN_TFM_SUPPORT_KEY = "db/dotnet/tizen_tfm_support"; //net6.0-tizen8.0:net6.0-tizen:net6.0:tizen10.0:tizen90:tizen80:tizen70:tizen60:tizen50:tizen40 + /* 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 +4 | linux-{arch}, linux | tizen10.0 ~ 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; -} - // Guided by Appfw, vconf daemon does not run at mic stage. // So vconf_get_* api does not work normally. -// Therefore, it provides a second chance to read the file when vconf_get_* is null. +// Therefore, it is changed to manage as a file instead of using vconf API. // /usr/share/dotnet.tizen/lib/dotnet_resolving.info static std::string getDotnetResolvingInfo(const char* key) { @@ -64,31 +50,16 @@ static std::string getDotnetResolvingInfo(const char* key) return line.substr(line.rfind(" ") + 1); } } - _ERR("Faield to get vconf. %s is null", key); return ""; } static std::vector getRidFallbackGraph() { - std::string tizen_rid_version; - char* tizen_rid_version_value = vconf_get_str(__TIZEN_RID_VERSION_KEY); - if (!tizen_rid_version_value) { - _INFO("Faield to get vconf. So, Read the dotnet_resolving.info file"); - tizen_rid_version = getDotnetResolvingInfo(__TIZEN_RID_VERSION_KEY); - } else { - tizen_rid_version = std::string(tizen_rid_version_value); - free(tizen_rid_version_value); - } - + std::string tizen_rid_version = getDotnetResolvingInfo(__TIZEN_RID_VERSION_KEY); std::vector rid_version; std::vector RID_FALLBACK_GRAPH; 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)); } @@ -106,49 +77,21 @@ static std::vector getRidFallbackGraph() static std::vector getTfmFallbackGraph() { - std::string dotnet_runtime_version; - char* dotnet_runtime_version_value = vconf_get_str(__DOTNET_RUNTIME_VERSION_KEY); - if (!dotnet_runtime_version_value) { - _INFO("Faield to get vconf. So, Read the dotnet_resolving.info file"); - dotnet_runtime_version = getDotnetResolvingInfo(__DOTNET_RUNTIME_VERSION_KEY); - } else { - dotnet_runtime_version = std::string(dotnet_runtime_version_value); - free(dotnet_runtime_version_value); - } - - std::vector tfm_list; - std::vector 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)); - } - - std::string tizen_tfm; - char* tizen_tfm_value = vconf_get_str(__TIZEN_TFM_SUPPORT_KEY); - if (!tizen_tfm_value) { - _INFO("Faield to get vconf. So, Read the dotnet_resolving.info file"); - tizen_tfm = getDotnetResolvingInfo(__TIZEN_TFM_SUPPORT_KEY); - } else { - tizen_tfm = std::string(tizen_tfm_value); - free(tizen_tfm_value); - } - splitPath(tizen_tfm, tfm_list); - tfm_list.push_back("net5.0"); + std::string tizen_tfm_support = getDotnetResolvingInfo(__TIZEN_TFM_SUPPORT_KEY); + std::vector TFM_FALLBACK_GRAPH; + splitPath(tizen_tfm_support, TFM_FALLBACK_GRAPH); + TFM_FALLBACK_GRAPH.push_back("net5.0"); std::vector 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)); + TFM_FALLBACK_GRAPH.push_back(std::string("netcoreapp" + version)); } std::vector 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)); + TFM_FALLBACK_GRAPH.push_back(std::string("netstandard" + version)); } - return tfm_list; + return TFM_FALLBACK_GRAPH; } // move all files under a certain directory to another directory @@ -189,37 +132,45 @@ int resolvePlatformSpecificFiles(const std::string& rootPath) // found best matched rid and tfm directory and copy all files to bin directory std::vector ridFallbackGraph = getRidFallbackGraph(); - for (auto& rid : ridFallbackGraph) { - std::string ridPath = concatPath(runtimesPath, rid); - if (isDirectory(ridPath)) { - _INFO("Found best matched rid (%s)", rid.c_str()); - // copy all files from /runtimes/${rid}/native to appBintPath if exist - std::string nativePath = concatPath(ridPath, "native"); - if (isDirectory(nativePath)) { - _INFO("Found best matched native path"); - if (!moveAllFilesTo(nativePath, appBinPath)) { - _ERR("Failed to copy files from native path"); - return -1; - } - } - - // found best matched tfm folder in the found rid folder - std::string libPath = concatPath(ridPath, "lib"); - std::vector tfmFallbackGraph = getTfmFallbackGraph(); - for (auto& tfm : tfmFallbackGraph) { - std::string tfmPath = concatPath(libPath, tfm); - if (isDirectory(tfmPath)) { - _INFO("Found best matched tfm (%s)", tfm .c_str()); - // copy all files from tfmPath to appBintPath - if (!moveAllFilesTo(tfmPath, appBinPath)) { - _ERR("Failed to copy files from tfm path"); - return -1; + try { + for (auto& rid : bf::recursive_directory_iterator(runtimesPath)) { + std::string ridPath = rid.path().string(); + if (bf::is_directory(ridPath) && strstr(ridPath.c_str(), ARCHITECTURE_IDENTIFIER) != NULL) { + for (auto& ridFG : ridFallbackGraph) { + if (!strcmp(ridPath.c_str(), ridFG.c_str())) { + std::string nativePath = concatPath(ridPath, "native"); + if (isDirectory(nativePath)) { + _INFO("Found best matched rid (%s)", ridFG.c_str()); + // copy all files from bin/runtimes/${rid}/native to appBintPath if exist + if (!moveAllFilesTo(nativePath, appBinPath)) { + _ERR("Failed to copy files from native path"); + return -1; + } + } + + // found best matched tfm folder in the found rid folder + std::string libPath = concatPath(ridPath, "lib"); + std::vector tfmFallbackGraph = getTfmFallbackGraph(); + for (auto& tfmFG : tfmFallbackGraph) { + std::string tfmPath = concatPath(libPath, tfmFG); + if (isDirectory(tfmPath)) { + _INFO("Found best matched tfm (%s)", tfmFG .c_str()); + // copy all files from bin/runtimes/${rid}/lib/${tfm} to appBintPath if exist + if (!moveAllFilesTo(tfmPath, appBinPath)) { + _ERR("Failed to copy files from tfm path"); + return -1; + } + break; + } + } + break; } - break; } + break; } - break; } + } catch (const bf::filesystem_error& error) { + _ERR("Failed to recursive directory: %s", error.what()); } // remove runtimes directory -- 2.7.4