check_executables.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import argparse
  17. import os
  18. from sys import exit
  19. from idf_ci_utils import is_executable
  20. def _strip_each_item(iterable):
  21. res = []
  22. for item in iterable:
  23. if item:
  24. res.append(item.strip())
  25. return res
  26. IDF_PATH = os.getenv('IDF_PATH', os.getcwd())
  27. EXECUTABLE_LIST_FN = os.path.join(IDF_PATH, 'tools/ci/executable-list.txt')
  28. known_executables = _strip_each_item(open(EXECUTABLE_LIST_FN).readlines())
  29. def check_executable_list():
  30. ret = 0
  31. for index, fn in enumerate(known_executables):
  32. if not os.path.exists(os.path.join(IDF_PATH, fn)):
  33. print('{}:{} {} not exists. Please remove it manually'.format(EXECUTABLE_LIST_FN, index + 1, fn))
  34. ret = 1
  35. return ret
  36. def check_executables(files):
  37. ret = 0
  38. for fn in files:
  39. if not is_executable(fn):
  40. continue
  41. if fn not in known_executables:
  42. print('"{}" is not in {}'.format(fn, EXECUTABLE_LIST_FN))
  43. ret = 1
  44. return ret
  45. def main():
  46. parser = argparse.ArgumentParser()
  47. parser.add_argument('--action', choices=['executables', 'list'], required=True,
  48. help='if "executables", pass all your executables to see if it\'s in the list.'
  49. 'if "list", check if all items on your list exist')
  50. parser.add_argument('filenames', nargs='*', help='Filenames to check.')
  51. args = parser.parse_args()
  52. if args.action == 'executables':
  53. ret = check_executables(args.filenames)
  54. elif args.action == 'list':
  55. ret = check_executable_list()
  56. else:
  57. raise ValueError
  58. return ret
  59. if __name__ == '__main__':
  60. exit(main())