suggest.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 make_suggestion(config, key, os_name):
  29. """
  30. Attempt to find packages which may satisfy a key based on the name.
  31. This function uses heuristics to suggest OS packages which may satisfy a
  32. key. Many of the heuristics do not apply to all platforms.
  33. :param config: the parsed YAML configuration.
  34. :param key: the name of the unsatisifed key.
  35. :param os_name: the name of the OS associated with the package.
  36. """
  37. os_version = config['supported_versions'][os_name][-1]
  38. os_arch = config['supported_arches'][os_name][0]
  39. # 1) Check for verbatim key
  40. suggestion = find_package(config, key, os_name, os_version, os_arch)
  41. if suggestion:
  42. print("Suggesting '%s' package for %s" % (suggestion.binary_name, os_name))
  43. return suggestion
  44. else:
  45. print("No '%s' package for %s %s (%s). Looking for variants..." % (
  46. key, os_name, os_version, os_arch))
  47. # 2) Try -devel in place of -dev
  48. if key.endswith('-dev'):
  49. suggestion = make_suggestion(config, key[:-4] + '-devel', os_name)
  50. if suggestion:
  51. return suggestion
  52. # 3) Try with 'lib' prefix
  53. if key.startswith('lib'):
  54. suggestion = make_suggestion(config, key[3:], os_name)
  55. if suggestion:
  56. return suggestion
  57. # 4) Try cmake(foo) and pkgconfig(foo)
  58. if key.endswith('-devel'):
  59. suggestion = make_suggestion(config, 'cmake(' + key[:-6] + ')', os_name)
  60. if suggestion:
  61. return suggestion
  62. suggestion = make_suggestion(config, 'pkgconfig(' + key[:-6] + ')', os_name)
  63. if suggestion:
  64. return suggestion