plugins.py
Go to the documentation of this file.
1 import collections
2 import os
3 import re
4 
5 from ros_introspection.plugin_xml import PluginXML
6 
7 from .manifest import enforce_tabbing_helper
8 from .util import roscompile
9 
10 PLUGIN_PATTERN = r'PLUGINLIB_EXPORT_CLASS\(([^:]+)::([^,]+),\s*([^:]+)::([^,]+)\)'
11 PLUGIN_RE = re.compile(PLUGIN_PATTERN)
12 
13 
14 def plugin_xml_by_package(package):
15  xmls = collections.defaultdict(list)
16  for xml in package.plugin_configs:
17  for parent_pkg in xml.parent_pkgs:
18  xmls[parent_pkg].append(xml)
19  return xmls
20 
21 
22 def contains_library(xmls, library, pkg, name):
23  for xml in xmls:
24  if xml.contains_library(library, pkg, name):
25  return True
26  return False
27 
28 
29 def lookup_library(build_rules, rel_fn):
30  for library, deps in build_rules.items():
31  if rel_fn in deps:
32  return library
33 
34 
35 @roscompile
36 def check_plugins(package):
37  """Check that all the plugins are properly defined.
38 
39  We have three dictionaries
40  * The plugins that are defined by macros (defined_macros)
41  * The plugins that have associated configuration files (existing_plugins)
42  * The plugins that are linked by the manifest. (plugin_xml_by_package)
43  First, we reconcile the macros with the files.
44  Then we handle the manifest.
45  Then we make sure that the specific classes are in the configurations
46  """
47  defined_macros = package.source_code.search_for_pattern(PLUGIN_RE)
48  existing_plugins = plugin_xml_by_package(package)
49  defined_plugins = package.manifest.get_plugin_xmls()
50  build_rules = package.cmake.get_source_build_rules('add_library', resolve_target_name=True)
51 
52  for rel_fn, plugin_info in defined_macros.items():
53  library = lookup_library(build_rules, rel_fn)
54  # pkg2/name2 is the parent class
55  for pkg1, name1, pkg2, name2 in plugin_info:
56  # Create file if needed
57  if pkg2 not in existing_plugins:
58  xml_filename = '%s_plugins.xml' % pkg2
59  print('\tCreating %s' % xml_filename)
60  p_xml = PluginXML(xml_filename, os.path.join(package.root, xml_filename))
61  package.plugin_configs.append(p_xml)
62  existing_plugins[pkg2] = [p_xml]
63 
64  # Make sure plugins are used in manifest
65  for plugin_xml in existing_plugins[pkg2]:
66  if plugin_xml.rel_fn not in defined_plugins[pkg2]:
67  ex_el = package.manifest.add_plugin_export(pkg2, plugin_xml.rel_fn)
68  enforce_tabbing_helper(package.manifest, ex_el, 2)
69 
70  # Make sure the class is in the files
71  if not contains_library(existing_plugins[pkg2], library, pkg1, name1):
72  # insert into first
73  xml = existing_plugins[pkg2][0]
74  xml.insert_new_class(library, pkg1, name1, pkg2, name2)
def lookup_library(build_rules, rel_fn)
Definition: plugins.py:29
def check_plugins(package)
Definition: plugins.py:36
def plugin_xml_by_package(package)
Definition: plugins.py:14
def enforce_tabbing_helper(manifest, node, tabs=1)
Definition: manifest.py:62
def contains_library(xmls, library, pkg, name)
Definition: plugins.py:22


roscompile
Author(s):
autogenerated on Wed Mar 3 2021 03:56:01