Skip to content

Commit

Permalink
Fix preflight motherboard target check (MarlinFirmware#21372)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
  • Loading branch information
ellensp and thinkyhead committed Mar 19, 2021
1 parent b51aed8 commit 790bba1
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions buildroot/share/PlatformIO/scripts/preflight-checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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):
Expand All @@ -43,24 +54,15 @@ def check_envs(build_env, board_envs, config):
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)

#
Expand Down

0 comments on commit 790bba1

Please sign in to comment.