check_examples_cmake_make.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/env python
  2. import json
  3. import os
  4. import pprint
  5. import subprocess
  6. import sys
  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. args = [sys.executable,
  39. get_idf_path('tools/find_apps.py'),
  40. '-p',
  41. get_idf_path('examples'),
  42. '--recursive',
  43. '--target', target,
  44. '--build-system', build_system]
  45. output = subprocess.check_output(args).decode('utf-8')
  46. o_list = output.split('\n')
  47. json_list = []
  48. for j in o_list:
  49. if j:
  50. json_list.append(json.loads(j))
  51. app_paths = []
  52. for j in json_list:
  53. app_paths.append(j['app_dir'])
  54. return _unify_paths(app_paths)
  55. def get_apps(target, build_system, ignorelist):
  56. apps = _get_apps(target, build_system)
  57. if len(ignorelist):
  58. return _exclude_by_pat_list(apps, ignorelist)
  59. else:
  60. return apps
  61. def get_cmake_ignore_list():
  62. print('- Getting CMake ignore list')
  63. return _file2linelist(
  64. get_idf_path('tools', 'ci',
  65. 'check_examples_cmake_make-cmake_ignore.txt'))
  66. def get_make_ignore_list():
  67. print('- Getting Make ignore list')
  68. return _file2linelist(
  69. get_idf_path('tools', 'ci',
  70. 'check_examples_cmake_make-make_ignore.txt'))
  71. def diff(first, second):
  72. print('- Comparing...')
  73. first = set(first)
  74. second = set(second)
  75. res = list(first - second) + list(second - first)
  76. return res
  77. def main():
  78. cmake_ignore = get_cmake_ignore_list()
  79. make_ignore = get_make_ignore_list()
  80. cmakes = get_apps('esp32', 'cmake', cmake_ignore)
  81. makes = get_apps('esp32', 'make', make_ignore)
  82. res = diff(cmakes, makes)
  83. if len(res):
  84. pp = pprint.PrettyPrinter(indent=4)
  85. print(
  86. '[ ERROR ] Some projects are not containing Make and Cmake project files:'
  87. )
  88. pp.pprint(res)
  89. raise ValueError('Test is not passed')
  90. else:
  91. print('[ DONE ]')
  92. if __name__ == '__main__':
  93. main()