Detect extra ENVS in preflight checks (#21361)
This commit is contained in:
parent
5ffa6f3331
commit
dc78e0a250
@ -2,33 +2,34 @@
|
|||||||
# preflight-checks.py
|
# preflight-checks.py
|
||||||
# Check for common issues prior to compiling
|
# Check for common issues prior to compiling
|
||||||
#
|
#
|
||||||
import os,re
|
import os,re,sys
|
||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
def get_envs_for_board(board):
|
def get_envs_for_board(board, envregex):
|
||||||
|
with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
|
||||||
|
r = re.compile(r"if\s+MB\((.+)\)")
|
||||||
if board.startswith("BOARD_"):
|
if board.startswith("BOARD_"):
|
||||||
board = board[6:]
|
board = board[6:]
|
||||||
with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f:
|
|
||||||
board_found = ""
|
for line in file:
|
||||||
r=re.compile(r"if\s+MB\((.+)\)")
|
|
||||||
for line in f.readlines():
|
|
||||||
mbs = r.findall(line)
|
mbs = r.findall(line)
|
||||||
if mbs:
|
if mbs and board in re.split(r",\s*", mbs[0]):
|
||||||
board_found = board if board in re.split(r",\s*", mbs[0]) else ""
|
line = file.readline()
|
||||||
if board_found and "#include " in line and "env:" in line:
|
found_envs = re.match(r"\s*#include .+" + envregex, line)
|
||||||
return re.findall(r"env:\w+", line)
|
if found_envs:
|
||||||
|
return re.findall(envregex + r"(\w+)", line)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def check_envs(build_env, base_envs, config):
|
def check_envs(build_env, board_envs, config):
|
||||||
if build_env in base_envs:
|
if build_env in board_envs:
|
||||||
return True
|
return True
|
||||||
ext = config.get(build_env, 'extends', default=None)
|
ext = config.get(build_env, 'extends', default=None)
|
||||||
if ext:
|
if ext:
|
||||||
if isinstance(ext, str):
|
if isinstance(ext, str):
|
||||||
return check_envs(ext, base_envs, config)
|
return check_envs(ext, board_envs, config)
|
||||||
elif isinstance(ext, list):
|
elif isinstance(ext, list):
|
||||||
for ext_env in ext:
|
for ext_env in ext:
|
||||||
if check_envs(ext_env, base_envs, config):
|
if check_envs(ext_env, board_envs, config):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -42,15 +43,24 @@ 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']
|
||||||
base_envs = get_envs_for_board(motherboard)
|
board_envs = get_envs_for_board(motherboard, osregex)
|
||||||
config = env.GetProjectConfig()
|
config = env.GetProjectConfig()
|
||||||
result = check_envs("env:"+build_env, base_envs, config)
|
result = check_envs(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 base_envs if e.startswith("env:")]))
|
(build_env, motherboard, ",".join([e[4:] for e in board_envs if re.match(r"^" + osregex, e)]))
|
||||||
raise SystemExit(err)
|
raise SystemExit(err)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user