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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # Sanity checks:
  42. if 'PIOENV' not in env:
  43. raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
  44. if 'MARLIN_FEATURES' not in env:
  45. raise SystemExit("Error: this script should be used after common Marlin scripts")
  46. if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
  47. raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
  48. build_env = env['PIOENV']
  49. motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
  50. board_envs = get_envs_for_board(motherboard)
  51. config = env.GetProjectConfig()
  52. result = check_envs("env:"+build_env, board_envs, config)
  53. if not result:
  54. err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
  55. ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
  56. raise SystemExit(err)
  57. #
  58. # Check for Config files in two common incorrect places
  59. #
  60. for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
  61. for f in [ "Configuration.h", "Configuration_adv.h" ]:
  62. if os.path.isfile(os.path.join(p, f)):
  63. err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
  64. raise SystemExit(err)