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


roscompile
Author(s):
autogenerated on Wed Jun 19 2019 19:56:53