Bläddra i källkod

🎨 PIO scripts cleanup

Scott Lahteine 2 år sedan
förälder
incheckning
8ccbac5317

+ 9
- 9
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/scripts/svg2cpp.py Visa fil

112
     if s:
112
     if s:
113
       m = re.search('viewBox="([0-9-.]+) ([0-9-.]+) ([0-9-.]+) ([0-9-.]+)"', svg)
113
       m = re.search('viewBox="([0-9-.]+) ([0-9-.]+) ([0-9-.]+) ([0-9-.]+)"', svg)
114
       if m:
114
       if m:
115
-        self.x_min    = float(m.group(1))
116
-        self.y_min    = float(m.group(2))
117
-        self.x_max    = float(m.group(3))
118
-        self.y_max    = float(m.group(4))
115
+        self.x_min = float(m[1])
116
+        self.y_min = float(m[2])
117
+        self.x_max = float(m[3])
118
+        self.y_max = float(m[4])
119
         return True
119
         return True
120
     return False
120
     return False
121
 
121
 
205
         pass # Just eat the spaces
205
         pass # Just eat the spaces
206
 
206
 
207
       elif self.eat_token('([LMHVZlmhvz])'):
207
       elif self.eat_token('([LMHVZlmhvz])'):
208
-        cmd = self.m.group(1)
208
+        cmd = self.m[1]
209
         # The following commands take no arguments
209
         # The following commands take no arguments
210
         if cmd == "Z" or cmd == "z":
210
         if cmd == "Z" or cmd == "z":
211
           self.process_svg_path_data_cmd(id, cmd, 0, 0)
211
           self.process_svg_path_data_cmd(id, cmd, 0, 0)
212
 
212
 
213
       elif self.eat_token('([CScsQqTtAa])'):
213
       elif self.eat_token('([CScsQqTtAa])'):
214
-        print("Unsupported path data command:", self.m.group(1), "in path", id, "\n", file=sys.stderr)
214
+        print("Unsupported path data command:", self.m[1], "in path", id, "\n", file=sys.stderr)
215
         quit()
215
         quit()
216
 
216
 
217
       elif self.eat_token('([ ,]*[-0-9e.]+)+'):
217
       elif self.eat_token('([ ,]*[-0-9e.]+)+'):
218
         # Process list of coordinates following command
218
         # Process list of coordinates following command
219
-        coords = re.split('[ ,]+', self.m.group(0))
219
+        coords = re.split('[ ,]+', self.m[0])
220
         # The following commands take two arguments
220
         # The following commands take two arguments
221
         if cmd == "L" or cmd == "l":
221
         if cmd == "L" or cmd == "l":
222
           while coords:
222
           while coords:
245
       id = "<none>"
245
       id = "<none>"
246
       m = re.search(' id="(.*)"', path)
246
       m = re.search(' id="(.*)"', path)
247
       if m:
247
       if m:
248
-        id = m.group(1)
248
+        id = m[1]
249
 
249
 
250
       m = re.search(' transform="(.*)"', path)
250
       m = re.search(' transform="(.*)"', path)
251
       if m:
251
       if m:
254
 
254
 
255
       m = re.search(' d="(.*)"', path)
255
       m = re.search(' d="(.*)"', path)
256
       if m:
256
       if m:
257
-        self.process_svg_path_data(id, m.group(1))
257
+        self.process_svg_path_data(id, m[1])
258
         self.op.path_finished(id)
258
         self.op.path_finished(id)
259
         self.reset()
259
         self.reset()
260
 
260
 

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

56
 		# Split up passed lines on commas or newlines and iterate
56
 		# Split up passed lines on commas or newlines and iterate
57
 		# Add common options to the features config under construction
57
 		# Add common options to the features config under construction
58
 		# For lib_deps replace a previous instance of the same library
58
 		# For lib_deps replace a previous instance of the same library
59
-		atoms = re.sub(r',\\s*', '\n', flines).strip().split('\n')
59
+		atoms = re.sub(r',\s*', '\n', flines).strip().split('\n')
60
 		for line in atoms:
60
 		for line in atoms:
61
 			parts = line.split('=')
61
 			parts = line.split('=')
62
 			name = parts.pop(0)
62
 			name = parts.pop(0)
64
 				feat[name] = '='.join(parts)
64
 				feat[name] = '='.join(parts)
65
 				blab("[%s] %s=%s" % (feature, name, feat[name]), 3)
65
 				blab("[%s] %s=%s" % (feature, name, feat[name]), 3)
