2021-02-25 15:15:55 +01:00
|
|
|
#
|
|
|
|
# preflight-checks.py
|
2021-02-27 01:03:11 +01:00
|
|
|
# Check for common issues prior to compiling
|
2021-02-25 15:15:55 +01:00
|
|
|
#
|
|
|
|
Import("env")
|
|
|
|
|
2021-04-17 21:19:33 +02:00
|
|
|
# Detect that 'vscode init' is running
|
|
|
|
from SCons.Script import COMMAND_LINE_TARGETS
|
|
|
|
if "idedata" in COMMAND_LINE_TARGETS:
|
|
|
|
env.Exit(0)
|
|
|
|
|
|
|
|
import os,re,sys
|
|
|
|
|
2021-03-19 06:05:30 +01:00
|
|
|
def get_envs_for_board(board):
|
2021-03-16 23:33:10 +01:00
|
|
|
with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
|
2021-03-19 06:05:30 +01:00
|
|
|
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
envregex = r"(?:env|win):"
|
|
|
|
elif sys.platform == 'darwin':
|
|
|
|
envregex = r"(?:env|mac|uni):"
|
|
|
|
elif sys.platform == 'linux':
|
|
|
|
envregex = r"(?:env|lin|uni):"
|
|
|
|
else:
|
|
|
|
envregex = r"(?:env):"
|
|
|
|
|
2021-03-16 23:33:10 +01:00
|
|
|
r = re.compile(r"if\s+MB\((.+)\)")
|
|
|
|
if board.startswith("BOARD_"):
|
|
|
|
board = board[6:]
|
|
|
|
|
|
|
|
for line in file:
|
2021-03-04 03:48:58 +01:00
|
|
|
mbs = r.findall(line)
|
2021-03-16 23:33:10 +01:00
|
|
|
if mbs and board in re.split(r",\s*", mbs[0]):
|
|
|
|
line = file.readline()
|
|
|
|
found_envs = re.match(r"\s*#include .+" + envregex, line)
|
|
|
|
if found_envs:
|
2021-03-19 06:05:30 +01:00
|
|
|
envlist = re.findall(envregex + r"(\w+)", line)
|
|
|
|
return [ "env:"+s for s in envlist ]
|
2021-03-04 03:48:58 +01:00
|
|
|
return []
|
2021-02-25 15:15:55 +01:00
|
|
|
|
2021-03-16 23:33:10 +01:00
|
|
|
def check_envs(build_env, board_envs, config):
|
|
|
|
if build_env in board_envs:
|
2021-03-04 03:48:58 +01:00
|
|
|
return True
|
|
|
|
ext = config.get(build_env, 'extends', default=None)
|
|
|
|
if ext:
|
|
|
|
if isinstance(ext, str):
|
2021-03-16 23:33:10 +01:00
|
|
|
return check_envs(ext, board_envs, config)
|
2021-03-04 03:48:58 +01:00
|
|
|
elif isinstance(ext, list):
|
|
|
|
for ext_env in ext:
|
2021-03-16 23:33:10 +01:00
|
|
|
if check_envs(ext_env, board_envs, config):
|
2021-03-04 03:48:58 +01:00
|
|
|
return True
|
|
|
|
return False
|
2021-02-25 15:15:55 +01:00
|
|
|
|
|
|
|
# Sanity checks:
|
|
|
|
if 'PIOENV' not in env:
|
2021-03-04 03:48:58 +01:00
|
|
|
raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
|
2021-02-25 15:15:55 +01:00
|
|
|
|
|
|
|
if 'MARLIN_FEATURES' not in env:
|
2021-03-04 03:48:58 +01:00
|
|
|
raise SystemExit("Error: this script should be used after common Marlin scripts")
|
2021-02-25 15:15:55 +01:00
|
|
|
|
|
|
|
if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
|
2021-03-04 03:48:58 +01:00
|
|
|
raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
|
2021-02-25 15:15:55 +01:00
|
|
|
|
|
|
|
build_env = env['PIOENV']
|
|
|
|
motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
|
2021-03-19 06:05:30 +01:00
|
|
|
board_envs = get_envs_for_board(motherboard)
|
2021-02-25 15:15:55 +01:00
|
|
|
config = env.GetProjectConfig()
|
2021-03-19 06:05:30 +01:00
|
|
|
result = check_envs("env:"+build_env, board_envs, config)
|
2021-02-25 15:15:55 +01:00
|
|
|
|
|
|
|
if not result:
|
2021-03-05 11:30:52 +01:00
|
|
|
err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
|
2021-03-19 06:05:30 +01:00
|
|
|
( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
|
2021-03-04 03:48:58 +01:00
|
|
|
raise SystemExit(err)
|
2021-02-25 15:15:55 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Check for Config files in two common incorrect places
|
|
|
|
#
|
|
|
|
for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
|
2021-03-04 03:48:58 +01:00
|
|
|
for f in [ "Configuration.h", "Configuration_adv.h" ]:
|
|
|
|
if os.path.isfile(os.path.join(p, f)):
|
|
|
|
err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
|
|
|
|
raise SystemExit(err)
|
2021-04-09 03:36:48 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Check for old files indicating an entangled Marlin (mixing old and new code)
|
|
|
|
#
|
|
|
|
mixedin = []
|
|
|
|
for p in [ os.path.join(env['PROJECT_DIR'], "Marlin/src/lcd/dogm") ]:
|
|
|
|
for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]:
|
|
|
|
if os.path.isfile(os.path.join(p, f)):
|
|
|
|
mixedin += [ f ]
|
|
|
|
if mixedin:
|
|
|
|
err = "ERROR: Old files fell into your Marlin folder. Remove %s and try again" % ", ".join(mixedin)
|
|
|
|
raise SystemExit(err)
|