aboutsummaryrefslogtreecommitdiffstats
path: root/passes/cmds/plugin.cc
diff options
context:
space:
mode:
authorBenedikt Tutzer <e1225461@student.tuwien.ac.at>2019-04-03 13:21:40 +0200
committerBenedikt Tutzer <e1225461@student.tuwien.ac.at>2019-04-03 13:21:40 +0200
commitfd7fb1377d4d30d692c78eb55173198339fea17d (patch)
tree3bbcf7ddcbe3868401d0a83665a253e5058fb052 /passes/cmds/plugin.cc
parentbbfb43006d2a7d67d06ee151a1b8ad05ec5b1750 (diff)
downloadyosys-fd7fb1377d4d30d692c78eb55173198339fea17d.tar.gz
yosys-fd7fb1377d4d30d692c78eb55173198339fea17d.tar.bz2
yosys-fd7fb1377d4d30d692c78eb55173198339fea17d.zip
Added cross-platform support for plugin-paths
Diffstat (limited to 'passes/cmds/plugin.cc')
-rw-r--r--passes/cmds/plugin.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/passes/cmds/plugin.cc b/passes/cmds/plugin.cc
index bb1ec8716..60dab38dd 100644
--- a/passes/cmds/plugin.cc
+++ b/passes/cmds/plugin.cc
@@ -26,6 +26,7 @@
#ifdef WITH_PYTHON
# include <boost/algorithm/string/predicate.hpp>
# include <Python.h>
+# include <experimental/filesystem>
#endif
YOSYS_NAMESPACE_BEGIN
@@ -51,25 +52,28 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
#endif
#ifdef WITH_PYTHON
- if(boost::algorithm::ends_with(filename, ".py"))
+
+ std::experimental::filesystem::path full_path(filename);
+
+ if(strcmp(full_path.extension().c_str(), ".py") == 0)
{
- int last_slash = filename.find_last_of('/');
- std::string path = filename.substr(0, last_slash);
- filename = filename.substr(last_slash+1, filename.size());
+ std::string path(full_path.parent_path().c_str());
+ filename = full_path.filename().c_str();
filename = filename.substr(0,filename.size()-3);
PyRun_SimpleString(("sys.path.insert(0,\""+path+"\")").c_str());
+ PyErr_Print();
PyObject *filename_p = PyUnicode_FromString(filename.c_str());
if(filename_p == NULL)
{
PyErr_Print();
- log_cmd_error("Issues converting `%s' to Python\n", filename.c_str());
+ log_cmd_error("Issues converting `%s' to Python\n", full_path.filename().c_str());
return;
}
PyObject *module_p = PyImport_Import(filename_p);
if(module_p == NULL)
{
PyErr_Print();
- log_cmd_error("Can't load python module `%s'\n", filename.c_str());
+ log_cmd_error("Can't load python module `%s'\n", full_path.filename().c_str());
return;
}
loaded_python_plugins[orig_filename] = module_p;