make.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import logging
  2. import os
  3. import shlex
  4. import subprocess
  5. import sys
  6. from .common import BuildSystem, BuildError
  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
  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. 'make print_flash_cmd',
  24. ]
  25. log_file = None
  26. build_stdout = sys.stdout
  27. build_stderr = sys.stderr
  28. if build_item.build_log_path:
  29. logging.info("Writing build log to {}".format(build_item.build_log_path))
  30. log_file = open(build_item.build_log_path, "w")
  31. build_stdout = log_file
  32. build_stderr = log_file
  33. for cmd in commands:
  34. cmd = shlex.split(cmd) if isinstance(cmd, string_type) else cmd
  35. try:
  36. subprocess.check_call(cmd, stdout=build_stdout, stderr=build_stderr, cwd=work_path)
  37. except subprocess.CalledProcessError as e:
  38. if log_file:
  39. log_file.close()
  40. raise BuildError("Build failed with exit code {}".format(e.returncode))
  41. build_item.size_json_fp = build_item.get_size_json_fp()
  42. @staticmethod
  43. def is_app(path):
  44. makefile_path = os.path.join(path, "Makefile")
  45. if not os.path.exists(makefile_path):
  46. return False
  47. with open(makefile_path, "r") as makefile:
  48. makefile_content = makefile.read()
  49. if MAKE_PROJECT_LINE not in makefile_content:
  50. return False
  51. return True
  52. @classmethod
  53. def supported_targets(cls, app_path):
  54. readme_supported_targets = cls._supported_targets(app_path)
  55. if readme_supported_targets and 'esp32' in readme_supported_targets:
  56. return ['esp32']
  57. else:
  58. return []