*/
#include <string>
-
+#include <fstream>
#include <pkgmgr-info.h>
-#include <vconf.h>
#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<std::string> 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)
{
return line.substr(line.rfind(" ") + 1);
}
}
- _ERR("Faield to get vconf. %s is null", key);
return "";
}
static std::vector<std::string> 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<std::string> rid_version;
std::vector<std::string> 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));
}
static std::vector<std::string> 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<std::string> tfm_list;
- 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));
- }
-
- 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<std::string> TFM_FALLBACK_GRAPH;
+ splitPath(tizen_tfm_support, TFM_FALLBACK_GRAPH);
+ TFM_FALLBACK_GRAPH.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));
+ TFM_FALLBACK_GRAPH.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));
+ 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
// found best matched rid and tfm directory and copy all files to bin directory
std::vector<std::string> 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<std::string> 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(getFileName(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<std::string> 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
return 0;
}
-int resolveAllApps()
+void resolveAllApps()
{
int ret = 0;
pkgmgrinfo_appinfo_filter_h handle;
ret = pkgmgrinfo_appinfo_filter_create(&handle);
if (ret != PMINFO_R_OK) {
- return -1;
+ _SERR("Failed to create pkgmgrinfo");
+ return;
}
ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, "dotnet");
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_filter_destroy(handle);
- return -1;
+ _SERR("Failed to add pkgmgrinfo filter app type");
+ return;
}
ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, appResolveCb, NULL);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_filter_destroy(handle);
- return -1;
+ _SERR("Failed to remove unused multi-targeting files");
+ return;
}
pkgmgrinfo_appinfo_filter_destroy(handle);
-
- return 0;
}