Skip to content

Commit 3749c34

Browse files
author
Ricky Stewart
committed
Bug 1632916 - Run JS/web-platform/ipdl build machinery in Python 3 r=jgraham,nika,glandium
Differential Revision: https://phabricator.services.mozilla.com/D72478
1 parent 2826536 commit 3749c34

File tree

35 files changed

+117
-91
lines changed

35 files changed

+117
-91
lines changed

config/check_vanilla_allocations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
# mismatched alloc/free checking.
3939
# ----------------------------------------------------------------------------
4040

41-
from __future__ import absolute_import
42-
from __future__ import print_function
41+
from __future__ import absolute_import, print_function, unicode_literals
4342

4443
import argparse
4544
import re
@@ -112,7 +111,7 @@ def main():
112111
]
113112

114113
# This is like alloc_fns, but regexp chars are not escaped.
115-
alloc_fns_unescaped = [fn.translate(None, r'\\') for fn in alloc_fns]
114+
alloc_fns_unescaped = [fn.replace('\\', '') for fn in alloc_fns]
116115

117116
# This regexp matches the relevant lines in the output of |nm|, which look
118117
# like the following.

config/config.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ MKDIR ?= mkdir
112112
SLEEP ?= sleep
113113
TOUCH ?= touch
114114

115-
PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py
115+
PYTHON_PATH = $(PYTHON3) $(topsrcdir)/config/pythonpath.py
116116

117117
#
118118
# Build using PIC by default

config/pythonpath.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
from __future__ import absolute_import
6-
from __future__ import print_function
5+
from __future__ import absolute_import, print_function, unicode_literals
6+
7+
78
"""
89
Run a python script, adding extra directories to the python path.
910
"""
1011

1112

1213
def main(args):
1314
def usage():
14-
print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
15+
print("pythonpath.py -I directory script.py [args...]", file=sys.stderr)
1516
sys.exit(150)
1617

1718
paths = []
@@ -47,14 +48,14 @@ def usage():
4748
frozenglobals['__name__'] = '__main__'
4849
frozenglobals['__file__'] = script
4950

50-
execfile(script, frozenglobals)
51+
exec(open(script, encoding='utf-8').read(), frozenglobals)
5152

5253

5354
# Freeze scope here ... why this makes things work I have no idea ...
5455
frozenglobals = globals()
5556

56-
import sys
5757
import os
58+
import sys
5859

5960
if __name__ == '__main__':
6061
main(sys.argv[1:])

ipc/ipdl/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ipdl_py_deps := \
2222
# NB: the IPDL compiler manages .ipdl-->.h/.cpp dependencies itself,
2323
# which is why we don't have explicit .h/.cpp targets here
2424
ipdl.track: $(ALL_IPDLSRCS) $(srcdir)/sync-messages.ini $(srcdir)/message-metadata.ini $(ipdl_py_deps)
25-
$(PYTHON) $(topsrcdir)/config/pythonpath.py \
25+
$(PYTHON3) $(topsrcdir)/config/pythonpath.py \
2626
$(PLY_INCLUDE) \
2727
$(srcdir)/ipdl.py \
2828
--sync-msg-list=$(srcdir)/sync-messages.ini \

ipc/ipdl/ipdl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
from __future__ import print_function
55

6+
from io import StringIO
67
import optparse
78
import os
89
import sys
9-
from cStringIO import StringIO
10-
from ConfigParser import RawConfigParser
10+
from configparser import RawConfigParser
1111

1212
import ipdl
1313

ipc/ipdl/ipdl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import os
1111
import sys
12-
from cStringIO import StringIO
12+
from io import StringIO
1313

1414
from ipdl.cgen import IPDLCodeGen
1515
from ipdl.lower import LowerToCxx, msgenums
@@ -75,6 +75,7 @@ def genmsgenum(ast):
7575

7676

7777
def writeifmodified(contents, file):
78+
contents = contents.encode('utf-8')
7879
dir = os.path.dirname(file)
7980
os.path.exists(dir) or os.makedirs(dir)
8081

