Fix preflight motherboard target check (#21372)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
parent
ac4f3c0c7e
commit
c4d757c6f7
@ -5,8 +5,18 @@
|
||||
import os,re,sys
|
||||
Import("env")
|
||||
|
||||
def get_envs_for_board(board, envregex):
|
||||
def get_envs_for_board(board):
|
||||
with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
|
||||
|
||||
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):"
|
||||
|
||||
r = re.compile(r"if\s+MB\((.+)\)")
|
||||
if board.startswith("BOARD_"):
|
||||
board = board[6:]
|
||||
@ -17,7 +27,8 @@ def get_envs_for_board(board, envregex):
|
||||
line = file.readline()
|
||||
found_envs = re.match(r"\s*#include .+" + envregex, line)
|
||||
if found_envs:
|
||||
return re.findall(envregex + r"(\w+)", line)
|
||||
envlist = re.findall(envregex + r"(\w+)", line)
|
||||
return [ "env:"+s for s in envlist ]
|
||||
return []
|
||||
|
||||
def check_envs(build_env, board_envs, config):
|
||||
@ -43,24 +54,15 @@ if 'MARLIN_FEATURES' not in env:
|
||||
if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
|
||||
raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
|
||||
|
||||
if sys.platform == 'win32':
|
||||
osregex = r"(?:env|win):"
|
||||
elif sys.platform == 'darwin':
|
||||
osregex = r"(?:env|mac|uni):"
|
||||
elif sys.platform == 'linux':
|
||||
osregex = r"(?:env|lin|uni):"
|
||||
else:
|
||||
osregex = r"(?:env):"
|
||||
|
||||
build_env = env['PIOENV']
|
||||
motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
|
||||
board_envs = get_envs_for_board(motherboard, osregex)
|
||||
board_envs = get_envs_for_board(motherboard)
|
||||
config = env.GetProjectConfig()
|
||||
result = check_envs(build_env, board_envs, config)
|
||||
result = check_envs("env:"+build_env, board_envs, config)
|
||||
|
||||
if not result:
|
||||
err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
|
||||
(build_env, motherboard, ",".join([e[4:] for e in board_envs if re.match(r"^" + osregex, e)]))
|
||||
( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
|
||||
raise SystemExit(err)
|
||||
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user