Skip to content

Commit af73a31

Browse files
mbr0wnmichael-west
authored andcommitted
rfnoc: Allow UHD_RFNOC_DIR to contain multiple paths
Like other environment variables, UHD_RFNOC_DIR can contain multiple paths. On Unix systems, paths are separated by :, on Windows, by ;. This is a valid shell statement: UHD_RFNOC_DIR=/path/to/rfnoc:$UHD_RFNOC_DIR This will prepend a new path to UHD_RFNOC_DIR. The prepended path will be used first, before the original ones.
1 parent ecae23b commit af73a31

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

host/lib/rfnoc/blockdef_xml_impl.cpp

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <boost/lexical_cast.hpp>
1717
#include <boost/property_tree/ptree.hpp>
1818
#include <boost/property_tree/xml_parser.hpp>
19+
#include <boost/tokenizer.hpp>
1920
#include <cstdlib>
2021

2122
using namespace uhd;
@@ -152,6 +153,40 @@ class blockdef_xml_impl : public blockdef
152153
public:
153154
enum xml_repr_t { DESCRIBES_BLOCK, DESCRIBES_COMPONENT };
154155

156+
static std::vector<std::string> get_env_paths(const std::string& var_name)
157+
{
158+
#ifdef UHD_PLATFORM_WIN32
159+
static const std::string env_path_sep = ";";
160+
#else
161+
static const std::string env_path_sep = ":";
162+
#endif /*UHD_PLATFORM_WIN32*/
163+
164+
#define path_tokenizer(inp) \
165+
boost::tokenizer<boost::char_separator<char>>( \
166+
inp, boost::char_separator<char>(env_path_sep.c_str()))
167+
168+
std::string var_value = "";
169+
char* env_var_str = NULL;
170+
env_var_str = std::getenv(var_name.c_str());
171+
if (env_var_str != NULL) {
172+
var_value = std::string(env_var_str);
173+
}
174+
175+
std::vector<std::string> paths;
176+
if (var_value.empty()) {
177+
return paths;
178+
}
179+
// convert to full filesystem path, filter blank paths
180+
for (const std::string& path_string : path_tokenizer(var_value)) {
181+
if (path_string.empty()) {
182+
continue;
183+
}
184+
paths.push_back(fs::system_complete(path_string).string());
185+
}
186+
187+
return paths;
188+
}
189+
155190
//! Returns a list of base paths for the XML files.
156191
// It is assumed that block definitions are in a subdir with name
157192
// XML_BLOCKS_SUBDIR and component definitions in a subdir with name
@@ -160,15 +195,20 @@ class blockdef_xml_impl : public blockdef
160195
{
161196
std::vector<boost::filesystem::path> paths;
162197

163-
// Path from environment variable
164-
if (std::getenv(XML_PATH_ENV.c_str()) != NULL) {
165-
paths.push_back(boost::filesystem::path(std::getenv(XML_PATH_ENV.c_str())));
198+
std::vector<std::string> xml_paths = get_env_paths(XML_PATH_ENV);
199+
for (std::string& str_path : xml_paths) {
200+
UHD_LOG_DEBUG("RFNOC", "Adding XML path: " << str_path);
201+
if (str_path.empty()) {
202+
continue;
203+
}
204+
paths.push_back(boost::filesystem::path(str_path.c_str()));
166205
}
167206

168207
// Finally, the default path
169208
const boost::filesystem::path pkg_path = uhd::get_pkg_path();
170209
paths.push_back(pkg_path / XML_DEFAULT_PATH);
171-
210+
UHD_LOG_DEBUG(
211+
"RFNOC", "Adding Default XML path: " << pkg_path / XML_DEFAULT_PATH);
172212
return paths;
173213
}
174214

0 commit comments

Comments
 (0)