Skip to content

Commit 426dd34

Browse files
authored
Added functions to retrieve tag files/configs (#143)
1 parent f071df0 commit 426dd34

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d)
3333
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp.in"
3434
"${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp")
3535

36+
file(COPY "${XCPP_TAGFILES_DIR}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/share/xeus-cpp")
37+
file(COPY "${XCPP_TAGCONFS_DIR}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/etc/xeus-cpp")
38+
3639
# Versionning
3740
# ===========
3841

include/xeus-cpp/xutils.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ namespace xcpp
3232

3333
XEUS_CPP_API
3434
interpreter_ptr build_interpreter(int argc, char** argv);
35+
36+
XEUS_CPP_API
37+
std::string retrieve_tagconf_dir();
38+
39+
XEUS_CPP_API
40+
std::string retrieve_tagfile_dir();
3541
}
3642

3743
#endif

src/xinspect.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "xeus-cpp/xbuffer.hpp"
1919
#include "xeus-cpp/xpreamble.hpp"
20+
#include "xeus-cpp/xutils.hpp"
2021

2122
#include "xdemangle.hpp"
2223
#include "xparser.hpp"
@@ -122,8 +123,8 @@ namespace xcpp
122123

123124
void inspect(const std::string& code, nl::json& kernel_res)
124125
{
125-
std::string tagconf_dir = XCPP_TAGCONFS_DIR;
126-
std::string tagfiles_dir = XCPP_TAGFILES_DIR;
126+
std::string tagconf_dir = retrieve_tagconf_dir();
127+
std::string tagfiles_dir = retrieve_tagfile_dir();
127128

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

src/xutils.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <unistd.h>
2323
#endif
2424

25+
#include "xeus/xsystem.hpp"
2526

2627
#include "xeus-cpp/xutils.hpp"
2728
#include "xeus-cpp/xinterpreter.hpp"
@@ -95,4 +96,41 @@ namespace xcpp
9596
return interp_ptr;
9697
}
9798

99+
std::string retrieve_tagconf_dir()
100+
{
101+
const char* tagconf_dir_env = std::getenv("XCPP_TAGCONFS_DIR");
102+
if (tagconf_dir_env != nullptr)
103+
{
104+
return tagconf_dir_env;
105+
}
106+
107+
std::string prefix = xeus::prefix_path();
108+
109+
#if defined(_WIN32)
110+
const char separator = '\\';
111+
#else
112+
const char separator = '/';
113+
#endif
114+
115+
return prefix + separator + "etc" + separator + "xeus-cpp" + separator + "tags.d";
116+
}
117+
118+
std::string retrieve_tagfile_dir()
119+
{
120+
const char* tagfile_dir_env = std::getenv("XCPP_TAGFILES_DIR");
121+
if (tagfile_dir_env != nullptr)
122+
{
123+
return tagfile_dir_env;
124+
}
125+
126+
std::string prefix = xeus::prefix_path();
127+
128+
#if defined(_WIN32)
129+
const char separator = '\\';
130+
#else
131+
const char separator = '/';
132+
#endif
133+
134+
return prefix + separator + "share" + separator + "xeus-cpp" + separator + "tagfiles";
135+
}
98136
}

0 commit comments

Comments
 (0)