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

preflight-checks.py 4.6KB

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