My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

preflight-checks.py 3.1KB

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