verify.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (c) 2021, Open Source Robotics Foundation
  2. # All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. # * Neither the name of the Willow Garage, Inc. nor the names of its
  13. # contributors may be used to endorse or promote products derived from
  14. # this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. # POSSIBILITY OF SUCH DAMAGE.
  27. from . import find_package
  28. def verify_rules(config, rules_to_check, all_rules, include_found=False):
  29. """
  30. Verify rosdep rules for supported platforms.
  31. For all platforms supported in the YAML configuration, verify that the
  32. repositories contain the packages listed in the rosdep rules.
  33. :param config: the parsed YAML configuration.
  34. :param rules_to_check: rosdep rules to be checked.
  35. :param all_rules: full rosdep rules to check for individual version rules.
  36. :param include_found: in addition to missing rules, also yield those found.
  37. :returns: a tuple of:
  38. - OS name
  39. - OS version
  40. - OS architecture
  41. - rosdep key
  42. - package name
  43. - corresponding package entry, if found
  44. """
  45. for key, rules in rules_to_check.items():
  46. for os_name, os_rules in rules.items():
  47. if os_name not in config['package_sources']:
  48. continue
  49. packages_to_check = {}
  50. if not isinstance(os_rules, dict):
  51. for os_ver in config['supported_versions'].get(os_name, ()):
  52. packages_to_check[os_ver] = os_rules
  53. else:
  54. packages_to_check = os_rules
  55. if '*' in os_rules:
  56. for os_ver in config['supported_versions'].get(os_name, ()):
  57. if os_ver not in all_rules[key][os_name]:
  58. packages_to_check.setdefault(os_ver, os_rules['*'])
  59. del packages_to_check['*']
  60. for os_ver, packages in packages_to_check.items():
  61. if os_ver not in config['supported_versions'].get(os_name, ()):
  62. continue
  63. if isinstance(packages, dict) and \
  64. tuple(packages.keys()) == ('packages',):
  65. packages = packages['packages']
  66. if not isinstance(packages, list):
  67. # Probably a dict specifying the key type, which is not
  68. # currently supported
  69. continue
  70. for package in packages or []:
  71. for needle, haystack in config['name_replacements'].get(
  72. os_name, {}).get(os_ver, {}).items():
  73. package = package.replace(needle, haystack)
  74. for os_arch in config['supported_arches'][os_name]:
  75. res = find_package(config, package, os_name, os_ver, os_arch)
  76. if not res or include_found:
  77. yield (os_name, os_ver, os_arch, key, package, res)