test_build_caches.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from collections import OrderedDict
  2. import os
  3. from catkin_pkg.package import parse_package_string
  4. from ros_buildfarm.common import topological_order_packages
  5. from rosdistro import get_index
  6. from rosdistro.distribution_cache_generator import generate_distribution_cache
  7. from scripts import eol_distro_names
  8. from .fold_block import Fold
  9. INDEX_YAML = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'index.yaml'))
  10. def test_build_caches():
  11. with Fold():
  12. print("""Checking if the 'package.xml' files for all packages are fetchable.
  13. If this fails you can run 'rosdistro_build_cache index.yaml' to perform the same check locally.
  14. """)
  15. index = 'file://' + os.path.abspath(INDEX_YAML)
  16. index = get_index(index)
  17. dist_names = sorted(index.distributions.keys())
  18. dist_names = [n for n in dist_names if n not in eol_distro_names]
  19. errors = []
  20. caches = OrderedDict()
  21. for dist_name in dist_names:
  22. with Fold():
  23. try:
  24. cache = generate_distribution_cache(index, dist_name)
  25. except RuntimeError as e:
  26. errors.append(str(e))
  27. else:
  28. caches[dist_name] = cache
  29. # also check topological order to prevent circular dependencies
  30. for dist_name, cache in caches.items():
  31. pkgs = {}
  32. print("Parsing manifest files for '%s'" % dist_name)
  33. for pkg_name, pkg_xml in cache.release_package_xmls.items():
  34. # Collect parsing warnings and fail if version convention are not respected
  35. warnings = []
  36. pkgs[pkg_name] = parse_package_string(pkg_xml, warnings=warnings)
  37. for warning in warnings:
  38. if 'version conventions' in warning:
  39. errors.append('%s: %s' % (pkg_name, warning))
  40. else:
  41. print('%s: WARNING: %s' % (pkg_name, warning))
  42. print("Order all packages in '%s' topologically" % dist_name)
  43. try:
  44. topological_order_packages(pkgs)
  45. except RuntimeError as e:
  46. errors.append('%s: %s' % (dist_name, e))
  47. if errors:
  48. raise RuntimeError('\n'.join(errors))