make.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import logging
  2. import os
  3. import subprocess
  4. import sys
  5. import shlex
  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. @staticmethod
  42. def is_app(path):
  43. makefile_path = os.path.join(path, "Makefile")
  44. if not os.path.exists(makefile_path):
  45. return False
  46. with open(makefile_path, "r") as makefile:
  47. makefile_content = makefile.read()
  48. if MAKE_PROJECT_LINE not in makefile_content:
  49. return False
  50. return True