Reland "mojo: drop py2 compatibility"
This reverts commit28c3f06318
. Reason for revert: include fix for presubmit. Original change's description: > Revert "mojo: drop py2 compatibility" > > This reverts commit42775cc82e
. > > Reason for revert: causes http://crbug.com/1315672 > > Original change's description: > > mojo: drop py2 compatibility > > > > Python2 is not used for Chromium build now. > > > > Bug: 1309804 > > Change-Id: I77b767ae72d82faaaa00dd1cce15e73f890ec568 > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3581234 > > Auto-Submit: Takuto Ikuta <tikuta@chromium.org> > > Reviewed-by: Ken Rockot <rockot@google.com> > > Commit-Queue: Ken Rockot <rockot@google.com> > > Cr-Commit-Position: refs/heads/main@{#991607} > > Bug: 1309804 > Change-Id: Iee05768e1a785a2273af57854c4ffde51922254a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3584231 > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > Auto-Submit: Andrey Kosyakov <caseq@chromium.org> > Commit-Queue: Lei Zhang <thestig@chromium.org> > Owners-Override: Lei Zhang <thestig@chromium.org> > Cr-Commit-Position: refs/heads/main@{#991666} Bug: 1309804 Fixed: 1315672 Change-Id: Ib6150ca75c2f06607b73ae09a3f0864ebc92cdbe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3583686 Auto-Submit: Takuto Ikuta <tikuta@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#991868}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
86ef158eae
commit
dca102247d
@ -5499,7 +5499,7 @@ def CheckStableMojomChanges(input_api, output_api):
|
||||
})
|
||||
|
||||
process = input_api.subprocess.Popen([
|
||||
input_api.python_executable,
|
||||
input_api.python3_executable,
|
||||
input_api.os_path.join(
|
||||
input_api.PresubmitLocalPath(), 'mojo', 'public', 'tools', 'mojom',
|
||||
'check_stable_mojom_compatibility.py'), '--src-root',
|
||||
|
@ -70,6 +70,7 @@ class MockInputApi(object):
|
||||
self.os_path = os.path
|
||||
self.platform = sys.platform
|
||||
self.python_executable = sys.executable
|
||||
self.python3_executable = sys.executable
|
||||
self.platform = sys.platform
|
||||
self.subprocess = subprocess
|
||||
self.sys = sys
|
||||
|
@ -28,11 +28,6 @@ sys.path.insert(
|
||||
os.pardir, os.pardir, 'build', 'android', 'gyp'))
|
||||
from util import build_utils
|
||||
|
||||
# TODO(crbug.com/1174969): Remove this once Python2 is obsoleted.
|
||||
if sys.version_info.major != 2:
|
||||
basestring = str
|
||||
long = int
|
||||
|
||||
GENERATOR_PREFIX = 'java'
|
||||
|
||||
_spec_to_java_type = {
|
||||
@ -149,7 +144,7 @@ def GetInterfaceResponseName(method):
|
||||
return UpperCamelCase(method.name) + '_Response'
|
||||
|
||||
def ParseStringAttribute(attribute):
|
||||
assert isinstance(attribute, basestring)
|
||||
assert isinstance(attribute, str)
|
||||
return attribute
|
||||
|
||||
def GetJavaTrueFalse(value):
|
||||
@ -338,7 +333,7 @@ def ExpressionToText(context, token, kind_spec=''):
|
||||
return _TranslateNamedValue(token)
|
||||
if kind_spec.startswith('i') or kind_spec.startswith('u'):
|
||||
number = ast.literal_eval(token.lstrip('+ '))
|
||||
if not isinstance(number, (int, long)):
|
||||
if not isinstance(number, int):
|
||||
raise ValueError('got unexpected type %r for int literal %r' % (
|
||||
type(number), token))
|
||||
# If the literal is too large to fit a signed long, convert it to the
|
||||
|
@ -8,12 +8,9 @@ import mojom.generate.module as mojom
|
||||
import mojom.generate.pack as pack
|
||||
import os
|
||||
import sys
|
||||
import urllib.request
|
||||
from mojom.generate.template_expander import UseJinja
|
||||
|
||||
if sys.version_info.major == 2:
|
||||
import urllib as urllib_request
|
||||
else:
|
||||
import urllib.request as urllib_request
|
||||
|
||||
_kind_to_javascript_default_value = {
|
||||
mojom.BOOL: "false",
|
||||
@ -250,7 +247,7 @@ def GetArrayExpectedDimensionSizes(kind):
|
||||
|
||||
|
||||
def GetRelativeUrl(module, base_module):
|
||||
return urllib_request.pathname2url(
|
||||
return urllib.request.pathname2url(
|
||||
os.path.relpath(module.path, os.path.dirname(base_module.path)))
|
||||
|
||||
|
||||
@ -448,7 +445,7 @@ class Generator(generator.Generator):
|
||||
"mojom-webui/%s-webui.js" % self.module.path)
|
||||
|
||||
def _GetRelativePath(self, path):
|
||||
relpath = urllib_request.pathname2url(
|
||||
relpath = urllib.request.pathname2url(
|
||||
os.path.relpath(path, os.path.dirname(self.module.path)))
|
||||
if relpath.startswith('.') or relpath.startswith('/'):
|
||||
return relpath
|
||||
@ -1059,7 +1056,7 @@ class Generator(generator.Generator):
|
||||
return s[len(prefix):]
|
||||
return s
|
||||
|
||||
import_path = urllib_request.pathname2url(
|
||||
import_path = urllib.request.pathname2url(
|
||||
os.path.relpath(
|
||||
strip_prefix(import_path, _SHARED_MODULE_PREFIX),
|
||||
strip_prefix(this_module_path, _SHARED_MODULE_PREFIX)))
|
||||
|
@ -41,12 +41,6 @@ _kind_to_cpp_proto_type = {
|
||||
}
|
||||
|
||||
|
||||
def _IsStrOrUnicode(x):
|
||||
if sys.version_info[0] < 3:
|
||||
return isinstance(x, (unicode, str))
|
||||
return isinstance(x, str)
|
||||
|
||||
|
||||
class _NameFormatter(CppNameFormatter):
|
||||
"""A formatter for the names of kinds or values."""
|
||||
|
||||
@ -451,7 +445,7 @@ class Generator(CppGenerator):
|
||||
if field.name == 'MAX':
|
||||
continue
|
||||
if field.value:
|
||||
if _IsStrOrUnicode(field.value):
|
||||
if isinstance(field.value, str):
|
||||
if field.value in values:
|
||||
return True
|
||||
values.add(field.value)
|
||||
|
@ -12,11 +12,7 @@
|
||||
# method = interface.AddMethod('Tat', 0)
|
||||
# method.AddParameter('baz', 0, mojom.INT32)
|
||||
|
||||
import sys
|
||||
if sys.version_info.major == 2:
|
||||
import cPickle as pickle
|
||||
else:
|
||||
import pickle
|
||||
import pickle
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
|
@ -12,19 +12,12 @@ already been parsed and converted to ASTs before.
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from mojom.generate import generator
|
||||
from mojom.generate import module as mojom
|
||||
from mojom.parse import ast
|
||||
|
||||
|
||||
def _IsStrOrUnicode(x):
|
||||
if sys.version_info[0] < 3:
|
||||
return isinstance(x, (unicode, str))
|
||||
return isinstance(x, str)
|
||||
|
||||
|
||||
def _DuplicateName(values):
|
||||
"""Returns the 'mojom_name' of the first entry in |values| whose 'mojom_name'
|
||||
has already been encountered. If there are no duplicates, returns None."""
|
||||
@ -572,7 +565,7 @@ def _ResolveNumericEnumValues(enum):
|
||||
prev_value += 1
|
||||
|
||||
# Integral value (e.g: BEGIN = -0x1).
|
||||
elif _IsStrOrUnicode(field.value):
|
||||
elif isinstance(field.value, str):
|
||||
prev_value = int(field.value, 0)
|
||||
|
||||
# Reference to a previous enum value (e.g: INIT = BEGIN).
|
||||
|
@ -9,15 +9,6 @@
|
||||
# failures, especially for more complex types.
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def _IsStrOrUnicode(x):
|
||||
if sys.version_info[0] < 3:
|
||||
return isinstance(x, (unicode, str))
|
||||
return isinstance(x, str)
|
||||
|
||||
|
||||
class NodeBase(object):
|
||||
"""Base class for nodes in the AST."""
|
||||
|
||||
@ -96,7 +87,7 @@ class Definition(NodeBase):
|
||||
include parameter definitions.) This class is meant to be subclassed."""
|
||||
|
||||
def __init__(self, mojom_name, **kwargs):
|
||||
assert _IsStrOrUnicode(mojom_name)
|
||||
assert isinstance(mojom_name, str)
|
||||
NodeBase.__init__(self, **kwargs)
|
||||
self.mojom_name = mojom_name
|
||||
|
||||
@ -108,7 +99,7 @@ class Attribute(NodeBase):
|
||||
"""Represents an attribute."""
|
||||
|
||||
def __init__(self, key, value, **kwargs):
|
||||
assert _IsStrOrUnicode(key)
|
||||
assert isinstance(key, str)
|
||||
super(Attribute, self).__init__(**kwargs)
|
||||
self.key = key
|
||||
self.value = value
|
||||
@ -131,10 +122,10 @@ class Const(Definition):
|
||||
def __init__(self, mojom_name, attribute_list, typename, value, **kwargs):
|
||||
assert attribute_list is None or isinstance(attribute_list, AttributeList)
|
||||
# The typename is currently passed through as a string.
|
||||
assert _IsStrOrUnicode(typename)
|
||||
assert isinstance(typename, str)
|
||||
# The value is either a literal (currently passed through as a string) or a
|
||||
# "wrapped identifier".
|
||||
assert _IsStrOrUnicode or isinstance(value, tuple)
|
||||
assert isinstance(value, (tuple, str))
|
||||
super(Const, self).__init__(mojom_name, **kwargs)
|
||||
self.attribute_list = attribute_list
|
||||
self.typename = typename
|
||||
@ -170,7 +161,7 @@ class EnumValue(Definition):
|
||||
# The optional value is either an int (which is current a string) or a
|
||||
# "wrapped identifier".
|
||||
assert attribute_list is None or isinstance(attribute_list, AttributeList)
|
||||
assert value is None or _IsStrOrUnicode(value) or isinstance(value, tuple)
|
||||
assert value is None or isinstance(value, (tuple, str))
|
||||
super(EnumValue, self).__init__(mojom_name, **kwargs)
|
||||
self.attribute_list = attribute_list
|
||||
self.value = value
|
||||
@ -193,7 +184,7 @@ class Import(NodeBase):
|
||||
|
||||
def __init__(self, attribute_list, import_filename, **kwargs):
|
||||
assert attribute_list is None or isinstance(attribute_list, AttributeList)
|
||||
assert _IsStrOrUnicode(import_filename)
|
||||
assert isinstance(import_filename, str)
|
||||
super(Import, self).__init__(**kwargs)
|
||||
self.attribute_list = attribute_list
|
||||
self.import_filename = import_filename
|
||||
@ -314,10 +305,10 @@ class Parameter(NodeBase):
|
||||
"""Represents a method request or response parameter."""
|
||||
|
||||
def __init__(self, mojom_name, attribute_list, ordinal, typename, **kwargs):
|
||||
assert _IsStrOrUnicode(mojom_name)
|
||||
assert isinstance(mojom_name, str)
|
||||
assert attribute_list is None or isinstance(attribute_list, AttributeList)
|
||||
assert ordinal is None or isinstance(ordinal, Ordinal)
|
||||
assert _IsStrOrUnicode(typename)
|
||||
assert isinstance(typename, str)
|
||||
super(Parameter, self).__init__(**kwargs)
|
||||
self.mojom_name = mojom_name
|
||||
self.attribute_list = attribute_list
|
||||
@ -363,13 +354,13 @@ class StructField(Definition):
|
||||
|
||||
def __init__(self, mojom_name, attribute_list, ordinal, typename,
|
||||
default_value, **kwargs):
|
||||
assert _IsStrOrUnicode(mojom_name)
|
||||
assert isinstance(mojom_name, str)
|
||||
assert attribute_list is None or isinstance(attribute_list, AttributeList)
|
||||
assert ordinal is None or isinstance(ordinal, Ordinal)
|
||||
assert _IsStrOrUnicode(typename)
|
||||
assert isinstance(typename, str)
|
||||
# The optional default value is currently either a value as a string or a
|
||||
# "wrapped identifier".
|
||||
assert default_value is None or _IsStrOrUnicode(default_value) or \
|
||||
assert default_value is None or isinstance(default_value, str) or \
|
||||
isinstance(default_value, tuple)
|
||||
super(StructField, self).__init__(mojom_name, **kwargs)
|
||||
self.attribute_list = attribute_list
|
||||
@ -416,10 +407,10 @@ class Union(Definition):
|
||||
|
||||
class UnionField(Definition):
|
||||
def __init__(self, mojom_name, attribute_list, ordinal, typename, **kwargs):
|
||||
assert _IsStrOrUnicode(mojom_name)
|
||||
assert isinstance(mojom_name, str)
|
||||
assert attribute_list is None or isinstance(attribute_list, AttributeList)
|
||||
assert ordinal is None or isinstance(ordinal, Ordinal)
|
||||
assert _IsStrOrUnicode(typename)
|
||||
assert isinstance(typename, str)
|
||||
super(UnionField, self).__init__(mojom_name, **kwargs)
|
||||
self.attribute_list = attribute_list
|
||||
self.ordinal = ordinal
|
||||
|
@ -30,16 +30,12 @@ from mojom.parse import conditional_features
|
||||
|
||||
|
||||
# Disable this for easier debugging.
|
||||
# In Python 2, subprocesses just hang when exceptions are thrown :(.
|
||||
_ENABLE_MULTIPROCESSING = sys.version_info[0] > 2
|
||||
_ENABLE_MULTIPROCESSING = True
|
||||
|
||||
if sys.version_info < (3, 4):
|
||||
_MULTIPROCESSING_USES_FORK = sys.platform.startswith('linux')
|
||||
else:
|
||||
# https://docs.python.org/3/library/multiprocessing.html#:~:text=bpo-33725
|
||||
if __name__ == '__main__' and sys.platform == 'darwin':
|
||||
multiprocessing.set_start_method('fork')
|
||||
_MULTIPROCESSING_USES_FORK = multiprocessing.get_start_method() == 'fork'
|
||||
# https://docs.python.org/3/library/multiprocessing.html#:~:text=bpo-33725
|
||||
if __name__ == '__main__' and sys.platform == 'darwin':
|
||||
multiprocessing.set_start_method('fork')
|
||||
_MULTIPROCESSING_USES_FORK = multiprocessing.get_start_method() == 'fork'
|
||||
|
||||
|
||||
def _ResolveRelativeImportPath(path, roots):
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
Reference in New Issue
Block a user