66
 			else:
66
 			else:
67
-				for dep in re.split(r",\s*", line):
67
+				for dep in re.split(r',\s*', line):
68
 					lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0)
68
 					lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0)
69
 					lib_re = re.compile('(?!^' + lib_name + '\\b)')
69
 					lib_re = re.compile('(?!^' + lib_name + '\\b)')
70
 					feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
70
 					feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
89
 				except:
89
 				except:
90
 					val = None
90
 					val = None
91
 				if val:
91
 				if val:
92
-					opt = mat.group(1).upper()
92
+					opt = mat[1].upper()
93
 					blab("%s.custom_marlin.%s = '%s'" % ( env['PIOENV'], opt, val ))
93
 					blab("%s.custom_marlin.%s = '%s'" % ( env['PIOENV'], opt, val ))
94
 					add_to_feat_cnf(opt, val)
94
 					add_to_feat_cnf(opt, val)
95
 
95
 

+ 29
- 24
buildroot/share/PlatformIO/scripts/signature.py Visa fil

4
 import os,subprocess,re,json,hashlib
4
 import os,subprocess,re,json,hashlib
5
 
5
 
6
 #
6
 #
7
-# The dumbest preprocessor in the world
8
-# Extract macro name from an header file and store them in an array
9
-# No processing is done here, so they are raw values here and it does not match what actually enabled
10
-# in the file (since you can have #if SOMETHING_UNDEFINED / #define BOB / #endif)
11
-# But it's useful to filter the useful macro spit out by the preprocessor from noise from the system
12
-# headers.
7
+# Return all macro names in a header as an array, so we can take
8
+# the intersection with the preprocessor output, giving a decent
9
+# reflection of all enabled options that (probably) came from the
10
+# configuration files. We end up with the actual configured state,
11
+# better than what the config files say. You can then use the
12
+# resulting config.ini to produce more exact configuration files.
13
 #
13
 #
14
 def extract_defines(filepath):
14
 def extract_defines(filepath):
15
 	f = open(filepath, encoding="utf8").read().split("\n")
15
 	f = open(filepath, encoding="utf8").read().split("\n")
16
 	a = []
16
 	a = []
17
 	for line in f:
17
 	for line in f:
18
-		sline = line.strip(" \t\n\r")
18
+		sline = line.strip()
19
 		if sline[:7] == "#define":
19
 		if sline[:7] == "#define":
20
 			# Extract the key here (we don't care about the value)
20
 			# Extract the key here (we don't care about the value)
21
-			kv = sline[8:].strip().split(' ')
21
+			kv = sline[8:].strip().split()
22
 			a.append(kv[0])
22
 			a.append(kv[0])
23
 	return a
23
 	return a
24
 
24
 
51
 	# Definitions from these files will be kept
51
 	# Definitions from these files will be kept
52
 	files_to_keep = [ 'Marlin/Configuration.h', 'Marlin/Configuration_adv.h' ]
52
 	files_to_keep = [ 'Marlin/Configuration.h', 'Marlin/Configuration_adv.h' ]
53
 
53
 
54
-	build_dir=os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV'])
54
+	build_dir = os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV'])
55
 
55
 
56
 	# Check if we can skip processing
56
 	# Check if we can skip processing
57
 	hashes = ''
57
 	hashes = ''
77
 	complete_cfg = run_preprocessor(env)
77
 	complete_cfg = run_preprocessor(env)
78
 
78
 
79
 	# Dumb #define extraction from the configuration files
79
 	# Dumb #define extraction from the configuration files
80
-	real_defines = {}
80
+	conf_defines = {}
81
 	all_defines = []
81
 	all_defines = []
82
 	for header in files_to_keep:
82
 	for header in files_to_keep:
83
 		defines = extract_defines(header)
83
 		defines = extract_defines(header)
84
 		# To filter only the define we want
84
 		# To filter only the define we want
85
-		all_defines = all_defines + defines
85
+		all_defines += defines
86
 		# To remember from which file it cames from
86
 		# To remember from which file it cames from
87
-		real_defines[header.split('/')[-1]] = defines
87
+		conf_defines[header.split('/')[-1]] = defines
88
 
88
 
89
 	r = re.compile(r"\(+(\s*-*\s*_.*)\)+")
89
 	r = re.compile(r"\(+(\s*-*\s*_.*)\)+")
90
 
90
 
116
 	resolved_defines = {}
116
 	resolved_defines = {}
117
 	for key in defines:
117
 	for key in defines:
118
 		# Remove all boards now
