Update some py scripts

2.0.x
Scott Lahteine 4 years ago committed by Scott Lahteine
parent ee74cee5d4
commit c8b73b00be

@ -1,3 +1,7 @@
#
# STM32F401VE_STEVAL.py
# Customizations for env:STM32F401VE_STEVAL
#
import os import os
Import("env") Import("env")

@ -6,41 +6,41 @@ import os,re
Import("env") Import("env")
def get_envs_for_board(board): def get_envs_for_board(board):
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: with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f:
board_found = "" board_found = ""
r=re.compile(r"if\s+MB\((.+)\)") r=re.compile(r"if\s+MB\((.+)\)")
for line in f.readlines(): for line in f.readlines():
mbs = r.findall(line) mbs = r.findall(line)
if mbs: if mbs:
board_found = board if board in re.split(r",\s*", mbs[0]) else "" board_found = board if board in re.split(r",\s*", mbs[0]) else ""
if board_found and "#include " in line and "env:" in line: if board_found and "#include " in line and "env:" in line:
return re.findall(r"env:\w+", line) return re.findall(r"env:\w+", line)
return [] return []
def check_envs(build_env, base_envs, config): def check_envs(build_env, base_envs, config):
if build_env in base_envs: if build_env in base_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, base_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, base_envs, config):
return True return True
return False return False
# Sanity checks: # Sanity checks:
if 'PIOENV' not in env: if 'PIOENV' not in env:
raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO") raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
if 'MARLIN_FEATURES' not in env: if 'MARLIN_FEATURES' not in env:
raise SystemExit("Error: this script should be used after common Marlin scripts") raise SystemExit("Error: this script should be used after common Marlin scripts")
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")
build_env = env['PIOENV'] build_env = env['PIOENV']
motherboard = env['MARLIN_FEATURES']['MOTHERBOARD'] motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
@ -49,16 +49,16 @@ config = env.GetProjectConfig()
result = check_envs("env:"+build_env, base_envs, config) result = check_envs("env:"+build_env, base_envs, config)
if not result: if not result:
err = "Error: your selected build environment '%s' is not compatible with MOTHERBOARD=%s in Configuration.h. " \ err = "Error: your selected build environment '%s' is not compatible with MOTHERBOARD=%s in Configuration.h. " \
"Please use one of compatible build environments for this board: %s" % \ "Please use one of compatible build environments for this board: %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 base_envs if e.startswith("env:")]))
raise SystemExit(err) raise SystemExit(err)
# #
# Check for Config files in two common incorrect places # Check for Config files in two common incorrect places
# #
for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
for f in [ "Configuration.h", "Configuration_adv.h" ]: for f in [ "Configuration.h", "Configuration_adv.h" ]:
if os.path.isfile(os.path.join(p, f)): 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 err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
raise SystemExit(err) raise SystemExit(err)

Loading…
Cancel
Save