My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

preflight-checks.py 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #
  2. # preflight-checks.py
  3. # Check for common issues prior to compiling
  4. #
  5. import pioutil
  6. if pioutil.is_pio_build():
  7. import os,re,sys
  8. Import("env")
  9. def get_envs_for_board(board):
  10. with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
  11. if sys.platform == 'win32':
  12. envregex = r"(?:env|win):"
  13. elif sys.platform == 'darwin':
  14. envregex = r"(?:env|mac|uni):"
  15. elif sys.platform == 'linux':
  16. envregex = r"(?:env|lin|uni):"
  17. else:
  18. envregex = r"(?:env):"
  19. r = re.compile(r"if\s+MB\((.+)\)")
  20. if board.startswith("BOARD_"):
  21. board = board[6:]
  22. for line in file:
  23. mbs = r.findall(line)
  24. if mbs and board in re.split(r",\s*", mbs[0]):
  25. line = file.readline()
  26. found_envs = re.match(r"\s*#include .+" + envregex, line)
  27. if found_envs:
  28. envlist = re.findall(envregex + r"(\w+)", line)
  29. return [ "env:"+s for s in envlist ]
  30. return []
  31. def check_envs(build_env, board_envs, config):
  32. if build_env in board_envs:
  33. return True
  34. ext = config.get(build_env, 'extends', default=None)
  35. if ext:
  36. if isinstance(ext, str):
  37. return check_envs(ext, board_envs, config)
  38. elif isinstance(ext, list):
  39. for ext_env in ext:
  40. if check_envs(ext_env, board_envs, config):
  41. return True
  42. return False
  43. def sanity_check_target():
  44. # Sanity checks:
  45. if 'PIOENV' not in env:
  46. raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
  47. # Require PlatformIO 6.1.1 or later
  48. vers = pioutil.get_pio_version()
  49. if vers < [6, 1, 1]:
  50. raise SystemExit("Error: Marlin requires PlatformIO >= 6.1.1. Use 'pio upgrade' to get a newer version.")
  51. if 'MARLIN_FEATURES' not in env:
  52. raise SystemExit("Error: this script should be used after common Marlin scripts")
  53. if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
  54. raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
  55. build_env = env['PIOENV']
  56. motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
  57. board_envs = get_envs_for_board(motherboard)
  58. config = env.GetProjectConfig()
  59. result = check_envs("env:"+build_env, board_envs, config)
  60. if not result:
  61. err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
  62. ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
  63. raise SystemExit(err)
  64. #
  65. # Check for Config files in two common incorrect places
  66. #
  67. for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
  68. for f in [ "Configuration.h", "Configuration_adv.h" ]:
  69. if os.path.isfile(os.path.join(p, f)):
  70. err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
  71. raise SystemExit(err)
  72. #
  73. # Find the name.cpp.o or name.o and remove it
  74. #
  75. def rm_ofile(subdir, name):
  76. build_dir = os.path.join(env['PROJECT_BUILD_DIR'], build_env);
  77. for outdir in [ build_dir, os.path.join(build_dir, "debug") ]:
  78. for ext in [ ".cpp.o", ".o" ]:
  79. fpath = os.path.join(outdir, "src", "src", subdir, name + ext)
  80. if os.path.exists(fpath):
  81. os.remove(fpath)
  82. #
  83. # Give warnings on every build
  84. #
  85. rm_ofile("inc", "Warnings")
  86. #
  87. # Rebuild 'settings.cpp' for EEPROM_INIT_NOW
  88. #
  89. if 'EEPROM_INIT_NOW' in env['MARLIN_FEATURES']:
  90. rm_ofile("module", "settings")
  91. #
  92. # Check for old files indicating an entangled Marlin (mixing old and new code)
  93. #
  94. mixedin = []
  95. p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "lcd", "dogm")
  96. for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]:
  97. if os.path.isfile(os.path.join(p, f)):
  98. mixedin += [ f ]
  99. p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "feature", "bedlevel", "abl")
  100. for f in [ "abl.cpp", "abl.h" ]:
  101. if os.path.isfile(os.path.join(p, f)):
  102. mixedin += [ f ]
  103. if mixedin:
  104. err = "ERROR: Old files fell into your Marlin folder. Remove %s and try again" % ", ".join(mixedin)
  105. raise SystemExit(err)
  106. sanity_check_target()