Bläddra i källkod

Add custom_verbose, custom_gcc deps flags

Scott Lahteine 3 år sedan
förälder
incheckning
28a0650cf3
1 ändrade filer med 43 tillägg och 24 borttagningar
  1. 43
    24
      buildroot/share/PlatformIO/scripts/common-dependencies.py

+ 43
- 24
buildroot/share/PlatformIO/scripts/common-dependencies.py Visa fil

@@ -18,7 +18,16 @@ except ImportError:
18 18
 
19 19
 Import("env")
20 20
 
21
-FEATURE_CONFIG = {}
21
+#print(env.Dump())
22
+
23
+try:
24
+	verbose = int(env.GetProjectOption('custom_verbose'))
25
+except:
26
+	verbose = 0
27
+
28
+def blab(str):
29
+	if verbose:
30
+		print(str)
22 31
 
23 32
 def parse_pkg_uri(spec):
24 33
 	if PackageManager.__name__ == 'PackageSpec':
@@ -27,6 +36,8 @@ def parse_pkg_uri(spec):
27 36
 		name, _, _ = PackageManager.parse_pkg_uri(spec)
28 37
 		return name
29 38
 
39
+FEATURE_CONFIG = {}
40
+
30 41
 def add_to_feat_cnf(feature, flines):
31 42
 	feat = FEATURE_CONFIG[feature]
32 43
 	atoms = re.sub(',\\s*', '\n', flines).strip().split('\n')
@@ -91,7 +102,8 @@ def force_ignore_unused_libs():
91 102
 	known_libs = get_all_known_libs()
92 103
 	diff = (list(set(known_libs) - set(env_libs)))
93 104
 	lib_ignore = env.GetProjectOption('lib_ignore') + diff
94
-	print("Ignore libraries:", lib_ignore)
105
+	if verbose:
106
+		print("Ignore libraries:", lib_ignore)
95 107
 	set_env_field('lib_ignore', lib_ignore)
96 108
 
97 109
 def apply_features_config():
@@ -103,7 +115,7 @@ def apply_features_config():
103 115
 		feat = FEATURE_CONFIG[feature]
104 116
 
105 117
 		if 'lib_deps' in feat and len(feat['lib_deps']):
106
-			print("Adding lib_deps for %s... " % feature)
118
+			blab("Adding lib_deps for %s... " % feature)
107 119
 
108 120
 			# feat to add
109 121
 			deps_to_add = {}
@@ -131,11 +143,11 @@ def apply_features_config():
131 143
 				set_env_field('lib_deps', deps + list(deps_to_add.values()))
132 144
 
133 145
 		if 'extra_scripts' in feat:
134
-			print("Running extra_scripts for %s... " % feature)
146
+			blab("Running extra_scripts for %s... " % feature)
135 147
 			env.SConscript(feat['extra_scripts'], exports="env")
136 148
 
137 149
 		if 'src_filter' in feat:
138
-			print("Adding src_filter for %s... " % feature)
150
+			blab("Adding src_filter for %s... " % feature)
139 151
 			src_filter = ' '.join(env.GetProjectOption('src_filter'))
140 152
 			# first we need to remove the references to the same folder
141 153
 			my_srcs = re.findall( r'[+-](<.*?>)', feat['src_filter'])
@@ -149,7 +161,7 @@ def apply_features_config():
149 161
 			env.Replace(SRC_FILTER=src_filter)
150 162
 
151 163
 		if 'lib_ignore' in feat:
152
-			print("Adding lib_ignore for %s... " % feature)
164
+			blab("Adding lib_ignore for %s... " % feature)
153 165
 			lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']]
154 166
 			set_env_field('lib_ignore', lib_ignore)
155 167
 
@@ -159,41 +171,49 @@ def apply_features_config():
159 171
 ENV_BUILD_PATH = os.path.join(env.Dictionary('PROJECT_BUILD_DIR'), env['PIOENV'])
160 172
 GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
161 173
 def search_compiler():
174
+	try:
175
+		filepath = env.GetProjectOption('custom_gcc')
176
+		blab('Getting compiler from env')
177
+		return filepath
178
+	except:
179
+		pass
180
+
162 181
 	if os.path.exists(GCC_PATH_CACHE):
163
-		print('Getting g++ path from cache')
182
+		blab('Getting g++ path from cache')
164 183
 		with open(GCC_PATH_CACHE, 'r') as f:
165 184
 			return f.read()
166 185
 
167
-	# PlatformIO inserts the toolchain bin folder on the front of the $PATH
168 186
 	# Find the current platform compiler by searching the $PATH
187
+	# which will be in a platformio toolchain bin folder
188
+	path_regex = re.escape(env['PROJECT_PACKAGES_DIR'])
189
+	gcc = "g++"
169 190
 	if env['PLATFORM'] == 'win32':
170 191
 		path_separator = ';'
171
-		path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*\\bin'
172
-		gcc = "g++.exe"
192
+		path_regex += r'.*\\bin'
193
+		gcc += ".exe"
173 194
 	else:
174 195
 		path_separator = ':'
175
-		path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*/bin'
176
-		gcc = "g++"
196
+		path_regex += r'/.+/bin'
177 197
 
178 198
 	# Search for the compiler
179
-	for path in env['ENV']['PATH'].split(path_separator):
180
-		if not re.search(path_regex, path, re.IGNORECASE):
199
+	for pathdir in env['ENV']['PATH'].split(path_separator):
200
+		if not re.search(path_regex, pathdir, re.IGNORECASE):
181 201
 			continue
182
-		for file in os.listdir(path):
183
-			if not file.endswith(gcc):
202
+		for filepath in os.listdir(pathdir):
203
+			if not filepath.endswith(gcc):
184 204
 				continue
185 205
 
186 206
 			# Cache the g++ path to no search always
187 207
 			if os.path.exists(ENV_BUILD_PATH):
188
-				print('Caching g++ for current env')
208
+				blab('Caching g++ for current env')
189 209
 				with open(GCC_PATH_CACHE, 'w+') as f:
190
-					f.write(file)
210
+					f.write(filepath)
191 211
 
192
-			return file
212
+			return filepath
193 213
 
194
-	file = env.get('CXX')
195
-	print("Couldn't find a compiler! Fallback to", file)
196
-	return file
214
+	filepath = env.get('CXX')
215
+	blab("Couldn't find a compiler! Fallback to %s" % filepath)
216
+	return filepath
197 217
 
198 218
 #
199 219
 # Use the compiler to get a list of all enabled features
@@ -203,7 +223,6 @@ def load_marlin_features():
203 223
 		return
204 224
 
205 225
 	# Process defines
206
-	#print(env.Dump())
207 226
 	build_flags = env.get('BUILD_FLAGS')
208 227
 	build_flags = env.ParseFlagsExtended(build_flags)
209 228
 
@@ -221,7 +240,7 @@ def load_marlin_features():
221 240
 
222 241
 	cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h']
223 242
 	cmd = ' '.join(cmd)
224
-	print(cmd)
243
+	blab(cmd)
225 244
 	define_list = subprocess.check_output(cmd, shell=True).splitlines()
226 245
 	marlin_features = {}
227 246
 	for define in define_list:

Laddar…
Avbryt
Spara