ipc/ipdl/ipdl/cxx/ast.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
import copy
6+
import functools
67

78

89
class Visitor:
@@ -442,6 +443,7 @@ def __init__(self, params=[], ret=Type('void')):
442443
self.ret = ret
443444

444445

446+
@functools.total_ordering
445447
class Typedef(Node):
446448
def __init__(self, fromtype, totypename, templateargs=[]):
447449
assert isinstance(totypename, str)
@@ -451,12 +453,12 @@ def __init__(self, fromtype, totypename, templateargs=[]):
451453
self.totypename = totypename
452454
self.templateargs = templateargs
453455

454-
def __cmp__(self, o):
455-
return cmp(self.totypename, o.totypename)
456+
def __lt__(self, other):
457+
return self.totypename < other.totypename
456458

457-
def __eq__(self, o):
458-
return (self.__class__ == o.__class__
459-
and 0 == cmp(self, o))
459+
def __eq__(self, other):
460+
return (self.__class__ == other.__class__
461+
and self.totypename == other.totypename)
460462

461463
def __hash__(self):
462464
return hash(self.totypename)

ipc/ipdl/ipdl/cxx/code.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# API are often easier to read than users of the AST APIs in these cases.
1212

1313
import re
14-
import sys
1514
import math
1615
import textwrap
1716

@@ -140,7 +139,7 @@ def _line(raw, skip_indent, lineno, context):
140139
values = eval(expr, context, {})
141140
except Exception as e:
142141
msg = "%s in substitution on line %d" % (repr(e), lineno)
143-
raise ValueError(msg), None, sys.exc_traceback
142+
raise ValueError(msg) from e
144143

145144
# If we aren't dealing with lists, wrap the result into a
146145
# single-element list.

ipc/ipdl/ipdl/lower.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ def visitStructDecl(self, sd):
14501450

14511451
# Compute a permutation of the fields for in-memory storage such
14521452
# that the memory layout of the structure will be well-packed.
1453-
permutation = range(len(newfields))
1453+
permutation = list(range(len(newfields)))
14541454

14551455
# Note that the results of `pod_size` ensure that non-POD fields
14561456
# sort before POD ones.

ipc/ipdl/ipdl/type.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ def typename(self):
125125
return self.__class__.__name__
126126

127127
def name(self):
128-
raise NotImplementedError
128+
raise NotImplementedError()
129129

130130
def fullname(self):
131-
raise NotImplementedError
131+
raise NotImplementedError()
132132

133133
def accept(self, visitor, *args):
134134
visit = getattr(visitor, 'visit' + self.__class__.__name__, None)
@@ -229,8 +229,18 @@ def hasBaseType(self): return False
229229

230230
@classmethod
231231
def convertsTo(cls, lesser, greater):
232-
if (lesser.nestedRange[0] < greater.nestedRange[0] or
233-
lesser.nestedRange[1] > greater.nestedRange[1]):
232+
def _unwrap(nr):
233+
if isinstance(nr, dict):
234+
return _unwrap(nr['nested'])
235+
elif isinstance(nr, int):
236+
return nr
237+
else:
238+
raise ValueError('Got unexpected nestedRange value: %s' % nr)
239+
240+
lnr0, gnr0, lnr1, gnr1 = (
241+
_unwrap(lesser.nestedRange[0]), _unwrap(greater.nestedRange[0]),
242+
_unwrap(lesser.nestedRange[1]), _unwrap(greater.nestedRange[1]))
243+
if (lnr0 < gnr0 or lnr1 > gnr1):
234244
return False
235245

236246
# Protocols that use intr semantics are not allowed to use
@@ -593,7 +603,7 @@ def iteractortypes(t, visited=None):
593603

594604
def hasshmem(type):
595605
"""Return true iff |type| is shmem or has it buried within."""
596-
class found:
606+
class found(BaseException):
597607
pass
598608

599609
class findShmem(TypeVisitor):

0 commit comments

Comments
 (0)