mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-03 21:09:12 +00:00 
			
		
		
		
	plugin: Re-vamped how plugin lookup was done to make it more consistent with the rest of yosys, and prevented a case where you could end up with .so.so on the end
				
					
				
			This commit is contained in:
		
							parent
							
								
									cee3cb31b9
								
							
						
					
					
						commit
						572c8df9a8
					
				
					 1 changed files with 21 additions and 11 deletions
				
			
		| 
						 | 
					@ -21,12 +21,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef YOSYS_ENABLE_PLUGINS
 | 
					#ifdef YOSYS_ENABLE_PLUGINS
 | 
				
			||||||
#  include <dlfcn.h>
 | 
					#  include <dlfcn.h>
 | 
				
			||||||
 | 
					#  include <boost/filesystem.hpp>
 | 
				
			||||||
 | 
					#  include <boost/algorithm/string/predicate.hpp>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef WITH_PYTHON
 | 
					#ifdef WITH_PYTHON
 | 
				
			||||||
#  include <boost/algorithm/string/predicate.hpp>
 | 
					 | 
				
			||||||
#  include <Python.h>
 | 
					#  include <Python.h>
 | 
				
			||||||
#  include <boost/filesystem.hpp>
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
YOSYS_NAMESPACE_BEGIN
 | 
					YOSYS_NAMESPACE_BEGIN
 | 
				
			||||||
| 
						 | 
					@ -41,20 +41,18 @@ std::map<std::string, std::string> loaded_plugin_aliases;
 | 
				
			||||||
void load_plugin(std::string filename, std::vector<std::string> aliases)
 | 
					void load_plugin(std::string filename, std::vector<std::string> aliases)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	std::string orig_filename = filename;
 | 
						std::string orig_filename = filename;
 | 
				
			||||||
 | 
						rewrite_filename(filename);
 | 
				
			||||||
 | 
						boost::filesystem::path full_path(filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (filename.find('/') == std::string::npos)
 | 
					 | 
				
			||||||
		filename = "./" + filename;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#ifdef WITH_PYTHON
 | 
						#ifdef WITH_PYTHON
 | 
				
			||||||
	if (!loaded_plugins.count(filename) && !loaded_python_plugins.count(filename)) {
 | 
						if (!loaded_plugins.count(orig_filename) && !loaded_python_plugins.count(orig_filename)) {
 | 
				
			||||||
	#else
 | 
						#else
 | 
				
			||||||
	if (!loaded_plugins.count(filename)) {
 | 
						if (!loaded_plugins.count(orig_filename)) {
 | 
				
			||||||
	#endif
 | 
						#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#ifdef WITH_PYTHON
 | 
							#ifdef WITH_PYTHON
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		boost::filesystem::path full_path(filename);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if(strcmp(full_path.extension().c_str(), ".py") == 0)
 | 
							if(strcmp(full_path.extension().c_str(), ".py") == 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::string path(full_path.parent_path().c_str());
 | 
								std::string path(full_path.parent_path().c_str());
 | 
				
			||||||
| 
						 | 
					@ -75,10 +73,23 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
 | 
				
			||||||
		#endif
 | 
							#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void *hdl = dlopen(filename.c_str(), RTLD_LAZY|RTLD_LOCAL);
 | 
							void *hdl = dlopen(filename.c_str(), RTLD_LAZY|RTLD_LOCAL);
 | 
				
			||||||
		if (hdl == NULL && orig_filename.find('/') == std::string::npos)
 | 
					
 | 
				
			||||||
			hdl = dlopen((proc_share_dirname() + "plugins/" + orig_filename + ".so").c_str(), RTLD_LAZY|RTLD_LOCAL);
 | 
							// We were unable to open the file, try to do so from the plugin directory
 | 
				
			||||||
 | 
							if (hdl == NULL && filename.find('/') == std::string::npos) {
 | 
				
			||||||
 | 
								hdl = dlopen([filename]() {
 | 
				
			||||||
 | 
									std::string new_path = proc_share_dirname() + "plugins/" + filename;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// Check if we need to append .so
 | 
				
			||||||
 | 
									if (new_path.find(".so") == std::string::npos)
 | 
				
			||||||
 | 
										new_path.append(".so");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									return new_path;
 | 
				
			||||||
 | 
								}().c_str(), RTLD_LAZY|RTLD_LOCAL);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (hdl == NULL)
 | 
							if (hdl == NULL)
 | 
				
			||||||
			log_cmd_error("Can't load module `%s': %s\n", filename.c_str(), dlerror());
 | 
								log_cmd_error("Can't load module `%s': %s\n", filename.c_str(), dlerror());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		loaded_plugins[orig_filename] = hdl;
 | 
							loaded_plugins[orig_filename] = hdl;
 | 
				
			||||||
		Pass::init_register();
 | 
							Pass::init_register();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -182,4 +193,3 @@ struct PluginPass : public Pass {
 | 
				
			||||||
} PluginPass;
 | 
					} PluginPass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
YOSYS_NAMESPACE_END
 | 
					YOSYS_NAMESPACE_END
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue