Skip to content

Commit

Permalink
[CR-1161728]: emconfig.json path issue if host code is in python. (#7687
Browse files Browse the repository at this point in the history
)

* CR-1161728 Resolved emconfig file issue for python host code

* Resolved python binary getSelfPath API issue

* Resolved getSlefPath API issue

* Resolved getSelfPath API issue in emulation layer

* Removed cout statements.

* Removed extra if condition

* Modified file existence with cwd

* Replaced file existence with boost::filesystem

* Replaced file existence with boost::filesystem for emconfig.json file

---------

Co-authored-by: Subrahmanyam Gundimeda <[email protected]>
  • Loading branch information
sgundime-xilinx and sgundime-xilinx authored Sep 7, 2023
1 parent 795bd77 commit 83fa507
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/runtime_src/core/pcie/emulation/common_em/config.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ namespace xclemulation{
return defaultValue;
}

static boost::filesystem::path get_file_absolutepath(const std::string& filename) {

boost::filesystem::path exe_parent_path {getExecutablePath()};
auto filepath = exe_parent_path / filename;

if (boost::filesystem::exists(filepath) == false) {
auto current_path = boost::filesystem::current_path();
filepath = current_path / filename;
if (boost::filesystem::exists(filepath) == false)
return boost::filesystem::path{};
}
return filepath;

}

void config::populateEnvironmentSetup(std::map<std::string,std::string>& mEnvironmentNameValueMap)
{
setenv("HW_EM_DISABLE_LATENCY", "true", true);
Expand Down Expand Up @@ -162,12 +177,14 @@ namespace xclemulation{
setXgqMode(getBoolValue(value,false));
}
else if (name == "user_pre_sim_script") {
std::string absolutePath = getAbsolutePath(value, getExecutablePath());
auto filepath = get_file_absolutepath(value);
std::string absolutePath = getAbsolutePath(value, filepath.parent_path().string());
setUserPreSimScript(absolutePath);
setenv("USER_PRE_SIM_SCRIPT", absolutePath.c_str(), true);
}
else if (name == "user_post_sim_script") {
std::string absolutePath = getAbsolutePath(value, getExecutablePath());
auto filepath = get_file_absolutepath(value);
std::string absolutePath = getAbsolutePath(value, filepath.parent_path().string());
setUserPostSimScript(absolutePath);
setenv("USER_POST_SIM_SCRIPT", absolutePath.c_str(), true);
}
Expand Down Expand Up @@ -205,7 +222,8 @@ namespace xclemulation{
}
}
else if (name == "wcfg_file_path") {
std::string path = getAbsolutePath(value, getExecutablePath());
auto filepath = get_file_absolutepath(value);
std::string path = getAbsolutePath(value, filepath.parent_path().string());
setWcfgFilePath(path);
}
else if(name == "enable_shared_memory")
Expand Down Expand Up @@ -403,13 +421,16 @@ namespace xclemulation{

static std::string getEmConfigFilePath()
{
std::string executablePath = getExecutablePath();
std::string emConfigPath = valueOrEmpty(std::getenv("EMCONFIG_PATH"));
if (!emConfigPath.empty()) {
executablePath = emConfigPath;
auto filename{"emconfig.json"};
auto filepath = get_file_absolutepath(filename);
boost::filesystem::path emconfig_env {valueOrEmpty(std::getenv("EMCONFIG_PATH"))};
if (emconfig_env.empty() == false) {
auto filepath_env_value = emconfig_env / "emconfig.json";
if (boost::filesystem::exists(filepath_env_value)) {
filepath = filepath_env_value;
}
}
std::string xclEmConfigfile = executablePath.empty()? "emconfig.json" :executablePath+ "/emconfig.json";
return xclEmConfigfile;
return filepath.string();
}

bool isXclEmulationModeHwEmuOrSwEmu()
Expand Down Expand Up @@ -440,9 +461,9 @@ namespace xclemulation{

std::string getEmDebugLogFile()
{
std::string executablePath = getExecutablePath();
std::string xclEmConfigfile = executablePath.empty()? "emulation_debug.log" :executablePath+ "/emulation_debug.log";
return xclEmConfigfile;
auto self_path = boost::filesystem::current_path();
auto em_debug_file_path = self_path / "emulation_debug.log";
return em_debug_file_path.string();
}

static std::string getCurrenWorkingDir()
Expand Down

0 comments on commit 83fa507

Please sign in to comment.