check_examples_cmake_make.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import pprint
  5. import json
  6. import subprocess
  7. # =============================================================================
  8. # Service funcs
  9. # =============================================================================
  10. def _build_path(path, *paths):
  11. return str(os.path.normpath(os.path.join(path, *paths)).replace("\\", "/"))
  12. def _unify_paths(path_list):
  13. return [_build_path(p) for p in path_list]
  14. def _exclude_by_pat_list(path_list, ignore_list):
  15. print("- Applying ignore list")
  16. path_list_res = list(path_list)
  17. for ign in ignore_list:
  18. if len(ign.strip()):
  19. for p in path_list:
  20. if p.find(ign) != -1:
  21. try:
  22. path_list_res.remove(p)
  23. except ValueError:
  24. pass
  25. return path_list_res
  26. def _file2linelist(path):
  27. with open(path) as f:
  28. lines = [line.rstrip() for line in f]
  29. return [str(line) for line in lines]
  30. # =============================================================================
  31. # Test funcs
  32. # =============================================================================
  33. def get_idf_path(path, *paths):
  34. IDF_PATH = os.getenv('IDF_PATH')
  35. return _build_path(IDF_PATH, path, *paths)
  36. def _get_apps(target, build_system):
  37. print("- Getting paths of apps")
  38. output = subprocess.check_output(
  39. sys.executable + " " + os.getenv('IDF_PATH') +
  40. "/tools/find_apps.py -p examples --recursive --target %s --build-system %s"
  41. % (target, build_system),
  42. shell=True)
  43. o_list = output.split("\n")
  44. json_list = []
  45. for j in o_list:
  46. if j:
  47. json_list.append(json.loads(j))
  48. app_paths = []
  49. for j in json_list:
  50. app_paths.append(j['app_dir'])
  51. return _unify_paths(app_paths)
  52. def get_apps(target, build_system, ignorelist):
  53. apps = _get_apps(target, build_system)
  54. if len(ignorelist):
  55. return _exclude_by_pat_list(apps, ignorelist)
  56. else:
  57. return apps
  58. def get_cmake_ignore_list():
  59. print("- Getting CMake ignore list")
  60. return _file2linelist(
  61. get_idf_path("tools", "ci",
  62. "check_examples_cmake_make-cmake_ignore.txt"))
  63. def get_make_ignore_list():
  64. print("- Getting Make ignore list")
  65. return _file2linelist(
  66. get_idf_path("tools", "ci",
  67. "check_examples_cmake_make-make_ignore.txt"))
  68. def diff(first, second):
  69. print("- Comparing...")
  70. first = set(first)
  71. second = set(second)
  72. res = list(first - second) + list(second - first)
  73. return res
  74. def main():
  75. cmake_ignore = get_cmake_ignore_list()
  76. make_ignore = get_make_ignore_list()
  77. cmakes = get_apps("esp32", "cmake", cmake_ignore)
  78. makes = get_apps("esp32", "make", make_ignore)
  79. res = diff(cmakes, makes)
  80. if len(res):
  81. pp = pprint.PrettyPrinter(indent=4)
  82. print(
  83. "[ ERROR ] Some projects are not containing Make and Cmake project files:"
  84. )
  85. pp.pprint(res)
  86. raise ValueError("Test is not passed")
  87. else:
  88. print("[ DONE ]")
  89. if __name__ == "__main__":
  90. main()