Browse Source

Fix search for best compiler (#18779)

Victor Oliveira 5 years ago
parent
commit
89722d2196
No account linked to committer's email address

+ 24
- 7
buildroot/share/PlatformIO/scripts/common-features-dependencies.h View File

27
  * Used by common-features-dependencies.py
27
  * Used by common-features-dependencies.py
28
  */
28
  */
29
 
29
 
30
-#ifndef __MARLIN_FIRMWARE__
31
-#define __MARLIN_FIRMWARE__
32
-#endif
33
-
34
-//
35
-// Prefix header to acquire configurations
36
-//
37
 #include <stdint.h>
30
 #include <stdint.h>
38
 
31
 
32
+// Include platform headers
33
+//#include "../../../../Marlin/src/HAL/platforms.h"
34
+
39
 #include "../../../../Marlin/src/core/boards.h"
35
 #include "../../../../Marlin/src/core/boards.h"
40
 #include "../../../../Marlin/src/core/macros.h"
36
 #include "../../../../Marlin/src/core/macros.h"
41
 #include "../../../../Marlin/Configuration.h"
37
 #include "../../../../Marlin/Configuration.h"
44
 
40
 
45
 #include "../../../../Marlin/src/inc/Conditionals_LCD.h"
41
 #include "../../../../Marlin/src/inc/Conditionals_LCD.h"
46
 
42
 
43
+#ifdef HAL_PATH
44
+  #include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_LCD.h)
45
+#endif
46
+
47
 #include "../../../../Marlin/src/core/drivers.h"
47
 #include "../../../../Marlin/src/core/drivers.h"
48
 #include "../../../../Marlin/Configuration_adv.h"
48
 #include "../../../../Marlin/Configuration_adv.h"
49
 
49
 
50
 #include "../../../../Marlin/src/inc/Conditionals_adv.h"
50
 #include "../../../../Marlin/src/inc/Conditionals_adv.h"
51
+
52
+#ifdef HAL_PATH
53
+  #include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_adv.h)
54
+#endif
55
+
56
+//#include "../../../../Marlin/src/pins/pins.h"
57
+
58
+#ifdef HAL_PATH
59
+  #include HAL_PATH(../../../../Marlin/src/HAL, timers.h)
60
+  #include HAL_PATH(../../../../Marlin/src/HAL, spi_pins.h)
61
+#endif
62
+
63
+#include "../../../../Marlin/src/inc/Conditionals_post.h"
64
+
65
+#ifdef HAL_PATH
66
+  #include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_post.h)
67
+#endif

+ 64
- 35
buildroot/share/PlatformIO/scripts/common-features-dependencies.py View File

30
 			parts = dep.split('=')
30
 			parts = dep.split('=')
31
 			name = parts.pop(0)
31
 			name = parts.pop(0)
32
 			rest = '='.join(parts)
32
 			rest = '='.join(parts)
33
-			if name == 'extra_scripts':
34
-				FEATURE_DEPENDENCIES[ukey]['extra_scripts'] = rest
35
-			elif name == 'src_filter':
36
-				FEATURE_DEPENDENCIES[ukey]['src_filter'] = rest
37
-			elif name == 'lib_ignore':
38
-				FEATURE_DEPENDENCIES[ukey]['lib_ignore'] = rest
33
+			if name in ['extra_scripts', 'src_filter', 'lib_ignore']:
34
+				FEATURE_DEPENDENCIES[ukey][name] = rest
39
 			else:
35
 			else:
40
 				FEATURE_DEPENDENCIES[ukey]['lib_deps'] += [dep]
36
 				FEATURE_DEPENDENCIES[ukey]['lib_deps'] += [dep]
41
 
37
 
57
 		env_libs.append(name)
53
 		env_libs.append(name)
58
 	return env_libs
54
 	return env_libs
59
 
55
 
60
-# We need to ignore all non-used libs,
61
-# so if a lib folder lay forgotten in .pio/lib_deps, it
62
-# will not break compiling
56
+# All unused libs should be ignored so that if a library
57
+# exists in .pio/lib_deps it will not break compilation.
63
 def force_ignore_unused_libs():
58
 def force_ignore_unused_libs():
64
 	env_libs = get_all_env_libs()
59
 	env_libs = get_all_env_libs()
65
 	known_libs = get_all_known_libs()
60
 	known_libs = get_all_known_libs()
66
 	diff = (list(set(known_libs) - set(env_libs)))
61
 	diff = (list(set(known_libs) - set(env_libs)))
67
 	lib_ignore = env.GetProjectOption("lib_ignore") + diff
62
 	lib_ignore = env.GetProjectOption("lib_ignore") + diff
68
-	print("Ignoring libs: ", lib_ignore)
63
+	print("Ignoring libs:", lib_ignore)
69
 	proj = env.GetProjectConfig()
64
 	proj = env.GetProjectConfig()
70
 	proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
65
 	proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
71
 
66
 
84
 				name, _, _ = PackageManager.parse_pkg_uri(dep)
79
 				name, _, _ = PackageManager.parse_pkg_uri(dep)
85
 				deps_to_add[name] = dep
80
 				deps_to_add[name] = dep
86
 
81
 
87
-			# first check if the env already have the dep
82
+			# Does the env already have the dependency?
88
 			deps = env.GetProjectOption("lib_deps")
83
 			deps = env.GetProjectOption("lib_deps")
89
 			for dep in deps:
84
 			for dep in deps:
90
 				name, _, _ = PackageManager.parse_pkg_uri(dep)
85
 				name, _, _ = PackageManager.parse_pkg_uri(dep)
91
 				if name in deps_to_add:
86
 				if name in deps_to_add:
92
 					del deps_to_add[name]
87
 					del deps_to_add[name]
93
 
88
 
94
-			# check if we need ignore any lib
89
+			# Are there any libraries that should be ignored?
95
 			lib_ignore = env.GetProjectOption("lib_ignore")
90
 			lib_ignore = env.GetProjectOption("lib_ignore")
96
 			for dep in deps:
91
 			for dep in deps:
97
 				name, _, _ = PackageManager.parse_pkg_uri(dep)
92
 				name, _, _ = PackageManager.parse_pkg_uri(dep)
98
 				if name in deps_to_add:
93
 				if name in deps_to_add:
99
 					del deps_to_add[name]
94
 					del deps_to_add[name]
100
 
95
 
101
-			# any left?
96
+			# Is there anything left?
102
 			if len(deps_to_add) > 0:
97
 			if len(deps_to_add) > 0:
103
-				# add only the missing deps
98
+				# Only add the missing dependencies
104
 				proj = env.GetProjectConfig()
99
 				proj = env.GetProjectConfig()
105
 				proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values()))
