|
@@ -0,0 +1,62 @@
|
|
1
|
+#
|
|
2
|
+# preflight-checks.py
|
|
3
|
+# Script to check for common issues prior to compiling
|
|
4
|
+#
|
|
5
|
+import os
|
|
6
|
+import re
|
|
7
|
+Import("env")
|
|
8
|
+
|
|
9
|
+def get_envs_for_board(board):
|
|
10
|
+ if board.startswith("BOARD_"):
|
|
11
|
+ board = board[6:]
|
|
12
|
+ with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f:
|
|
13
|
+ board_found = ""
|
|
14
|
+ r=re.compile(r"if\s+MB\((.+)\)")
|
|
15
|
+ for line in f.readlines():
|
|
16
|
+ mbs = r.findall(line)
|
|
17
|
+ if mbs:
|
|
18
|
+ board_found = board if board in re.split(r",\s*", mbs[0]) else ""
|
|
19
|
+ if board_found and "#include " in line and "env:" in line:
|
|
20
|
+ return re.findall(r"env:\w+", line)
|
|
21
|
+ return []
|
|
22
|
+
|
|
23
|
+def check_envs(build_env, base_envs, config):
|
|
24
|
+ if build_env in base_envs:
|
|
25
|
+ return True
|
|
26
|
+ ext = config.get(build_env, 'extends', default=None)
|
|
27
|
+ if ext:
|
|
28
|
+ for ext_env in ext:
|
|
29
|
+ if check_envs(ext_env, base_envs, config):
|
|
30
|
+ return True
|
|
31
|
+ return False
|
|
32
|
+
|
|
33
|
+# Sanity checks:
|
|
34
|
+if 'PIOENV' not in env:
|
|
35
|
+ raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO")
|
|
36
|
+
|
|
37
|
+if 'MARLIN_FEATURES' not in env:
|
|
38
|
+ raise SystemExit("Error: this script should be used after common Marlin scripts")
|
|
39
|
+
|
|
40
|
+if 'MOTHERBOARD' not in env['MARLIN_FEATURES']:
|
|
41
|
+ raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h")
|
|
42
|
+
|
|
43
|
+build_env = env['PIOENV']
|
|
44
|
+motherboard = env['MARLIN_FEATURES']['MOTHERBOARD']
|
|
45
|
+base_envs = get_envs_for_board(motherboard)
|
|
46
|
+config = env.GetProjectConfig()
|
|
47
|
+result = check_envs("env:"+build_env, base_envs, config)
|
|
48
|
+
|
|
49
|
+if not result:
|
|
50
|
+ err = "Error: your selected build environment '%s' is not compatible with MOTHERBOARD=%s in Configuration.h. " \
|
|
51
|
+ "Please use one of compatible build environments for this board: %s" % \
|
|
52
|
+ (build_env, motherboard, ",".join([e[4:] for e in base_envs if e.startswith("env:")]))
|
|
53
|
+ raise SystemExit(err)
|
|
54
|
+
|
|
55
|
+#
|
|
56
|
+# Check for Config files in two common incorrect places
|
|
57
|
+#
|
|
58
|
+for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]:
|
|
59
|
+ for f in [ "Configuration.h", "Configuration_adv.h" ]:
|
|
60
|
+ if os.path.isfile(os.path.join(p, f)):
|
|
61
|
+ err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
|
|
62
|
+ raise SystemExit(err)
|