Browse Source

Detect extra ENVS in preflight checks (#21361)

Scott Lahteine 3 years ago
parent
commit
dc78e0a250
No account linked to committer's email address
1 changed files with 29 additions and 19 deletions
  1. 29
    19
      buildroot/share/PlatformIO/scripts/preflight-checks.py

+ 29
- 19
buildroot/share/PlatformIO/scripts/preflight-checks.py View File

@@ -2,33 +2,34 @@
2 2
 # preflight-checks.py
3 3
 # Check for common issues prior to compiling
4 4
 #
5
-import os,re
5
+import os,re,sys
6 6
 Import("env")
7 7
 
8
-def get_envs_for_board(board):
9
-	if board.startswith("BOARD_"):
10
-		board = board[6:]
11
-	with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f:
12
-		board_found = ""
13
-		r=re.compile(r"if\s+MB\((.+)\)")
14
-		for line in f.readlines():
8
+def get_envs_for_board(board, envregex):
9
+	with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file:
10
+		r = re.compile(r"if\s+MB\((.+)\)")
11
+		if board.startswith("BOARD_"):
12
+			board = board[6:]
13
+
14
+		for line in file:
15 15
 			mbs = r.findall(line)
16
-			if mbs:
17
-				board_found = board if board in re.split(r",\s*", mbs[0]) else ""
18
-			if board_found and "#include " in line and "env:" in line:
19
-				return re.findall(r"env:\w+", line)
16
+			if mbs and board in re.split(r",\s*", mbs[0]):
17
+				line = file.readline()
18
+				found_envs = re.match(r"\s*#include .+" + envregex, line)
19
+				if found_envs:
20
+					return re.findall(envregex + r"(\w+)", line)
20 21
 	return []
21 22
 
22
-def check_envs(build_env, base_envs, config):
23
-	if build_env in base_envs:
23
+def check_envs(build_env, board_envs, config):
24
+	if build_env in board_envs:
24 25
 		return True
25 26
 	ext = config.get(build_env, 'extends', default=None)
26 27
 	if ext:
27 28
 		if isinstance(ext, str):
28
-			return check_envs(ext, base_envs, config)
29
+			return check_envs(ext, board_envs, config)
29 30
 		elif isinstance(ext, list):
30 31
 			for ext_env in ext:
31
-				if check_envs(ext_env, base_envs, config):
32
+				if check_envs(ext_env, board_envs, config):
32 33
 					return True
33 34
 	return False
34 35
 
@@ -42,15 +43,24 @@ if 'MARLIN_FEATURES' not in env:
42 43
 if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
43 44
 	raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
44 45
 
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
+
45 55
 build_env = env['PIOENV']
46 56
 motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
47
-base_envs = get_envs_for_board(motherboard)
57
+board_envs = get_envs_for_board(motherboard, osregex)
48 58
 config = env.GetProjectConfig()
49
-result = check_envs("env:"+build_env, base_envs, config)
59
+result = check_envs(build_env, board_envs, config)
50 60
 
51 61
 if not result:
52 62
 	err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \
53
-		  (build_env, motherboard, ",".join([e[4:] for e in base_envs if e.startswith("env:")]))
63
+		  (build_env, motherboard, ",".join([e[4:] for e in board_envs if re.match(r"^" + osregex, e)]))
54 64
 	raise SystemExit(err)
55 65
 
56 66
 #

Loading…
Cancel
Save