100
 				proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values()))
106
 
101
 
129
 			proj = env.GetProjectConfig()
124
 			proj = env.GetProjectConfig()
130
 			proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
125
 			proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
131
 
126
 
132
-# search the current compiler, considering the OS
127
+#
128
+# Find a compiler, considering the OS
129
+#
130
+ENV_BUILD_PATH = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env["PIOENV"])
131
+GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
133
 def search_compiler():
132
 def search_compiler():
133
+	if os.path.exists(GCC_PATH_CACHE):
134
+		print('Getting g++ path from cache')
135
+		with open(GCC_PATH_CACHE, 'r') as f:
136
+			return f.read()
137
+
138
+	# PlatformIO inserts the toolchain bin folder on the front of the $PATH
139
+	# Find the current platform compiler by searching the $PATH
134
 	if env['PLATFORM'] == 'win32':
140
 	if env['PLATFORM'] == 'win32':
135
-		# the first path have the compiler
136
-		for path in env['ENV']['PATH'].split(';'):
137
-			if not re.search(r'platformio\\packages.*\\bin', path):
138
-				continue
139
-			#print(path)
140
-			for file in os.listdir(path):
141
-				if file.endswith("g++.exe"):
142
-					return file
143
-		print("Could not find the g++")
144
-		return None
141
+		path_separator = ';'
142
+		path_regex = r'platformio\\packages.*\\bin'
143
+		gcc = "g++.exe"
145
 	else:
144
 	else:
