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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #
  2. # preflight-checks.py
  3. # Check for common issues prior to compiling
  4. #
  5. import os
  6. import re
  7. Import("env")
  8. def get_envs_for_board(board):
  9. if board.startswith("BOARD_"):
  10. board = board[6:]
  11. with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f:
  12. board_found = ""
  13. r=re.compile(r"if\s+MB\((.+)\)")
  14. for line in f.readlines():
  15. mbs = r.findall(line)
  16. if mbs:
  17. board_found = board if board in re.split(r",\s*", mbs[0]) else ""
  18. if board_found and "#include " in line and "env:" in line:
  19. return re.findall(r"env:\w+", line)
  20. return []
  21. def check_envs(build_env, base_envs, config):
  22. if build_env in base_envs:
  23. return True
  24. ext = config.get(build_env, 'extends', default=None)
  25. if ext:
  26. if isinstance(ext, str):
  27. return check_envs(ext, base_envs, config)
  28. elif isinstance(ext, list):
  29. for ext_env in ext:
  30. if check_envs(ext_env, base_envs, config):
  31. return True
  32. return False
  33. # Sanity checks:
  34. if 'PIOENV' not in env:
  35. raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
  36. if 'MARLIN_FEATURES' not in env:
  37. raise SystemExit("Error: this script should be used after common Marlin scripts")
  38. if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
  39. raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
  40. build_env = env['PIOENV']
  41. motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
  42. base_envs = get_envs_for_board(motherboard)
  43. config = env.GetProjectConfig()
  44. result = check_envs("env:"+build_env, base_envs, config)
  45. if not result:
  46. err = "Error: your selected build environment '%s' is not compatible with MOTHERBOARD=%s in Configuration.h. " \
  47. "Please use one of compatible build environments for this board: %s" % \
  48. (build_env, motherboard, ",".join([e[4:] for e in base_envs if e.startswith("env:")]))
  49. raise SystemExit(err)
  50. #
  51. # Check for Config files in two common incorrect places
  52. #
  53. for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
  54. for f in [ "Configuration.h", "Configuration_adv.h" ]:
  55. if os.path.isfile(os.path.join(p, f)):
  56. err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
  57. raise SystemExit(err)