Skip to content

Commit

Permalink
Added functions to retrieve tag files/configs
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Jun 18, 2024
1 parent f071df0 commit 728bce5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp")

file(COPY "${XCPP_TAGFILES_DIR}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/share/xeus-cpp")
file(COPY "${XCPP_TAGCONFS_DIR}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/etc/xeus-cpp")

# Versionning
# ===========

Expand Down
6 changes: 6 additions & 0 deletions include/xeus-cpp/xutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ namespace xcpp

XEUS_CPP_API
interpreter_ptr build_interpreter(int argc, char** argv);

XEUS_CPP_API
std::string retrieve_tagconf_dir();

XEUS_CPP_API
std::string retrieve_tagfile_dir();
}

#endif
5 changes: 3 additions & 2 deletions src/xinspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "xeus-cpp/xbuffer.hpp"
#include "xeus-cpp/xpreamble.hpp"
#include "xeus-cpp/xutils.hpp"

#include "xdemangle.hpp"
#include "xparser.hpp"
Expand Down Expand Up @@ -122,8 +123,8 @@ namespace xcpp

void inspect(const std::string& code, nl::json& kernel_res)
{
std::string tagconf_dir = XCPP_TAGCONFS_DIR;
std::string tagfiles_dir = XCPP_TAGFILES_DIR;
std::string tagconf_dir = retrieve_tagconf_dir();
std::string tagfiles_dir = retrieve_tagfile_dir();

nl::json tagconfs = read_tagconfs(tagconf_dir.c_str());

Expand Down
38 changes: 38 additions & 0 deletions src/xutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <unistd.h>
#endif

#include "xeus/xsystem.hpp"

#include "xeus-cpp/xutils.hpp"
#include "xeus-cpp/xinterpreter.hpp"
Expand Down Expand Up @@ -95,4 +96,41 @@ namespace xcpp
return interp_ptr;
}

std::string retrieve_tagconf_dir()
{
const char* tagconf_dir_env = std::getenv("XCPP_TAGCONFS_DIR");
if (tagconf_dir_env != nullptr)
{
return tagconf_dir_env;
}

std::string prefix = xeus::prefix_path();

#if defined (_WIN32)
const char separator = '\\';
#else
const char separator = '/';
#endif

return prefix + separator + "etc" + separator + "xeus-cpp" + separator + "tags.d";
}

std::string retrieve_tagfile_dir()
{
const char* tagfile_dir_env = std::getenv("XCPP_TAGFILES_DIR");
if (tagfile_dir_env != nullptr)
{
return tagfile_dir_env;
}

std::string prefix = xeus::prefix_path();

#if defined (_WIN32)
const char separator = '\\';
#else
const char separator = '/';
#endif

return prefix + separator + "share" + separator + "xeus-cpp" + separator + "tagfiles";
}
}

0 comments on commit 728bce5

Please sign in to comment.