plugins.py
Go to the documentation of this file.
00001 import os
00002 import collections
00003 from ros_introspection.plugin_xml import PluginXML
00004 from manifest import enforce_tabbing_helper
00005 from util import roscompile
00006 import re
00007 
00008 PLUGIN_PATTERN = 'PLUGINLIB_EXPORT_CLASS\(([^:]+)::([^,]+),\s*([^:]+)::([^,]+)\)'
00009 PLUGIN_RE = re.compile(PLUGIN_PATTERN)
00010 
00011 
00012 def plugin_xml_by_package(package):
00013     xmls = collections.defaultdict(list)
00014     for xml in package.plugin_configs:
00015         for parent_pkg in xml.parent_pkgs:
00016             xmls[parent_pkg].append(xml)
00017     return xmls
00018 
00019 
00020 def contains_library(xmls, library, pkg, name):
00021     for xml in xmls:
00022         if xml.contains_library(library, pkg, name):
00023             return True
00024     return False
00025 
00026 
00027 def lookup_library(build_rules, rel_fn):
00028     for library, deps in build_rules.iteritems():
00029         if rel_fn in deps:
00030             return library
00031 
00032 
00033 @roscompile
00034 def check_plugins(package):
00035     """ We have three dictionaries
00036           * The plugins that are defined by macros (defined_macros)
00037           * The plugins that have associated configuration files (existing_plugins)
00038           * The plugins that are linked by the manifest. (plugin_xml_by_package)
00039         First, we reconcile the macros with the files.
00040         Then we handle the manifest.
00041         Then we make sure that the specific classes are in the configurations
00042     """
00043     defined_macros = package.source_code.search_for_pattern(PLUGIN_RE)
00044     existing_plugins = plugin_xml_by_package(package)
00045     defined_plugins = package.manifest.get_plugin_xmls()
00046     build_rules = package.cmake.get_source_build_rules('add_library', resolve_target_name=True)
00047 
00048     for rel_fn, plugin_info in defined_macros.iteritems():
00049         library = lookup_library(build_rules, rel_fn)
00050         # pkg2/name2 is the parent class
00051         for pkg1, name1, pkg2, name2 in plugin_info:
00052             # Create file if needed
00053             if pkg2 not in existing_plugins:
00054                 xml_filename = '%s_plugins.xml' % pkg2
00055                 print('\tCreating %s' % xml_filename)
00056                 p_xml = PluginXML(xml_filename, os.path.join(package.root, xml_filename))
00057                 package.plugin_configs.append(p_xml)
00058                 existing_plugins[pkg2] = [p_xml]
00059 
00060             # Make sure plugins are used in manifest
00061             for plugin_xml in existing_plugins[pkg2]:
00062                 if plugin_xml.rel_fn not in defined_plugins[pkg2]:
00063                     ex_el = package.manifest.add_plugin_export(pkg2, plugin_xml.rel_fn)
00064                     enforce_tabbing_helper(package.manifest, ex_el, 2)
00065 
00066             # Make sure the class is in the files
00067             if not contains_library(existing_plugins[pkg2], library, pkg1, name1):
00068                 # insert into first
00069                 xml = existing_plugins[pkg2][0]
00070                 xml.insert_new_class(library, pkg1, name1, pkg2, name2)


roscompile
Author(s):
autogenerated on Wed Jun 19 2019 19:21:36