146
-		return env.get('CXX')
145
+		path_separator = ':'
146
+		path_regex = r'platformio/packages.*/bin'
147
+		gcc = "g++"
148
+
149
+	# Search for the compiler
150
+	for path in env['ENV']['PATH'].split(path_separator):
151
+		if not re.search(path_regex, path):
152
+			continue
153
+		for file in os.listdir(path):
154
+			if not file.endswith(gcc):
155
+				continue
156
+
157
+			# Cache the g++ path to no search always
158
+			if os.path.exists(ENV_BUILD_PATH):
159
+				print('Caching g++ for current env')
160
+				with open(GCC_PATH_CACHE, 'w+') as f:
161
+					f.write(file)
162
+
163
+			return file
147
 
164
 
165
+	file = env.get('CXX')
166
+	print("Couldn't find a compiler! Fallback to", file)
167
+	return file
148
 
168
 
149
-# load marlin features
169
+#
170
+# Use the compiler to get a list of all enabled features
171
+#
150
 def load_marlin_features():
172
 def load_marlin_features():
151
 	if "MARLIN_FEATURES" in env:
173
 	if "MARLIN_FEATURES" in env:
152
 		return
174
 		return
153
 
175
 
154
-	# procces defines
155
-	# print(env.Dump())
176
+	# Process defines
177
+	#print(env.Dump())
156
 	build_flags = env.get('BUILD_FLAGS')
178
 	build_flags = env.get('BUILD_FLAGS')
157
 	build_flags = env.ParseFlagsExtended(build_flags)
179
 	build_flags = env.ParseFlagsExtended(build_flags)
158
 
180
 
159
 	cxx = search_compiler()
181
 	cxx = search_compiler()
160
 	cmd = [cxx]
182
 	cmd = [cxx]
161
 
183
 
162
-	# build flags from board.json
163
-	# if 'BOARD' in env:
164
-	# 	cmd += [env.BoardConfig().get("build.extra_flags")]
184
+	# Build flags from board.json
185
+	#if 'BOARD' in env:
186
+	#	cmd += [env.BoardConfig().get("build.extra_flags")]
165
 	for s in build_flags['CPPDEFINES']:
187
 	for s in build_flags['CPPDEFINES']:
166
 		if isinstance(s, tuple):
188
 		if isinstance(s, tuple):
167
 			cmd += ['-D' + s[0] + '=' + str(s[1])]
189
 			cmd += ['-D' + s[0] + '=' + str(s[1])]
168
 		else:
190
 		else:
169
 			cmd += ['-D' + s]
191
 			cmd += ['-D' + s]
170
-	# cmd += ['-w -dM -E -x c++ Marlin/src/inc/MarlinConfigPre.h']
192
+
171
 	cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-features-dependencies.h']
193
 	cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-features-dependencies.h']
172
 	cmd = ' '.join(cmd)
194
 	cmd = ' '.join(cmd)
173
 	print(cmd)
195
 	print(cmd)
179
 		marlin_features[feature] = definition
201
 		marlin_features[feature] = definition
180
 	env["MARLIN_FEATURES"] = marlin_features
202
 	env["MARLIN_FEATURES"] = marlin_features
181
 
203
 
204
+#
205
+# Return True if a matching feature is enabled
206
+#
182
 def MarlinFeatureIsEnabled(env, feature):
207
 def MarlinFeatureIsEnabled(env, feature):
183
 	load_marlin_features()
208
 	load_marlin_features()
184
 	r = re.compile(feature)
209
 	r = re.compile(feature)
185
 	matches = list(filter(r.match, env["MARLIN_FEATURES"]))
210
 	matches = list(filter(r.match, env["MARLIN_FEATURES"]))
186
 	return len(matches) > 0
211
 	return len(matches) > 0
187
 
212
 
188
-# add a method for others scripts to check if a feature is enabled
213
+#
214
+# Add a method for other PIO scripts to query enabled features
215
+#
189
 env.AddMethod(MarlinFeatureIsEnabled)
216
 env.AddMethod(MarlinFeatureIsEnabled)
190
 
217
 
191
-# install all dependencies for features enabled in Configuration.h
218
+#
219
+# Add dependencies for enabled Marlin features
220
+#
192
 install_features_dependencies()
221
 install_features_dependencies()
193
 force_ignore_unused_libs()
222
 force_ignore_unused_libs()

Loading…
Cancel
Save