My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preflight-checks.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, envregex):
  8. with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
  9. r = re.compile(r"if\s+MB\((.+)\)")
  10. if board.startswith("BOARD_"):
  11. board = board[6:]
  12. for line in file:
  13. mbs = r.findall(line)
  14. if mbs and board in re.split(r",\s*", mbs[0]):
  15. line = file.readline()
  16. found_envs = re.match(r"\s*#include .+" + envregex, line)
  17. if found_envs:
  18. return re.findall(envregex + r"(\w+)", line)
  19. return []
  20. def check_envs(build_env, board_envs, config):
  21. if build_env in board_envs:
  22. return True
  23. ext = config.get(build_env, 'extends', default=None)
  24. if ext:
  25. if isinstance(ext, str):
  26. return check_envs(ext, board_envs, config)
  27. elif isinstance(ext, list):
  28. for ext_env in ext:
  29. if check_envs(ext_env, board_envs, config):
  30. return True
  31. return False
  32. # Sanity checks:
  33. if 'PIOENV' not in env:
  34. raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
  35. if 'MARLIN_FEATURES' not in env:
  36. raise SystemExit("Error: this script should be used after common Marlin scripts")
  37. if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
  38. raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
  39. if sys.platform == 'win32':
  40. osregex = r"(?:env|win):"
  41. elif sys.platform == 'darwin':
  42. osregex = r"(?:env|mac|uni):"
  43. elif sys.platform == 'linux':
  44. osregex = r"(?:env|lin|uni):"
  45. else:
  46. osregex = r"(?:env):"
  47. build_env = env['PIOENV']
  48. motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
  49. board_envs = get_envs_for_board(motherboard, osregex)
  50. config = env.GetProjectConfig()
  51. result = check_envs(build_env, board_envs, config)
  52. if not result:
  53. err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
  54. (build_env, motherboard, ",".join([e[4:] for e in board_envs if re.match(r"^" + osregex, e)]))
  55. raise SystemExit(err)
  56. #
  57. # Check for Config files in two common incorrect places
  58. #
  59. for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
  60. for f in [ "Configuration.h", "Configuration_adv.h" ]:
  61. if os.path.isfile(os.path.join(p, f)):
  62. err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
  63. raise SystemExit(err)