Browse Source

Fix preflight motherboard target check (#21372)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
ellensp 3 years ago
parent
commit
790bba1556
No account linked to committer's email address
1 changed files with 16 additions and 14 deletions
  1. 16
    14
      buildroot/share/PlatformIO/scripts/preflight-checks.py

+ 16
- 14
buildroot/share/PlatformIO/scripts/preflight-checks.py View File

@@ -5,8 +5,18 @@
5 5
 import os,re,sys
6 6
 Import("env")
7 7
 
8
-def get_envs_for_board(board, envregex):
8
+def get_envs_for_board(board):
9 9
 	with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
10
+
11
+		if sys.platform == 'win32':
12
+			envregex = r"(?:env|win):"
13
+		elif sys.platform == 'darwin':
14
+			envregex = r"(?:env|mac|uni):"
15
+		elif sys.platform == 'linux':
16
+			envregex = r"(?:env|lin|uni):"
17
+		else:
18
+			envregex = r"(?:env):"
19
+
10 20
 		r = re.compile(r"if\s+MB\((.+)\)")
11 21
 		if board.startswith("BOARD_"):
12 22
 			board = board[6:]
@@ -17,7 +27,8 @@ def get_envs_for_board(board, envregex):
17 27
 				line = file.readline()
18 28
 				found_envs = re.match(r"\s*#include .+" + envregex, line)
19 29
 				if found_envs:
20
-					return re.findall(envregex + r"(\w+)", line)
30
+					envlist = re.findall(envregex + r"(\w+)", line)
31
+					return [ "env:"+s for s in envlist ]
21 32
 	return []
22 33
 
23 34
 def check_envs(build_env, board_envs, config):
@@ -43,24 +54,15 @@ if 'MARLIN_FEATURES' not in env:
43 54
 if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
44 55
 	raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
45 56
 
46
-if sys.platform == 'win32':
47
-	osregex = r"(?:env|win):"
48
-elif sys.platform == 'darwin':
49
-	osregex = r"(?:env|mac|uni):"
50
-elif sys.platform == 'linux':
51
-	osregex = r"(?:env|lin|uni):"
52
-else:
53
-	osregex = r"(?:env):"
54
-
55 57
 build_env = env['PIOENV']
56 58
 motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
57
-board_envs = get_envs_for_board(motherboard, osregex)
59
+board_envs = get_envs_for_board(motherboard)
58 60
 config = env.GetProjectConfig()
59
-result = check_envs(build_env, board_envs, config)
61
+result = check_envs("env:"+build_env, board_envs, config)
60 62
 
61 63
 if not result:
62 64
 	err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
63
-		  (build_env, motherboard, ",".join([e[4:] for e in board_envs if re.match(r"^" + osregex, e)]))
65
+		  ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
64 66
 	raise SystemExit(err)
65 67
 
66 68
 #

Loading…
Cancel
Save