Added cross-platform support for plugin-paths
authorBenedikt Tutzer <e1225461@student.tuwien.ac.at>
Wed, 3 Apr 2019 11:21:40 +0000 (13:21 +0200)
committerBenedikt Tutzer <e1225461@student.tuwien.ac.at>
Wed, 3 Apr 2019 11:21:40 +0000 (13:21 +0200)
Makefile
passes/cmds/plugin.cc

index 6f7448843d5ca185431b7b5d541183477b02cb51..618e4b6032da9d8f0b0f360f295b3d7936b5210f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -270,9 +270,9 @@ endif
 
 ifeq ($(ENABLE_PYOSYS),1)
        ifeq ($(PYTHON_MAJOR_VERSION),3)
-               LDLIBS += -lpython$(PYTHON_VERSION)m -lboost_python-py$(subst .,,$(PYTHON_VERSION)) -lboost_system
+               LDLIBS += -lpython$(PYTHON_VERSION)m -lboost_python-py$(subst .,,$(PYTHON_VERSION)) -lboost_system  -lstdc++fs
        else
-               LDLIBS += -lpython$(PYTHON_VERSION) -lboost_python-py$(subst .,,$(PYTHON_VERSION)) -lboost_system
+               LDLIBS += -lpython$(PYTHON_VERSION) -lboost_python-py$(subst .,,$(PYTHON_VERSION)) -lboost_system  -lstdc++fs
        endif
 CXXFLAGS += -I/usr/include/python$(PYTHON_VERSION) -D WITH_PYTHON
 PY_WRAPPER_FILE = kernel/python_wrappers
index bb1ec8716ef6c811da84c38a60bbc1b3c4c2153d..60dab38dd0373c46337459d55a32269ce889aa45 100644 (file)
@@ -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;