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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if 'MARLIN_FEATURES' not in env:
  48. raise SystemExit("Error: this script should be used after common Marlin scripts")
  49. if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
  50. raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
  51. build_env = env['PIOENV']
  52. motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
  53. board_envs = get_envs_for_board(motherboard)
  54. config = env.GetProjectConfig()
  55. result = check_envs("env:"+build_env, board_envs, config)
  56. if not result:
  57. err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
  58. ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
  59. raise SystemExit(err)
  60. #
  61. # Check for Config files in two common incorrect places
  62. #
  63. for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
  64. for f in [ "Configuration.h", "Configuration_adv.h" ]:
  65. if os.path.isfile(os.path.join(p, f)):
  66. err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
  67. raise SystemExit(err)
  68. #
  69. # Give warnings on every build
  70. #
  71. warnfile = os.path.join(env['PROJECT_BUILD_DIR'], build_env, "src", "src", "inc", "Warnings.cpp.o")
  72. if os.path.exists(warnfile):
  73. os.remove(warnfile)
  74. #
  75. # Check for old files indicating an entangled Marlin (mixing old and new code)
  76. #
  77. mixedin = []
  78. p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "lcd", "dogm")
  79. for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]:
  80. if os.path.isfile(os.path.join(p, f)):
  81. mixedin += [ f ]
  82. if mixedin:
  83. err = "ERROR: Old files fell into your Marlin folder. Remove %s and try again" % ", ".join(mixedin)
  84. raise SystemExit(err)
  85. sanity_check_target()