Merge "set environment for debugging by env_list" into tizen
authorEden Lee <bw1212.lee@samsung.com>
Thu, 26 Jul 2018 06:19:55 +0000 (06:19 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 26 Jul 2018 06:19:55 +0000 (06:19 +0000)
NativeLauncher/launcher/dotnet/dotnet_launcher.cc

index 676029c..d11c8f0 100644 (file)
@@ -20,6 +20,7 @@
 #include <string>
 #include <fstream>
 #include <vector>
+#include <sstream>
 
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -36,6 +37,7 @@
 #include "log_manager.h"
 
 #define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
+#define ENV_FILE_PATH "/usr/share/dotnet.tizen/lib/coreclr_env.list"
 
 namespace tizen {
 namespace runtime {
@@ -83,6 +85,37 @@ static std::string getExtraNativeLibDirs(const std::string& appRoot)
        return candidate;
 }
 
+
+static std::vector<std::string> __envList;
+
+static void setEnvFromFile()
+{
+       std::string envList;
+       std::ifstream inFile(ENV_FILE_PATH);
+
+       __envList.clear();
+
+       if (inFile) {
+               _INFO("coreclr_env.list is found");
+               inFile >> envList;
+
+               std::istringstream ss(envList);
+               std::string token;
+
+               while (std::getline(ss, token, ':')) {
+                       if (!token.empty()) {
+                               __envList.push_back(token);
+                       }
+               }
+
+               for (unsigned int i = 0; i < __envList.size(); i++) {
+                       putenv(const_cast<char *>(__envList[i].c_str()));
+               }
+       } else {
+               _INFO("coreclr_env.list file is not found. skip");
+       }
+}
+
 CoreRuntime::CoreRuntime(const char* mode) :
        initializeClr(nullptr),
        executeAssembly(nullptr),
@@ -136,6 +169,9 @@ int CoreRuntime::initialize(bool standalone)
        putenv(const_cast<char *>("UNW_ARM_UNWIND_METHOD=6"));
 #endif // __arm__
 
+       // read string from external file and set them to environment value.
+       setEnvFromFile();
+
        if (initializePathManager(std::string(), std::string(), std::string()) < 0) {
                _ERR("Failed to initialize PathManager");
                return -1;
@@ -267,6 +303,8 @@ void CoreRuntime::dispose()
        finalizePluginManager();
        finalizePathManager();
 
+       __envList.clear();
+
        _DBG("Dotnet runtime disposed");
 }