diff options
Diffstat (limited to 'recipes-bsp/u-boot/u-boot-qoriq/0001-buildman-Convert-to-Python-3.patch')
-rw-r--r-- | recipes-bsp/u-boot/u-boot-qoriq/0001-buildman-Convert-to-Python-3.patch | 928 |
1 files changed, 928 insertions, 0 deletions
diff --git a/recipes-bsp/u-boot/u-boot-qoriq/0001-buildman-Convert-to-Python-3.patch b/recipes-bsp/u-boot/u-boot-qoriq/0001-buildman-Convert-to-Python-3.patch new file mode 100644 index 00000000..5d7ec42f --- /dev/null +++ b/recipes-bsp/u-boot/u-boot-qoriq/0001-buildman-Convert-to-Python-3.patch | |||
@@ -0,0 +1,928 @@ | |||
1 | From c05aa0364280803d8274e260a739553d588ea052 Mon Sep 17 00:00:00 2001 | ||
2 | From: Simon Glass <sjg@chromium.org> | ||
3 | Date: Thu, 31 Oct 2019 07:42:53 -0600 | ||
4 | Subject: [PATCH] buildman: Convert to Python 3 | ||
5 | |||
6 | Convert buildman to Python 3 and make it use that, to meet the 2020 | ||
7 | deadline. | ||
8 | |||
9 | Upstream-Status: Backport | ||
10 | |||
11 | Signed-off-by: Simon Glass <sjg@chromium.org> | ||
12 | --- | ||
13 | tools/buildman/board.py | 9 +-- | ||
14 | tools/buildman/bsettings.py | 20 +++---- | ||
15 | tools/buildman/builder.py | 47 ++++++++-------- | ||
16 | tools/buildman/builderthread.py | 24 ++++---- | ||
17 | tools/buildman/buildman.py | 10 ++-- | ||
18 | tools/buildman/control.py | 44 +++++++-------- | ||
19 | tools/buildman/func_test.py | 16 +++--- | ||
20 | tools/buildman/test.py | 22 ++++---- | ||
21 | tools/buildman/toolchain.py | 99 +++++++++++++++++---------------- | ||
22 | 9 files changed, 146 insertions(+), 145 deletions(-) | ||
23 | |||
24 | diff --git a/tools/buildman/board.py b/tools/buildman/board.py | ||
25 | index 2a1d021574..447aaabea8 100644 | ||
26 | --- a/tools/buildman/board.py | ||
27 | +++ b/tools/buildman/board.py | ||
28 | @@ -1,6 +1,7 @@ | ||
29 | # SPDX-License-Identifier: GPL-2.0+ | ||
30 | # Copyright (c) 2012 The Chromium OS Authors. | ||
31 | |||
32 | +from collections import OrderedDict | ||
33 | import re | ||
34 | |||
35 | class Expr: | ||
36 | @@ -120,7 +121,7 @@ class Boards: | ||
37 | Args: | ||
38 | fname: Filename of boards.cfg file | ||
39 | """ | ||
40 | - with open(fname, 'r') as fd: | ||
41 | + with open(fname, 'r', encoding='utf-8') as fd: | ||
42 | for line in fd: | ||
43 | if line[0] == '#': | ||
44 | continue | ||
45 | @@ -155,7 +156,7 @@ class Boards: | ||
46 | key is board.target | ||
47 | value is board | ||
48 | """ | ||
49 | - board_dict = {} | ||
50 | + board_dict = OrderedDict() | ||
51 | for board in self._boards: | ||
52 | board_dict[board.target] = board | ||
53 | return board_dict | ||
54 | @@ -166,7 +167,7 @@ class Boards: | ||
55 | Returns: | ||
56 | List of Board objects that are marked selected | ||
57 | """ | ||
58 | - board_dict = {} | ||
59 | + board_dict = OrderedDict() | ||
60 | for board in self._boards: | ||
61 | if board.build_it: | ||
62 | board_dict[board.target] = board | ||
63 | @@ -259,7 +260,7 @@ class Boards: | ||
64 | due to each argument, arranged by argument. | ||
65 | List of errors found | ||
66 | """ | ||
67 | - result = {} | ||
68 | + result = OrderedDict() | ||
69 | warnings = [] | ||
70 | terms = self._BuildTerms(args) | ||
71 | |||
72 | diff --git a/tools/buildman/bsettings.py b/tools/buildman/bsettings.py | ||
73 | index 03d7439aa5..0b7208da37 100644 | ||
74 | --- a/tools/buildman/bsettings.py | ||
75 | +++ b/tools/buildman/bsettings.py | ||
76 | @@ -1,9 +1,9 @@ | ||
77 | # SPDX-License-Identifier: GPL-2.0+ | ||
78 | # Copyright (c) 2012 The Chromium OS Authors. | ||
79 | |||
80 | -import ConfigParser | ||
81 | +import configparser | ||
82 | import os | ||
83 | -import StringIO | ||
84 | +import io | ||
85 | |||
86 | |||
87 | def Setup(fname=''): | ||
88 | @@ -15,20 +15,20 @@ def Setup(fname=''): | ||
89 | global settings | ||
90 | global config_fname | ||
91 | |||
92 | - settings = ConfigParser.SafeConfigParser() | ||
93 | + settings = configparser.SafeConfigParser() | ||
94 | if fname is not None: | ||
95 | config_fname = fname | ||
96 | if config_fname == '': | ||
97 | config_fname = '%s/.buildman' % os.getenv('HOME') | ||
98 | if not os.path.exists(config_fname): | ||
99 | - print 'No config file found ~/.buildman\nCreating one...\n' | ||
100 | + print('No config file found ~/.buildman\nCreating one...\n') | ||
101 | CreateBuildmanConfigFile(config_fname) | ||
102 | - print 'To install tool chains, please use the --fetch-arch option' | ||
103 | + print('To install tool chains, please use the --fetch-arch option') | ||
104 | if config_fname: | ||
105 | settings.read(config_fname) | ||
106 | |||
107 | def AddFile(data): | ||
108 | - settings.readfp(StringIO.StringIO(data)) | ||
109 | + settings.readfp(io.StringIO(data)) | ||
110 | |||
111 | def GetItems(section): | ||
112 | """Get the items from a section of the config. | ||
113 | @@ -41,7 +41,7 @@ def GetItems(section): | ||
114 | """ | ||
115 | try: | ||
116 | return settings.items(section) | ||
117 | - except ConfigParser.NoSectionError as e: | ||
118 | + except configparser.NoSectionError as e: | ||
119 | return [] | ||
120 | except: | ||
121 | raise | ||
122 | @@ -68,10 +68,10 @@ def CreateBuildmanConfigFile(config_fname): | ||
123 | try: | ||
124 | f = open(config_fname, 'w') | ||
125 | except IOError: | ||
126 | - print "Couldn't create buildman config file '%s'\n" % config_fname | ||
127 | + print("Couldn't create buildman config file '%s'\n" % config_fname) | ||
128 | raise | ||
129 | |||
130 | - print >>f, '''[toolchain] | ||
131 | + print('''[toolchain] | ||
132 | # name = path | ||
133 | # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux | ||
134 | |||
135 | @@ -93,5 +93,5 @@ openrisc = or1k | ||
136 | # snapper-boards=ENABLE_AT91_TEST=1 | ||
137 | # snapper9260=${snapper-boards} BUILD_TAG=442 | ||
138 | # snapper9g45=${snapper-boards} BUILD_TAG=443 | ||
139 | -''' | ||
140 | +''', file=f) | ||
141 | f.close(); | ||
142 | diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py | ||
143 | index fbb236676c..cfbe4c26b1 100644 | ||
144 | --- a/tools/buildman/builder.py | ||
145 | +++ b/tools/buildman/builder.py | ||
146 | @@ -9,7 +9,7 @@ from datetime import datetime, timedelta | ||
147 | import glob | ||
148 | import os | ||
149 | import re | ||
150 | -import Queue | ||
151 | +import queue | ||
152 | import shutil | ||
153 | import signal | ||
154 | import string | ||
155 | @@ -92,11 +92,10 @@ u-boot/ source directory | ||
156 | """ | ||
157 | |||
158 | # Possible build outcomes | ||
159 | -OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = range(4) | ||
160 | +OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = list(range(4)) | ||
161 | |||
162 | # Translate a commit subject into a valid filename (and handle unicode) | ||
163 | -trans_valid_chars = string.maketrans('/: ', '---') | ||
164 | -trans_valid_chars = trans_valid_chars.decode('latin-1') | ||
165 | +trans_valid_chars = str.maketrans('/: ', '---') | ||
166 | |||
167 | BASE_CONFIG_FILENAMES = [ | ||
168 | 'u-boot.cfg', 'u-boot-spl.cfg', 'u-boot-tpl.cfg' | ||
169 | @@ -122,8 +121,8 @@ class Config: | ||
170 | def __hash__(self): | ||
171 | val = 0 | ||
172 | for fname in self.config: | ||
173 | - for key, value in self.config[fname].iteritems(): | ||
174 | - print key, value | ||
175 | + for key, value in self.config[fname].items(): | ||
176 | + print(key, value) | ||
177 | val = val ^ hash(key) & hash(value) | ||
178 | return val | ||
179 | |||
180 | @@ -293,8 +292,8 @@ class Builder: | ||
181 | self._re_dtb_warning = re.compile('(.*): Warning .*') | ||
182 | self._re_note = re.compile('(.*):(\d*):(\d*): note: this is the location of the previous.*') | ||
183 | |||
184 | - self.queue = Queue.Queue() | ||
185 | - self.out_queue = Queue.Queue() | ||
186 | + self.queue = queue.Queue() | ||
187 | + self.out_queue = queue.Queue() | ||
188 | for i in range(self.num_threads): | ||
189 | t = builderthread.BuilderThread(self, i, incremental, | ||
190 | per_board_out_dir) | ||
191 | @@ -781,7 +780,7 @@ class Builder: | ||
192 | config = {} | ||
193 | environment = {} | ||
194 | |||
195 | - for board in boards_selected.itervalues(): | ||
196 | + for board in boards_selected.values(): | ||
197 | outcome = self.GetBuildOutcome(commit_upto, board.target, | ||
198 | read_func_sizes, read_config, | ||
199 | read_environment) | ||
200 | @@ -814,13 +813,13 @@ class Builder: | ||
201 | tconfig = Config(self.config_filenames, board.target) | ||
202 | for fname in self.config_filenames: | ||
203 | if outcome.config: | ||
204 | - for key, value in outcome.config[fname].iteritems(): | ||
205 | + for key, value in outcome.config[fname].items(): | ||
206 | tconfig.Add(fname, key, value) | ||
207 | config[board.target] = tconfig | ||
208 | |||
209 | tenvironment = Environment(board.target) | ||
210 | if outcome.environment: | ||
211 | - for key, value in outcome.environment.iteritems(): | ||
212 | + for key, value in outcome.environment.items(): | ||
213 | tenvironment.Add(key, value) | ||
214 | environment[board.target] = tenvironment | ||
215 | |||
216 | @@ -1040,12 +1039,12 @@ class Builder: | ||
217 | |||
218 | # We now have a list of image size changes sorted by arch | ||
219 | # Print out a summary of these | ||
220 | - for arch, target_list in arch_list.iteritems(): | ||
221 | + for arch, target_list in arch_list.items(): | ||
222 | # Get total difference for each type | ||
223 | totals = {} | ||
224 | for result in target_list: | ||
225 | total = 0 | ||
226 | - for name, diff in result.iteritems(): | ||
227 | + for name, diff in result.items(): | ||
228 | if name.startswith('_'): | ||
229 | continue | ||
230 | total += diff | ||
231 | @@ -1250,7 +1249,7 @@ class Builder: | ||
232 | if self._show_unknown: | ||
233 | self.AddOutcome(board_selected, arch_list, unknown_boards, '?', | ||
234 | self.col.MAGENTA) | ||
235 | - for arch, target_list in arch_list.iteritems(): | ||
236 | + for arch, target_list in arch_list.items(): | ||
237 | Print('%10s: %s' % (arch, target_list)) | ||
238 | self._error_lines += 1 | ||
239 | if better_err: | ||
240 | @@ -1283,13 +1282,13 @@ class Builder: | ||
241 | environment_minus = {} | ||
242 | environment_change = {} | ||
243 | base = tbase.environment | ||
244 | - for key, value in tenvironment.environment.iteritems(): | ||
245 | + for key, value in tenvironment.environment.items(): | ||
246 | if key not in base: | ||
247 | environment_plus[key] = value | ||
248 | - for key, value in base.iteritems(): | ||
249 | + for key, value in base.items(): | ||
250 | if key not in tenvironment.environment: | ||
251 | environment_minus[key] = value | ||
252 | - for key, value in base.iteritems(): | ||
253 | + for key, value in base.items(): | ||
254 | new_value = tenvironment.environment.get(key) | ||
255 | if new_value and value != new_value: | ||
256 | desc = '%s -> %s' % (value, new_value) | ||
257 | @@ -1342,15 +1341,15 @@ class Builder: | ||
258 | config_minus = {} | ||
259 | config_change = {} | ||
260 | base = tbase.config[name] | ||
261 | - for key, value in tconfig.config[name].iteritems(): | ||
262 | + for key, value in tconfig.config[name].items(): | ||
263 | if key not in base: | ||
264 | config_plus[key] = value | ||
265 | all_config_plus[key] = value | ||
266 | - for key, value in base.iteritems(): | ||
267 | + for key, value in base.items(): | ||
268 | if key not in tconfig.config[name]: | ||
269 | config_minus[key] = value | ||
270 | all_config_minus[key] = value | ||
271 | - for key, value in base.iteritems(): | ||
272 | + for key, value in base.items(): | ||
273 | new_value = tconfig.config.get(key) | ||
274 | if new_value and value != new_value: | ||
275 | desc = '%s -> %s' % (value, new_value) | ||
276 | @@ -1368,7 +1367,7 @@ class Builder: | ||
277 | summary[target] = '\n'.join(lines) | ||
278 | |||
279 | lines_by_target = {} | ||
280 | - for target, lines in summary.iteritems(): | ||
281 | + for target, lines in summary.items(): | ||
282 | if lines in lines_by_target: | ||
283 | lines_by_target[lines].append(target) | ||
284 | else: | ||
285 | @@ -1392,7 +1391,7 @@ class Builder: | ||
286 | Print('%s:' % arch) | ||
287 | _OutputConfigInfo(lines) | ||
288 | |||
289 | - for lines, targets in lines_by_target.iteritems(): | ||
290 | + for lines, targets in lines_by_target.items(): | ||
291 | if not lines: | ||
292 | continue | ||
293 | Print('%s :' % ' '.join(sorted(targets))) | ||
294 | @@ -1463,7 +1462,7 @@ class Builder: | ||
295 | commits: Selected commits to build | ||
296 | """ | ||
297 | # First work out how many commits we will build | ||
298 | - count = (self.commit_count + self._step - 1) / self._step | ||
299 | + count = (self.commit_count + self._step - 1) // self._step | ||
300 | self.count = len(board_selected) * count | ||
301 | self.upto = self.warned = self.fail = 0 | ||
302 | self._timestamps = collections.deque() | ||
303 | @@ -1566,7 +1565,7 @@ class Builder: | ||
304 | self.ProcessResult(None) | ||
305 | |||
306 | # Create jobs to build all commits for each board | ||
307 | - for brd in board_selected.itervalues(): | ||
308 | + for brd in board_selected.values(): | ||
309 | job = builderthread.BuilderJob() | ||
310 | job.board = brd | ||
311 | job.commits = commits | ||
312 | diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py | ||
313 | index 8a9d47cd5e..570c1f6595 100644 | ||
314 | --- a/tools/buildman/builderthread.py | ||
315 | +++ b/tools/buildman/builderthread.py | ||
316 | @@ -28,7 +28,7 @@ def Mkdir(dirname, parents = False): | ||
317 | except OSError as err: | ||
318 | if err.errno == errno.EEXIST: | ||
319 | if os.path.realpath('.') == os.path.realpath(dirname): | ||
320 | - print "Cannot create the current working directory '%s'!" % dirname | ||
321 | + print("Cannot create the current working directory '%s'!" % dirname) | ||
322 | sys.exit(1) | ||
323 | pass | ||
324 | else: | ||
325 | @@ -291,15 +291,13 @@ class BuilderThread(threading.Thread): | ||
326 | outfile = os.path.join(build_dir, 'log') | ||
327 | with open(outfile, 'w') as fd: | ||
328 | if result.stdout: | ||
329 | - # We don't want unicode characters in log files | ||
330 | - fd.write(result.stdout.decode('UTF-8').encode('ASCII', 'replace')) | ||
331 | + fd.write(result.stdout) | ||
332 | |||
333 | errfile = self.builder.GetErrFile(result.commit_upto, | ||
334 | result.brd.target) | ||
335 | if result.stderr: | ||
336 | with open(errfile, 'w') as fd: | ||
337 | - # We don't want unicode characters in log files | ||
338 | - fd.write(result.stderr.decode('UTF-8').encode('ASCII', 'replace')) | ||
339 | + fd.write(result.stderr) | ||
340 | elif os.path.exists(errfile): | ||
341 | os.remove(errfile) | ||
342 | |||
343 | @@ -314,17 +312,17 @@ class BuilderThread(threading.Thread): | ||
344 | else: | ||
345 | fd.write('%s' % result.return_code) | ||
346 | with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: | ||
347 | - print >>fd, 'gcc', result.toolchain.gcc | ||
348 | - print >>fd, 'path', result.toolchain.path | ||
349 | - print >>fd, 'cross', result.toolchain.cross | ||
350 | - print >>fd, 'arch', result.toolchain.arch | ||
351 | + print('gcc', result.toolchain.gcc, file=fd) | ||
352 | + print('path', result.toolchain.path, file=fd) | ||
353 | + print('cross', result.toolchain.cross, file=fd) | ||
354 | + print('arch', result.toolchain.arch, file=fd) | ||
355 | fd.write('%s' % result.return_code) | ||
356 | |||
357 | # Write out the image and function size information and an objdump | ||
358 | env = result.toolchain.MakeEnvironment(self.builder.full_path) | ||
359 | with open(os.path.join(build_dir, 'env'), 'w') as fd: | ||
360 | for var in sorted(env.keys()): | ||
361 | - print >>fd, '%s="%s"' % (var, env[var]) | ||
362 | + print('%s="%s"' % (var, env[var]), file=fd) | ||
363 | lines = [] | ||
364 | for fname in ['u-boot', 'spl/u-boot-spl']: | ||
365 | cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname] | ||
366 | @@ -335,7 +333,7 @@ class BuilderThread(threading.Thread): | ||
367 | nm = self.builder.GetFuncSizesFile(result.commit_upto, | ||
368 | result.brd.target, fname) | ||
369 | with open(nm, 'w') as fd: | ||
370 | - print >>fd, nm_result.stdout, | ||
371 | + print(nm_result.stdout, end=' ', file=fd) | ||
372 | |||
373 | cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname] | ||
374 | dump_result = command.RunPipe([cmd], capture=True, | ||
375 | @@ -346,7 +344,7 @@ class BuilderThread(threading.Thread): | ||
376 | objdump = self.builder.GetObjdumpFile(result.commit_upto, | ||
377 | result.brd.target, fname) | ||
378 | with open(objdump, 'w') as fd: | ||
379 | - print >>fd, dump_result.stdout, | ||
380 | + print(dump_result.stdout, end=' ', file=fd) | ||
381 | for line in dump_result.stdout.splitlines(): | ||
382 | fields = line.split() | ||
383 | if len(fields) > 5 and fields[1] == '.rodata': | ||
384 | @@ -378,7 +376,7 @@ class BuilderThread(threading.Thread): | ||
385 | sizes = self.builder.GetSizesFile(result.commit_upto, | ||
386 | result.brd.target) | ||
387 | with open(sizes, 'w') as fd: | ||
388 | - print >>fd, '\n'.join(lines) | ||
389 | + print('\n'.join(lines), file=fd) | ||
390 | |||
391 | # Write out the configuration files, with a special case for SPL | ||
392 | for dirname in ['', 'spl', 'tpl']: | ||
393 | diff --git a/tools/buildman/buildman.py b/tools/buildman/buildman.py | ||
394 | index f17aa15e7c..30a8690f93 100755 | ||
395 | --- a/tools/buildman/buildman.py | ||
396 | +++ b/tools/buildman/buildman.py | ||
397 | @@ -1,4 +1,4 @@ | ||
398 | -#!/usr/bin/env python2 | ||
399 | +#!/usr/bin/env python3 | ||
400 | # SPDX-License-Identifier: GPL-2.0+ | ||
401 | # | ||
402 | # Copyright (c) 2012 The Chromium OS Authors. | ||
403 | @@ -6,6 +6,8 @@ | ||
404 | |||
405 | """See README for more information""" | ||
406 | |||
407 | +from __future__ import print_function | ||
408 | + | ||
409 | import multiprocessing | ||
410 | import os | ||
411 | import re | ||
412 | @@ -46,11 +48,11 @@ def RunTests(skip_net_tests): | ||
413 | suite = unittest.TestLoader().loadTestsFromTestCase(module) | ||
414 | suite.run(result) | ||
415 | |||
416 | - print result | ||
417 | + print(result) | ||
418 | for test, err in result.errors: | ||
419 | - print err | ||
420 | + print(err) | ||
421 | for test, err in result.failures: | ||
422 | - print err | ||
423 | + print(err) | ||
424 | |||
425 | |||
426 | options, args = cmdline.ParseArgs() | ||
427 | diff --git a/tools/buildman/control.py b/tools/buildman/control.py | ||
428 | index 9787b86747..216012d001 100644 | ||
429 | --- a/tools/buildman/control.py | ||
430 | +++ b/tools/buildman/control.py | ||
431 | @@ -30,7 +30,7 @@ def GetActionSummary(is_summary, commits, selected, options): | ||
432 | """ | ||
433 | if commits: | ||
434 | count = len(commits) | ||
435 | - count = (count + options.step - 1) / options.step | ||
436 | + count = (count + options.step - 1) // options.step | ||
437 | commit_str = '%d commit%s' % (count, GetPlural(count)) | ||
438 | else: | ||
439 | commit_str = 'current source' | ||
440 | @@ -59,31 +59,31 @@ def ShowActions(series, why_selected, boards_selected, builder, options, | ||
441 | board_warnings: List of warnings obtained from board selected | ||
442 | """ | ||
443 | col = terminal.Color() | ||
444 | - print 'Dry run, so not doing much. But I would do this:' | ||
445 | |||
446 | + print('Dry run, so not doing much. But I would do this:') | ||
447 | + print() | ||
448 | if series: | ||
449 | commits = series.commits | ||
450 | else: | ||
451 | commits = None | ||
452 | - print GetActionSummary(False, commits, boards_selected, | ||
453 | - options) | ||
454 | - print 'Build directory: %s' % builder.base_dir | ||
455 | + print(GetActionSummary(False, commits, boards_selected, | ||
456 | + options)) | ||
457 | + print('Build directory: %s' % builder.base_dir) | ||
458 | if commits: | ||
459 | for upto in range(0, len(series.commits), options.step): | ||
460 | commit = series.commits[upto] | ||
461 | - print ' ', col.Color(col.YELLOW, commit.hash[:8], bright=False), | ||
462 | - print commit.subject | ||
463 | |||
464 | + print(' ', col.Color(col.YELLOW, commit.hash[:8], bright=False), end=' ') | ||
465 | + print(commit.subject) | ||
466 | + print() | ||
467 | for arg in why_selected: | ||
468 | if arg != 'all': | ||
469 | - print arg, ': %d boards' % len(why_selected[arg]) | ||
470 | + print(arg, ': %d boards' % len(why_selected[arg])) | ||
471 | if options.verbose: | ||
472 | - print ' %s' % ' '.join(why_selected[arg]) | ||
473 | - print ('Total boards to build for each commit: %d\n' % | ||
474 | - len(why_selected['all'])) | ||
475 | + print(' %s' % ' '.join(why_selected[arg])) | ||
476 | + print(('Total boards to build for each commit: %d\n' % | ||
477 | + len(why_selected['all']))) | ||
478 | if board_warnings: | ||
479 | for warning in board_warnings: | ||
480 | - print col.Color(col.YELLOW, warning) | ||
481 | + print(col.Color(col.YELLOW, warning)) | ||
482 | |||
483 | def CheckOutputDir(output_dir): | ||
484 | """Make sure that the output directory is not within the current directory | ||
485 | @@ -146,17 +146,17 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, | ||
486 | if options.fetch_arch: | ||
487 | if options.fetch_arch == 'list': | ||
488 | sorted_list = toolchains.ListArchs() | ||
489 | - print col.Color(col.BLUE, 'Available architectures: %s\n' % | ||
490 | - ' '.join(sorted_list)) | ||
491 | + print(col.Color(col.BLUE, 'Available architectures: %s\n' % | ||
492 | + ' '.join(sorted_list))) | ||
493 | return 0 | ||
494 | else: | ||
495 | fetch_arch = options.fetch_arch | ||
496 | if fetch_arch == 'all': | ||
497 | fetch_arch = ','.join(toolchains.ListArchs()) | ||
498 | - print col.Color(col.CYAN, '\nDownloading toolchains: %s' % | ||
499 | - fetch_arch) | ||
500 | + print(col.Color(col.CYAN, '\nDownloading toolchains: %s' % | ||
501 | + fetch_arch)) | ||
502 | for arch in fetch_arch.split(','): | ||
503 | |||
504 | + print() | ||
505 | ret = toolchains.FetchAndInstall(arch) | ||
506 | if ret: | ||
507 | return ret | ||
508 | @@ -167,7 +167,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, | ||
509 | toolchains.Scan(options.list_tool_chains and options.verbose) | ||
510 | if options.list_tool_chains: | ||
511 | toolchains.List() | ||
512 | |||
513 | + print() | ||
514 | return 0 | ||
515 | |||
516 | # Work out how many commits to build. We want to build everything on the | ||
517 | @@ -191,7 +191,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, | ||
518 | sys.exit(col.Color(col.RED, "Range '%s' has no commits" % | ||
519 | options.branch)) | ||
520 | if msg: | ||
521 | - print col.Color(col.YELLOW, msg) | ||
522 | + print(col.Color(col.YELLOW, msg)) | ||
523 | count += 1 # Build upstream commit also | ||
524 | |||
525 | if not count: | ||
526 | @@ -268,7 +268,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, | ||
527 | options.threads = min(multiprocessing.cpu_count(), len(selected)) | ||
528 | if not options.jobs: | ||
529 | options.jobs = max(1, (multiprocessing.cpu_count() + | ||
530 | - len(selected) - 1) / len(selected)) | ||
531 | + len(selected) - 1) // len(selected)) | ||
532 | |||
533 | if not options.step: | ||
534 | options.step = len(series.commits) - 1 | ||
535 | diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py | ||
536 | index f90b8ea7f5..4c3d497294 100644 | ||
537 | --- a/tools/buildman/func_test.py | ||
538 | +++ b/tools/buildman/func_test.py | ||
539 | @@ -270,7 +270,7 @@ class TestFunctional(unittest.TestCase): | ||
540 | stdout=''.join(commit_log[:count])) | ||
541 | |||
542 | # Not handled, so abort | ||
543 | - print 'git log', args | ||
544 | + print('git log', args) | ||
545 | sys.exit(1) | ||
546 | |||
547 | def _HandleCommandGitConfig(self, args): | ||
548 | @@ -286,7 +286,7 @@ class TestFunctional(unittest.TestCase): | ||
549 | stdout='refs/heads/master\n') | ||
550 | |||
551 | # Not handled, so abort | ||
552 | - print 'git config', args | ||
553 | + print('git config', args) | ||
554 | sys.exit(1) | ||
555 | |||
556 | def _HandleCommandGit(self, in_args): | ||
557 | @@ -320,7 +320,7 @@ class TestFunctional(unittest.TestCase): | ||
558 | return command.CommandResult(return_code=0) | ||
559 | |||
560 | # Not handled, so abort | ||
561 | - print 'git', git_args, sub_cmd, args | ||
562 | + print('git', git_args, sub_cmd, args) | ||
563 | sys.exit(1) | ||
564 | |||
565 | def _HandleCommandNm(self, args): | ||
566 | @@ -351,7 +351,7 @@ class TestFunctional(unittest.TestCase): | ||
567 | if pipe_list[1] == ['wc', '-l']: | ||
568 | wc = True | ||
569 | else: | ||
570 | - print 'invalid pipe', kwargs | ||
571 | + print('invalid pipe', kwargs) | ||
572 | sys.exit(1) | ||
573 | cmd = pipe_list[0][0] | ||
574 | args = pipe_list[0][1:] | ||
575 | @@ -371,7 +371,7 @@ class TestFunctional(unittest.TestCase): | ||
576 | |||
577 | if not result: | ||
578 | # Not handled, so abort | ||
579 | - print 'unknown command', kwargs | ||
580 | + print('unknown command', kwargs) | ||
581 | sys.exit(1) | ||
582 | |||
583 | if wc: | ||
584 | @@ -404,14 +404,14 @@ class TestFunctional(unittest.TestCase): | ||
585 | return command.CommandResult(return_code=0) | ||
586 | |||
587 | # Not handled, so abort | ||
588 | - print 'make', stage | ||
589 | + print('make', stage) | ||
590 | sys.exit(1) | ||
591 | |||
592 | # Example function to print output lines | ||
593 | def print_lines(self, lines): | ||
594 | - print len(lines) | ||
595 | + print(len(lines)) | ||
596 | for line in lines: | ||
597 | - print line | ||
598 | + print(line) | ||
599 | #self.print_lines(terminal.GetPrintTestLines()) | ||
600 | |||
601 | def testNoBoards(self): | ||
602 | diff --git a/tools/buildman/test.py b/tools/buildman/test.py | ||
603 | index ed99b9375c..b4e28d6867 100644 | ||
604 | --- a/tools/buildman/test.py | ||
605 | +++ b/tools/buildman/test.py | ||
606 | @@ -212,11 +212,11 @@ class TestBuild(unittest.TestCase): | ||
607 | self.assertEqual(lines[1].text, '02: %s' % commits[1][1]) | ||
608 | |||
609 | col = terminal.Color() | ||
610 | - self.assertSummary(lines[2].text, 'sandbox', 'w+', ['board4'], | ||
611 | + self.assertSummary(lines[2].text, 'arm', 'w+', ['board1'], | ||
612 | outcome=OUTCOME_WARN) | ||
613 | - self.assertSummary(lines[3].text, 'arm', 'w+', ['board1'], | ||
614 | + self.assertSummary(lines[3].text, 'powerpc', 'w+', ['board2', 'board3'], | ||
615 | outcome=OUTCOME_WARN) | ||
616 | - self.assertSummary(lines[4].text, 'powerpc', 'w+', ['board2', 'board3'], | ||
617 | + self.assertSummary(lines[4].text, 'sandbox', 'w+', ['board4'], | ||
618 | outcome=OUTCOME_WARN) | ||
619 | |||
620 | # Second commit: The warnings should be listed | ||
621 | @@ -226,10 +226,10 @@ class TestBuild(unittest.TestCase): | ||
622 | |||
623 | # Third commit: Still fails | ||
624 | self.assertEqual(lines[6].text, '03: %s' % commits[2][1]) | ||
625 | - self.assertSummary(lines[7].text, 'sandbox', '+', ['board4']) | ||
626 | - self.assertSummary(lines[8].text, 'arm', '', ['board1'], | ||
627 | + self.assertSummary(lines[7].text, 'arm', '', ['board1'], | ||
628 | outcome=OUTCOME_OK) | ||
629 | - self.assertSummary(lines[9].text, 'powerpc', '+', ['board2', 'board3']) | ||
630 | + self.assertSummary(lines[8].text, 'powerpc', '+', ['board2', 'board3']) | ||
631 | + self.assertSummary(lines[9].text, 'sandbox', '+', ['board4']) | ||
632 | |||
633 | # Expect a compiler error | ||
634 | self.assertEqual(lines[10].text, '+%s' % | ||
635 | @@ -237,8 +237,6 @@ class TestBuild(unittest.TestCase): | ||
636 | |||
637 | # Fourth commit: Compile errors are fixed, just have warning for board3 | ||
638 | self.assertEqual(lines[11].text, '04: %s' % commits[3][1]) | ||
639 | - self.assertSummary(lines[12].text, 'sandbox', 'w+', ['board4'], | ||
640 | - outcome=OUTCOME_WARN) | ||
641 | expect = '%10s: ' % 'powerpc' | ||
642 | expect += ' ' + col.Color(col.GREEN, '') | ||
643 | expect += ' ' | ||
644 | @@ -246,7 +244,9 @@ class TestBuild(unittest.TestCase): | ||
645 | expect += ' ' + col.Color(col.YELLOW, 'w+') | ||
646 | expect += ' ' | ||
647 | expect += col.Color(col.YELLOW, ' %s' % 'board3') | ||
648 | - self.assertEqual(lines[13].text, expect) | ||
649 | + self.assertEqual(lines[12].text, expect) | ||
650 | + self.assertSummary(lines[13].text, 'sandbox', 'w+', ['board4'], | ||
651 | + outcome=OUTCOME_WARN) | ||
652 | |||
653 | # Compile error fixed | ||
654 | self.assertEqual(lines[14].text, '-%s' % | ||
655 | @@ -259,9 +259,9 @@ class TestBuild(unittest.TestCase): | ||
656 | |||
657 | # Fifth commit | ||
658 | self.assertEqual(lines[16].text, '05: %s' % commits[4][1]) | ||
659 | - self.assertSummary(lines[17].text, 'sandbox', '+', ['board4']) | ||
660 | - self.assertSummary(lines[18].text, 'powerpc', '', ['board3'], | ||
661 | + self.assertSummary(lines[17].text, 'powerpc', '', ['board3'], | ||
662 | outcome=OUTCOME_OK) | ||
663 | + self.assertSummary(lines[18].text, 'sandbox', '+', ['board4']) | ||
664 | |||
665 | # The second line of errors[3] is a duplicate, so buildman will drop it | ||
666 | expect = errors[3].rstrip().split('\n') | ||
667 | diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py | ||
668 | index a65737fdf8..cc26e2ede5 100644 | ||
669 | --- a/tools/buildman/toolchain.py | ||
670 | +++ b/tools/buildman/toolchain.py | ||
671 | @@ -4,18 +4,19 @@ | ||
672 | |||
673 | import re | ||
674 | import glob | ||
675 | -from HTMLParser import HTMLParser | ||
676 | +from html.parser import HTMLParser | ||
677 | import os | ||
678 | import sys | ||
679 | import tempfile | ||
680 | -import urllib2 | ||
681 | +import urllib.request, urllib.error, urllib.parse | ||
682 | |||
683 | import bsettings | ||
684 | import command | ||
685 | import terminal | ||
686 | +import tools | ||
687 | |||
688 | (PRIORITY_FULL_PREFIX, PRIORITY_PREFIX_GCC, PRIORITY_PREFIX_GCC_PATH, | ||
689 | - PRIORITY_CALC) = range(4) | ||
690 | + PRIORITY_CALC) = list(range(4)) | ||
691 | |||
692 | # Simple class to collect links from a page | ||
693 | class MyHTMLParser(HTMLParser): | ||
694 | @@ -100,15 +101,15 @@ class Toolchain: | ||
695 | raise_on_error=False) | ||
696 | self.ok = result.return_code == 0 | ||
697 | if verbose: | ||
698 | - print 'Tool chain test: ', | ||
699 | + print('Tool chain test: ', end=' ') | ||
700 | if self.ok: | ||
701 | - print "OK, arch='%s', priority %d" % (self.arch, | ||
702 | - self.priority) | ||
703 | + print("OK, arch='%s', priority %d" % (self.arch, | ||
704 | + self.priority)) | ||
705 | else: | ||
706 | - print 'BAD' | ||
707 | - print 'Command: ', cmd | ||
708 | - print result.stdout | ||
709 | - print result.stderr | ||
710 | + print('BAD') | ||
711 | + print('Command: ', cmd) | ||
712 | + print(result.stdout) | ||
713 | + print(result.stderr) | ||
714 | else: | ||
715 | self.ok = True | ||
716 | |||
717 | @@ -138,7 +139,7 @@ class Toolchain: | ||
718 | value = '' | ||
719 | for name, value in bsettings.GetItems('toolchain-wrapper'): | ||
720 | if not value: | ||
721 | - print "Warning: Wrapper not found" | ||
722 | + print("Warning: Wrapper not found") | ||
723 | if value: | ||
724 | value = value + ' ' | ||
725 | |||
726 | @@ -227,11 +228,11 @@ class Toolchains: | ||
727 | """ | ||
728 | toolchains = bsettings.GetItems('toolchain') | ||
729 | if show_warning and not toolchains: | ||
730 | - print ("Warning: No tool chains. Please run 'buildman " | ||
731 | + print(("Warning: No tool chains. Please run 'buildman " | ||
732 | "--fetch-arch all' to download all available toolchains, or " | ||
733 | "add a [toolchain] section to your buildman config file " | ||
734 | "%s. See README for details" % | ||
735 | - bsettings.config_fname) | ||
736 | + bsettings.config_fname)) | ||
737 | |||
738 | paths = [] | ||
739 | for name, value in toolchains: | ||
740 | @@ -272,10 +273,10 @@ class Toolchains: | ||
741 | if add_it: | ||
742 | self.toolchains[toolchain.arch] = toolchain | ||
743 | elif verbose: | ||
744 | - print ("Toolchain '%s' at priority %d will be ignored because " | ||
745 | + print(("Toolchain '%s' at priority %d will be ignored because " | ||
746 | "another toolchain for arch '%s' has priority %d" % | ||
747 | (toolchain.gcc, toolchain.priority, toolchain.arch, | ||
748 | - self.toolchains[toolchain.arch].priority)) | ||
749 | + self.toolchains[toolchain.arch].priority))) | ||
750 | |||
751 | def ScanPath(self, path, verbose): | ||
752 | """Scan a path for a valid toolchain | ||
753 | @@ -289,9 +290,9 @@ class Toolchains: | ||
754 | fnames = [] | ||
755 | for subdir in ['.', 'bin', 'usr/bin']: | ||
756 | dirname = os.path.join(path, subdir) | ||
757 | - if verbose: print " - looking in '%s'" % dirname | ||
758 | + if verbose: print(" - looking in '%s'" % dirname) | ||
759 | for fname in glob.glob(dirname + '/*gcc'): | ||
760 | - if verbose: print " - found '%s'" % fname | ||
761 | + if verbose: print(" - found '%s'" % fname) | ||
762 | fnames.append(fname) | ||
763 | return fnames | ||
764 | |||
765 | @@ -321,9 +322,9 @@ class Toolchains: | ||
766 | Args: | ||
767 | verbose: True to print out progress information | ||
768 | """ | ||
769 | - if verbose: print 'Scanning for tool chains' | ||
770 | + if verbose: print('Scanning for tool chains') | ||
771 | for name, value in self.prefixes: | ||
772 | - if verbose: print " - scanning prefix '%s'" % value | ||
773 | + if verbose: print(" - scanning prefix '%s'" % value) | ||
774 | if os.path.exists(value): | ||
775 | self.Add(value, True, verbose, PRIORITY_FULL_PREFIX, name) | ||
776 | continue | ||
777 | @@ -335,10 +336,10 @@ class Toolchains: | ||
778 | for f in fname_list: | ||
779 | self.Add(f, True, verbose, PRIORITY_PREFIX_GCC_PATH, name) | ||
780 | if not fname_list: | ||
781 | - raise ValueError, ("No tool chain found for prefix '%s'" % | ||
782 | + raise ValueError("No tool chain found for prefix '%s'" % | ||
783 | value) | ||
784 | for path in self.paths: | ||
785 | - if verbose: print " - scanning path '%s'" % path | ||
786 | + if verbose: print(" - scanning path '%s'" % path) | ||
787 | fnames = self.ScanPath(path, verbose) | ||
788 | for fname in fnames: | ||
789 | self.Add(fname, True, verbose) | ||
790 | @@ -346,13 +347,13 @@ class Toolchains: | ||
791 | def List(self): | ||
792 | """List out the selected toolchains for each architecture""" | ||
793 | col = terminal.Color() | ||
794 | - print col.Color(col.BLUE, 'List of available toolchains (%d):' % | ||
795 | - len(self.toolchains)) | ||
796 | + print(col.Color(col.BLUE, 'List of available toolchains (%d):' % | ||
797 | + len(self.toolchains))) | ||
798 | if len(self.toolchains): | ||
799 | - for key, value in sorted(self.toolchains.iteritems()): | ||
800 | - print '%-10s: %s' % (key, value.gcc) | ||
801 | + for key, value in sorted(self.toolchains.items()): | ||
802 | + print('%-10s: %s' % (key, value.gcc)) | ||
803 | else: | ||
804 | - print 'None' | ||
805 | + print('None') | ||
806 | |||
807 | def Select(self, arch): | ||
808 | """Returns the toolchain for a given architecture | ||
809 | @@ -370,7 +371,7 @@ class Toolchains: | ||
810 | return self.toolchains[alias] | ||
811 | |||
812 | if not arch in self.toolchains: | ||
813 | - raise ValueError, ("No tool chain found for arch '%s'" % arch) | ||
814 | + raise ValueError("No tool chain found for arch '%s'" % arch) | ||
815 | return self.toolchains[arch] | ||
816 | |||
817 | def ResolveReferences(self, var_dict, args): | ||
818 | @@ -464,9 +465,9 @@ class Toolchains: | ||
819 | links = [] | ||
820 | for version in versions: | ||
821 | url = '%s/%s/%s/' % (base, arch, version) | ||
822 | - print 'Checking: %s' % url | ||
823 | - response = urllib2.urlopen(url) | ||
824 | - html = response.read() | ||
825 | + print('Checking: %s' % url) | ||
826 | + response = urllib.request.urlopen(url) | ||
827 | + html = tools.ToString(response.read()) | ||
828 | parser = MyHTMLParser(fetch_arch) | ||
829 | parser.feed(html) | ||
830 | if fetch_arch == 'list': | ||
831 | @@ -488,14 +489,14 @@ class Toolchains: | ||
832 | Full path to the downloaded archive file in that directory, | ||
833 | or None if there was an error while downloading | ||
834 | """ | ||
835 | - print 'Downloading: %s' % url | ||
836 | + print('Downloading: %s' % url) | ||
837 | leaf = url.split('/')[-1] | ||
838 | tmpdir = tempfile.mkdtemp('.buildman') | ||
839 | - response = urllib2.urlopen(url) | ||
840 | + response = urllib.request.urlopen(url) | ||
841 | fname = os.path.join(tmpdir, leaf) | ||
842 | fd = open(fname, 'wb') | ||
843 | meta = response.info() | ||
844 | - size = int(meta.getheaders('Content-Length')[0]) | ||
845 | + size = int(meta.get('Content-Length')) | ||
846 | done = 0 | ||
847 | block_size = 1 << 16 | ||
848 | status = '' | ||
849 | @@ -504,19 +505,19 @@ class Toolchains: | ||
850 | while True: | ||
851 | buffer = response.read(block_size) | ||
852 | if not buffer: | ||
853 | - print chr(8) * (len(status) + 1), '\r', | ||
854 | + print(chr(8) * (len(status) + 1), '\r', end=' ') | ||
855 | break | ||
856 | |||
857 | done += len(buffer) | ||
858 | fd.write(buffer) | ||
859 | - status = r'%10d MiB [%3d%%]' % (done / 1024 / 1024, | ||
860 | - done * 100 / size) | ||
861 | + status = r'%10d MiB [%3d%%]' % (done // 1024 // 1024, | ||
862 | + done * 100 // size) | ||
863 | status = status + chr(8) * (len(status) + 1) | ||
864 | - print status, | ||
865 | + print(status, end=' ') | ||
866 | sys.stdout.flush() | ||
867 | fd.close() | ||
868 | if done != size: | ||
869 | - print 'Error, failed to download' | ||
870 | + print('Error, failed to download') | ||
871 | os.remove(fname) | ||
872 | fname = None | ||
873 | return tmpdir, fname | ||
874 | @@ -565,11 +566,11 @@ class Toolchains: | ||
875 | """ | ||
876 | # Fist get the URL for this architecture | ||
877 | col = terminal.Color() | ||
878 | - print col.Color(col.BLUE, "Downloading toolchain for arch '%s'" % arch) | ||
879 | + print(col.Color(col.BLUE, "Downloading toolchain for arch '%s'" % arch)) | ||
880 | url = self.LocateArchUrl(arch) | ||
881 | if not url: | ||
882 | - print ("Cannot find toolchain for arch '%s' - use 'list' to list" % | ||
883 | - arch) | ||
884 | + print(("Cannot find toolchain for arch '%s' - use 'list' to list" % | ||
885 | + arch)) | ||
886 | return 2 | ||
887 | home = os.environ['HOME'] | ||
888 | dest = os.path.join(home, '.buildman-toolchains') | ||
889 | @@ -580,28 +581,28 @@ class Toolchains: | ||
890 | tmpdir, tarfile = self.Download(url) | ||
891 | if not tarfile: | ||
892 | return 1 | ||
893 | - print col.Color(col.GREEN, 'Unpacking to: %s' % dest), | ||
894 | + print(col.Color(col.GREEN, 'Unpacking to: %s' % dest), end=' ') | ||
895 | sys.stdout.flush() | ||
896 | path = self.Unpack(tarfile, dest) | ||
897 | os.remove(tarfile) | ||
898 | os.rmdir(tmpdir) | ||
899 | |||
900 | + print() | ||
901 | |||
902 | # Check that the toolchain works | ||
903 | - print col.Color(col.GREEN, 'Testing') | ||
904 | + print(col.Color(col.GREEN, 'Testing')) | ||
905 | dirpath = os.path.join(dest, path) | ||
906 | compiler_fname_list = self.ScanPath(dirpath, True) | ||
907 | if not compiler_fname_list: | ||
908 | - print 'Could not locate C compiler - fetch failed.' | ||
909 | + print('Could not locate C compiler - fetch failed.') | ||
910 | return 1 | ||
911 | if len(compiler_fname_list) != 1: | ||
912 | - print col.Color(col.RED, 'Warning, ambiguous toolchains: %s' % | ||
913 | - ', '.join(compiler_fname_list)) | ||
914 | + print(col.Color(col.RED, 'Warning, ambiguous toolchains: %s' % | ||
915 | + ', '.join(compiler_fname_list))) | ||
916 | toolchain = Toolchain(compiler_fname_list[0], True, True) | ||
917 | |||
918 | # Make sure that it will be found by buildman | ||
919 | if not self.TestSettingsHasPath(dirpath): | ||
920 | - print ("Adding 'download' to config file '%s'" % | ||
921 | - bsettings.config_fname) | ||
922 | + print(("Adding 'download' to config file '%s'" % | ||
923 | + bsettings.config_fname)) | ||
924 | bsettings.SetItem('toolchain', 'download', '%s/*/*' % dest) | ||
925 | return 0 | ||
926 | -- | ||
927 | 2.24.0 | ||
928 | |||