118
 		# Remove all boards now
119
-		if key[0:6] == "BOARD_" and key != "BOARD_INFO_NAME":
119
+		if key.startswith("BOARD_") and key != "BOARD_INFO_NAME":
120
 			continue
120
 			continue
121
 		# Remove all keys ending by "_NAME" as it does not make a difference to the configuration
121
 		# Remove all keys ending by "_NAME" as it does not make a difference to the configuration
122
-		if key[-5:] == "_NAME" and key != "CUSTOM_MACHINE_NAME":
122
+		if key.endswith("_NAME") and key != "CUSTOM_MACHINE_NAME":
123
 			continue
123
 			continue
124
-		# Remove all keys ending by "_T_DECLARED" as it's a copy of not important system stuff
125
-		if key[-11:] == "_T_DECLARED":
124
+		# Remove all keys ending by "_T_DECLARED" as it's a copy of extraneous system stuff
125
+		if key.endswith("_T_DECLARED"):
126
 			continue
126
 			continue
127
 		# Remove keys that are not in the #define list in the Configuration list
127
 		# Remove keys that are not in the #define list in the Configuration list
128
-		if not (key in all_defines) and key != "DETAILED_BUILD_VERSION" and key != "STRING_DISTRIBUTION_DATE":
128
+		if key not in all_defines + [ 'DETAILED_BUILD_VERSION', 'STRING_DISTRIBUTION_DATE' ]:
129
 			continue
129
 			continue
130
 
130
 
131
 		# Don't be that smart guy here
131
 		# Don't be that smart guy here
136
 	data = {}
136
 	data = {}
137
 	data['__INITIAL_HASH'] = hashes
137
 	data['__INITIAL_HASH'] = hashes
138
 	# First create a key for each header here
138
 	# First create a key for each header here
139
-	for header in real_defines:
139
+	for header in conf_defines:
140
 		data[header] = {}
140
 		data[header] = {}
141
 
141
 
142
 	# Then populate the object where each key is going to (that's a O(N^2) algorithm here...)
142
 	# Then populate the object where each key is going to (that's a O(N^2) algorithm here...)
143
 	for key in resolved_defines:
143
 	for key in resolved_defines:
144
-		for header in real_defines:
145
-			if key in real_defines[header]:
144
+		for header in conf_defines:
145
+			if key in conf_defines[header]:
146
 				data[header][key] = resolved_defines[key]
146
 				data[header][key] = resolved_defines[key]
147
 
147
 
148
 	# Append the source code version and date
148
 	# Append the source code version and date
155
 	except:
155
 	except:
156
 		pass
156
 		pass
157
 
157
 
158
+	#
159
+	# Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_DUMP > 0
160
+	#
158
 	with open(marlin_json, 'w') as outfile:
161
 	with open(marlin_json, 'w') as outfile:
159
 		json.dump(data, outfile, separators=(',', ':'))
162
 		json.dump(data, outfile, separators=(',', ':'))
160
 
163
 
163
 
166
 
164
 	# Generate a C source file for storing this array
167
 	# Generate a C source file for storing this array
165
 	with open('Marlin/src/mczip.h','wb') as result_file:
168
 	with open('Marlin/src/mczip.h','wb') as result_file:
166
-		result_file.write(b'#ifndef NO_CONFIGURATION_EMBEDDING_WARNING\n')
167
-		result_file.write(b'  #warning "Generated file \'mc.zip\' is embedded (Define NO_CONFIGURATION_EMBEDDING_WARNING to suppress this warning.)"\n')
168
-		result_file.write(b'#endif\n')
169
-		result_file.write(b'const unsigned char mc_zip[] PROGMEM = {\n ')
169
+		result_file.write(
170
+			  b'#ifndef NO_CONFIGURATION_EMBEDDING_WARNING\n'
171
+			+ b'  #warning "Generated file \'mc.zip\' is embedded (Define NO_CONFIGURATION_EMBEDDING_WARNING to suppress this warning.)"\n'
172
+			+ b'#endif\n'
173
+			+ b'const unsigned char mc_zip[] PROGMEM = {\n '
174
+		)
170
 		count = 0
175
 		count = 0
171
 		for b in open(os.path.join(build_dir, 'mc.zip'), 'rb').read():
176
 		for b in open(os.path.join(build_dir, 'mc.zip'), 'rb').read():
172
 			result_file.write(b' 0x%02X,' % b)
177
 			result_file.write(b' 0x%02X,' % b)

Laddar…
Avbryt
Spara