Fix preflight motherboard target check (#21372)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
parent
b51aed8aa5
commit
790bba1556
|
@ -5,8 +5,18 @@
|
||||||
import os,re,sys
|
import os,re,sys
|
||||||
Import("env")
|
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:
|
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\((.+)\)")
|
r = re.compile(r"if\s+MB\((.+)\)")
|
||||||
if board.startswith("BOARD_"):
|
if board.startswith("BOARD_"):
|
||||||
board = board[6:]
|
board = board[6:]
|
||||||
|
@ -17,7 +27,8 @@ def get_envs_for_board(board, envregex):
|
||||||
line = file.readline()
|
line = file.readline()
|
||||||
found_envs = re.match(r"\s*#include .+" + envregex, line)
|
found_envs = re.match(r"\s*#include .+" + envregex, line)
|
||||||
if found_envs:
|
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 []
|
return []
|
||||||
|
|
||||||
def check_envs(build_env, board_envs, config):
|
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']:
|
if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
|
||||||
raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
|
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']
|
build_env = env['PIOENV']
|
||||||
motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
|
motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
|
||||||
board_envs = get_envs_for_board(motherboard, osregex)
|
board_envs = get_envs_for_board(motherboard)
|
||||||
config = env.GetProjectConfig()
|
config = env.GetProjectConfig()
|
||||||
result = check_envs(build_env, board_envs, config)
|
result = check_envs("env:"+build_env, board_envs, config)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
|
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)
|
raise SystemExit(err)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue