make.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import logging
  2. import os
  3. import shlex
  4. import subprocess
  5. import sys
  6. from .common import BuildError, BuildSystem
  7. # Same for the Makefile projects:
  8. MAKE_PROJECT_LINE = r'include $(IDF_PATH)/make/project.mk'
  9. BUILD_SYSTEM_MAKE = 'make'
  10. try:
  11. string_type = basestring # type: ignore
  12. except NameError:
  13. string_type = str
  14. class MakeBuildSystem(BuildSystem):
  15. NAME = BUILD_SYSTEM_MAKE
  16. @classmethod
  17. def build(cls, build_item):
  18. build_path, work_path = cls.build_prepare(build_item)
  19. commands = [
  20. 'make clean',
  21. 'make defconfig',
  22. 'make all',
  23. # In case if secure_boot is enabled then for bootloader build need to add `bootloader` cmd
  24. 'make bootloader',
  25. 'make print_flash_cmd',
  26. ]
  27. log_file = None
  28. build_stdout = sys.stdout
  29. build_stderr = sys.stderr
  30. if build_item.build_log_path:
  31. logging.info('Writing build log to {}'.format(build_item.build_log_path))
  32. log_file = open(build_item.build_log_path, 'w')
  33. build_stdout = log_file
  34. build_stderr = log_file
  35. for cmd in commands:
  36. cmd = shlex.split(cmd) if isinstance(cmd, string_type) else cmd
  37. try:
  38. subprocess.check_call(cmd, stdout=build_stdout, stderr=build_stderr, cwd=work_path)
  39. except subprocess.CalledProcessError as e:
  40. if log_file:
  41. log_file.close()
  42. raise BuildError('Build failed with exit code {}'.format(e.returncode))
  43. build_item.size_json_fp = build_item.get_size_json_fp()
  44. @staticmethod
  45. def is_app(path):
  46. makefile_path = os.path.join(path, 'Makefile')
  47. if not os.path.exists(makefile_path):
  48. return False
  49. with open(makefile_path, 'r') as makefile:
  50. makefile_content = makefile.read()
  51. if MAKE_PROJECT_LINE not in makefile_content:
  52. return False
  53. return True
  54. @classmethod
  55. def supported_targets(cls, app_path):
  56. readme_supported_targets = cls._supported_targets(app_path)
  57. if readme_supported_targets and 'esp32' in readme_supported_targets:
  58. return ['esp32']
  59. else:
  60. return []