EnvironmentLoader, clean merge

This commit is contained in:
David Miller 2020-04-24 19:25:57 -04:00
parent b9002bb790
commit 75ee8f0604
4 changed files with 136 additions and 17 deletions

View File

@ -25,8 +25,8 @@
"variables": [
{
"name": "WSL",
"type": "BOOL",
"value": "TRUE"
"value": "TRUE",
"type": "BOOL"
}
]
},
@ -46,8 +46,8 @@
"variables": [
{
"name": "WSL",
"type": "BOOL",
"value": "TRUE"
"value": "TRUE",
"type": "BOOL"
}
]
},
@ -64,18 +64,18 @@
"variables": [
{
"name": "CMAKE_C_COMPILER",
"type": "STRING",
"value": "${env.cc}"
"value": "${env.cc}",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"type": "STRING",
"value": "${env.cxx}"
"value": "${env.cxx}",
"type": "STRING"
},
{
"name": "CMAKE_SYSROOT",
"type": "STRING",
"value": "${env.fexsysroot}"
"value": "${env.fexsysroot}",
"type": "STRING"
}
]
},
@ -92,18 +92,18 @@
"variables": [
{
"name": "CMAKE_C_COMPILER",
"type": "STRING",
"value": "${env.cc}"
"value": "${env.cc}",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"type": "STRING",
"value": "${env.cxx}"
"value": "${env.cxx}",
"type": "STRING"
},
{
"name": "CMAKE_SYSROOT",
"type": "STRING",
"value": "${env.fexsysroot}"
"value": "${env.fexsysroot}",
"type": "STRING"
}
]
},
@ -117,7 +117,7 @@
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_clang_x64" ],
"remoteMachineName": "${env.fexremote}", // string "-662331587;z.port0.org (username=ubuntu, port=22, authentication=PrivateKey)",
"remoteMachineName": "${env.fexremote}",
"remoteCMakeListsRoot": "$HOME/projects/.vs/${projectDirName}/src",
"remoteBuildRoot": "$HOME/projects/.vs/${projectDirName}/build/${name}",
"remoteInstallRoot": "$HOME/projects/.vs/${projectDirName}/install/${name}",

View File

@ -1,6 +1,7 @@
set(NAME Common)
set(SRCS
ArgumentLoader.cpp
EnvironmentLoader.cpp
Config.cpp
StringUtil.cpp)

View File

@ -0,0 +1,111 @@
#include <functional>
#include <filesystem>
#include <string_view>
#include <unordered_map>
#include "Common/Config.h"
#include "LogManager.h"
namespace FEX::EnvLoader {
using string = std::string;
using string_view = std::string_view;
void Load(char *const envp[])
{
std::unordered_map<string_view,string_view> EnvMap;
for(const char *const *pvar=envp; pvar && *pvar; pvar++) {
string_view Var(*pvar);
size_t pos = Var.rfind('=');
if (string::npos==pos)
continue;
string_view Ident = Var.substr(0,pos);
string_view Value = Var.substr(pos+1);
EnvMap[Ident]=Value;
}
std::function GetVar = [=](const string_view id) -> const string_view {
if (EnvMap.find(id) != EnvMap.end())
return EnvMap.at(id);
// If envp[] was empty, search using std::getenv()
const char* vs = std::getenv(id.data());
string_view sv(vs?vs:"");
return sv;
};
string_view Value;
{
if ((Value = GetVar("FEX_CORE")).size()) {
// Accept Numeric or name //
if (isdigit(Value[0])) Config::Add("Core", Value);
else {
uint32_t CoreVal = 0;
if (Value == string_view("irint")) CoreVal = 0; // default
else if (Value == string_view("irjit")) CoreVal = 1;
else if (Value == string_view("llvm")) CoreVal = 2;
else if (Value == string_view("host")) CoreVal = 3;
else if (Value == string_view("vm")) CoreVal = 4;
else { LogMan::Msg::D("FEX_CORE has invalid identifier"); }
Config::Add("Core", std::to_string(CoreVal));
}
}
if ((Value = GetVar("FEX_BREAK")).size()) {
if (isdigit(Value[0])) Config::Add("Break", Value);
}
if ((Value = GetVar("FEX_SINGLE_STEP")).size()) {
if (isdigit(Value[0])) {
Config::Add("SingleStep", Value);
Config::Add("MaxInst", std::to_string(1u));
}
}
else if ((Value = GetVar("FEX_MAX_INST")).size()) {
if (isdigit(Value[0])) Config::Add("MaxInst", Value);
}
if ((Value = GetVar("FEX_MULTIBLOCK")).size()) {
if (isdigit(Value[0])) Config::Add("Multiblock", Value);
}
if ((Value = GetVar("FEX_GDB_SERVER")).size()) {
if (isdigit(Value[0])) Config::Add("GdbServer", Value);
}
}
{
if ((Value = GetVar("FEX_ROOTFS")).size()) {
Config::Add("RootFS", Value);
if (!std::filesystem::exists(Value)) {
LogMan::Msg::D("FEX_ROOTFS '%s' doesn't exist", Value.data());
Config::Add("RootFS", "");
}
}
if ((Value = GetVar("FEX_UNIFIED_MEM")).size()) {
if (isdigit(Value[0])) Config::Add("UnifiedMemory", Value);
}
}
{
if ((Value = GetVar("FEX_DUMP_GPRS")).size()) {
if (isdigit(Value[0])) Config::Add("DumpGPRs", Value);
}
if ((Value = GetVar("FEX_IPC_CLIENT")).size()) {
if (isdigit(Value[0])) Config::Add("IPCClient", Value);
}
if ((Value = GetVar("FEX_ELF_TYPE")).size()) {
if (isdigit(Value[0])) Config::Add("ELFType", Value);
}
if ((Value = GetVar("FEX_IPCID")).size()) {
Config::Add("IPCID", Value);
}
}
}
}

View File

@ -0,0 +1,7 @@
#pragma once
namespace FEX::EnvLoader {
void Load(char *const envp[]);
}