Skip to content

Added functions to retrieve tag files/configs #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
}