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

preflight-checks.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #
  2. # preflight-checks.py
  3. # Check for common issues prior to compiling
  4. #
  5. import os,re,sys
  6. Import("env")
  7. def get_envs_for_board(board):
  8. with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
  9. if sys.platform == 'win32':
  10. envregex = r"(?:env|win):"
  11. elif sys.platform == 'darwin':
  12. envregex = r"(?:env|mac|uni):"
  13. elif sys.platform == 'linux':
  14. envregex = r"(?:env|lin|uni):"
  15. else:
  16. envregex = r"(?:env):"
  17. r = re.compile(r"if\s+MB\((.+)\)")
  18. if board.startswith("BOARD_"):
  19. board = board[6:]
  20. for line in file:
  21. mbs = r.findall(line)
  22. if mbs and board in re.split(r",\s*", mbs[0]):
  23. line = file.readline()
  24. found_envs = re.match(r"\s*#include .+" + envregex, line)
  25. if found_envs:
  26. envlist = re.findall(envregex + r"(\w+)", line)
  27. return [ "env:"+s for s in envlist ]
  28. return []
  29. def check_envs(build_env, board_envs, config):
  30. if build_env in board_envs:
  31. return True
  32. ext = config.get(build_env, 'extends', default=None)
  33. if ext:
  34. if isinstance(ext, str):
  35. return check_envs(ext, board_envs, config)
  36. elif isinstance(ext, list):
  37. for ext_env in ext:
  38. if check_envs(ext_env, board_envs, config):
  39. return True
  40. return False
  41. def sanity_check_target():
  42. # Sanity checks:
  43. if 'PIOENV' not in env:
  44. raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
  45. if 'MARLIN_FEATURES' not in env:
  46. raise SystemExit("Error: this script should be used after common Marlin scripts")
  47. if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
  48. raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
  49. build_env = env['PIOENV']
  50. motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
  51. board_envs = get_envs_for_board(motherboard)
  52. config = env.GetProjectConfig()
  53. result = check_envs("env:"+build_env, board_envs, config)
  54. if not result:
  55. err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
  56. ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
  57. raise SystemExit(err)
  58. #
  59. # Check for Config files in two common incorrect places
  60. #
  61. for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
  62. for f in [ "Configuration.h", "Configuration_adv.h" ]:
  63. if os.path.isfile(os.path.join(p, f)):
  64. err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
  65. raise SystemExit(err)
  66. #
  67. # Check for old files indicating an entangled Marlin (mixing old and new code)
  68. #
  69. mixedin = []
  70. for p in [ os.path.join(env['PROJECT_DIR'], "Marlin/src/lcd/dogm") ]:
  71. for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]:
  72. if os.path.isfile(os.path.join(p, f)):
  73. mixedin += [ f ]
  74. if mixedin:
  75. err = "ERROR: Old files fell into your Marlin folder. Remove %s and try again" % ", ".join(mixedin)
  76. raise SystemExit(err)
  77. # Detect that 'vscode init' is running
  78. from SCons.Script import COMMAND_LINE_TARGETS
  79. if "idedata" not in COMMAND_LINE_TARGETS:
  80. sanity_check_target()