Commit ece5bb95 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

make_instrumenting_probes: Fix map() Python 3 compatibility

map() returns a list in Python 2. Python 3 returns an iterator.
Wrapping in a list() results in the same behaviour on both.

Traceback (most recent call last):
  File "../../third_party/blink/renderer/build/scripts/make_instrumenting_probes.py", line 283, in <module>
    main()
  File "../../third_party/blink/renderer/build/scripts/make_instrumenting_probes.py", line 262, in main
    cpp_file.write(cpp_template.render(template_context))
  File "C:\Google\chromium\src\third_party\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "C:\Google\chromium\src\third_party\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "C:\Google\chromium\src\third_party\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Google\chromium\src\third_party\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "C:\Google\chromium\src\third_party\blink\renderer\build\scripts\templates\instrumenting_probes_impl.cc.tmpl", line 129, in <module>
    void {{probe.name}}Impl({{ params_list(probe) }}) {
  File "C:\Google\chromium\src\third_party\jinja2\runtime.py", line 579, in _invoke
    rv = self._func(*arguments)
  File "C:\Google\chromium\src\third_party\blink\renderer\build\scripts\templates\instrumenting_probes_impl.cc.tmpl", line 91, in <module>
    {%- for param in probe.params %}
  File "C:\Google\chromium\src\third_party\jinja2\runtime.py", line 435, in __init__
    self._after = self._safe_next()
  File "C:\Google\chromium\src\third_party\jinja2\runtime.py", line 455, in _safe_next
    return next(self._iterator)
  File "../../third_party/blink/renderer/build/scripts/make_instrumenting_probes.py", line 148, in __init__
    self.default_value = parts[1] if len(parts) != 1 else None
TypeError: object of type 'map' has no len()

Traceback (most recent call last):
  File "../../third_party/blink/renderer/build/scripts/make_instrumenting_probes.py", line 283, in <module>
    main()
  File "../../third_party/blink/renderer/build/scripts/make_instrumenting_probes.py", line 262, in main
    cpp_file.write(cpp_template.render(template_context))
  File "C:\Google\chromium\src\third_party\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "C:\Google\chromium\src\third_party\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "C:\Google\chromium\src\third_party\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Google\chromium\src\third_party\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "C:\Google\chromium\src\third_party\blink\renderer\build\scripts\templates\instrumenting_probes_impl.cc.tmpl", line 130, in <module>
    {{sink_class}}* probe_sink = To{{sink_class}}({{probe.params[0].name}});
  File "C:\Google\chromium\src\third_party\jinja2\environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: map object has no element 0

Bug: 941669
Change-Id: Ie584b13c8b3e54ee9f06faffd57d93917c88ccfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033510
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#738465}
parent eadf26e3
......@@ -134,7 +134,7 @@ class Method(object):
raise Exception("Instant probe must return void: %s" % self.name)
# Splitting parameters by a comma, assuming that attribute lists contain no more than one attribute.
self.params = map(Parameter, map(str.strip, match.group(3).split(",")))
self.params = list(map(Parameter, map(str.strip, match.group(3).split(","))))
class Parameter(object):
......@@ -144,7 +144,7 @@ class Parameter(object):
if match:
self.options.append(match.group(1))
parts = map(str.strip, source.split("="))
parts = list(map(str.strip, source.split("=")))
self.default_value = parts[1] if len(parts) != 1 else None
param_decl = parts[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment