Skip to content

Commit d990224

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 b664506 commit d990224

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):

ipc/ipdl/test/cxx/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include $(topsrcdir)/config/rules.mk
2020
IPDLUNITTEST_BIN = $(DEPTH)/dist/bin/ipdlunittest$(BIN_SUFFIX)
2121

2222
IPDLUnitTests.cpp : Makefile.in moz.build $(GENTESTER) $(TESTER_TEMPLATE) $(IPDLTESTHDRS)
23-
$(PYTHON) $(GENTESTER) $(TESTER_TEMPLATE) -t $(IPDLTESTS) -e $(EXTRA_PROTOCOLS) > $@
23+
$(PYTHON3) $(GENTESTER) $(TESTER_TEMPLATE) -t $(IPDLTESTS) -e $(EXTRA_PROTOCOLS) > $@
2424

2525
check-proc::
2626
@$(EXIT_ON_ERROR) \

ipc/ipdl/test/cxx/genIPDLUnitTests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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 print_function
5+
from __future__ import print_function, unicode_literals
66

77
import string
88
import sys
@@ -124,7 +124,7 @@ def main(argv):
124124
}
125125
''' % (t, t, t, t) for t in unittests+extras])
126126

127-
templatefile = open(template, 'r')
127+
templatefile = open(template, 'r', encoding='utf-8')
128128
sys.stdout.write(
129129
string.Template(templatefile.read()).substitute(
130130
INCLUDES=includes,

ipc/ipdl/test/ipdl/IPDLCompile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def run(self):
2828
self.specfilename
2929
])
3030

31-
proc = subprocess.Popen(args=self.argv,
32-
stdout=subprocess.PIPE,
33-
stderr=subprocess.PIPE)
31+
proc = subprocess.Popen(
32+
args=self.argv, stdout=subprocess.PIPE,
33+
stderr=subprocess.PIPE, universal_newlines=True)
3434
self.stdout, self.stderr = proc.communicate()
3535

3636
self.returncode = proc.returncode

ipc/ipdl/test/ipdl/Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ OKTESTS := $(wildcard $(srcdir)/ok/*.ipdl) $(wildcard $(srcdir)/ok/*.ipdlh)
88
ERRORTESTS := $(wildcard $(srcdir)/error/*.ipdl) $(wildcard $(srcdir)/error/*.ipdlh)
99

1010
check::
11-
@$(PYTHON) $(srcdir)/runtests.py \
11+
@$(PYTHON3) $(srcdir)/runtests.py \
1212
$(srcdir)/ok $(srcdir)/error \
13-
$(PYTHON) $(topsrcdir)/config/pythonpath.py \
13+
$(PYTHON3) $(topsrcdir)/config/pythonpath.py \
1414
$(PLY_INCLUDE) \
1515
$(topsrcdir)/ipc/ipdl/ipdl.py \
1616
--sync-msg-list=$(srcdir)/sync-messages.ini \

ipc/ipdl/test/ipdl/error/BadNestedManagee.ipdl

Lines changed: 0 additions & 9 deletions
This file was deleted.

ipc/ipdl/test/ipdl/error/BadNestedManager.ipdl

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//error: protocol `PBadNestedManagee' requires more powerful send semantics than its manager `PBadNestedManager' provides
2+
3+
include protocol PBadNestedManager;
4+
5+
nested(upto inside_sync) async protocol PBadNestedManagee {
6+
manager PBadNestedManager;
7+
child:
8+
async __delete__();
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//error: protocol `PBadNestedManagee' requires more powerful send semantics than its manager `PBadNestedManager' provides
2+
3+
include protocol PBadNestedManagee;
4+
5+
nested(upto not) async protocol PBadNestedManager {
6+
manages PBadNestedManagee;
7+
parent:
8+
async PBadNestedManagee();
9+
};

js/src/Makefile.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ endif
4040
endif
4141

4242
check-js-msg::
43-
(cd $(topsrcdir) && $(PYTHON) $(topsrcdir)/config/check_js_msg_encoding.py);
43+
(cd $(topsrcdir) && $(PYTHON3) $(topsrcdir)/config/check_js_msg_encoding.py);
4444

4545
check-jit-test::
46-
$(JITTEST_SANITIZER_ENV) $(wildcard $(RUN_TEST_PROGRAM)) $(PYTHON) -u $(srcdir)/jit-test/jit_test.py \
46+
$(JITTEST_SANITIZER_ENV) $(wildcard $(RUN_TEST_PROGRAM)) $(PYTHON3) -u $(srcdir)/jit-test/jit_test.py \
4747
--no-slow --no-progress --format=automation --jitflags=all \
4848
$(JITTEST_VALGRIND_FLAG) \
4949
$(JITTEST_EXTRA_ARGS) \
@@ -52,7 +52,7 @@ check-jit-test::
5252
check:: check-js-msg
5353

5454
check-jstests:
55-
$(wildcard $(RUN_TEST_PROGRAM)) $(PYTHON) -u $(srcdir)/tests/jstests.py \
55+
$(wildcard $(RUN_TEST_PROGRAM)) $(PYTHON3) -u $(srcdir)/tests/jstests.py \
5656
--no-progress --format=automation --timeout 300 \
5757
$(JSTESTS_EXTRA_ARGS) \
5858
$(DIST)/bin/$(JS_SHELL_NAME)$(BIN_SUFFIX)

js/src/build/Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ include $(topsrcdir)/config/rules.mk
99
# check_vanilla_allocations.py is tailored to Linux, so only run it there.
1010
# That should be enough to catch any problems.
1111
check-vanilla-allocations:
12-
$(PYTHON) $(topsrcdir)/config/check_vanilla_allocations.py $(REAL_LIBRARY)
12+
$(PYTHON3) $(topsrcdir)/config/check_vanilla_allocations.py $(REAL_LIBRARY)
1313

1414
# The "aggressive" variant will likely fail on some compiler/platform
1515
# combinations, but is worth running by hand every once in a while.
1616
check-vanilla-allocations-aggressive:
17-
$(PYTHON) $(topsrcdir)/config/check_vanilla_allocations.py --aggressive $(REAL_LIBRARY)
17+
$(PYTHON3) $(topsrcdir)/config/check_vanilla_allocations.py --aggressive $(REAL_LIBRARY)
1818

1919
ifeq ($(OS_ARCH),Linux)
2020
ifeq (,$(filter -flto,$(COMPUTED_CFLAGS) $(COMPUTED_CXXFLAGS) $(COMPUTED_LDFLAGS)))

js/src/tests/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ PKG_STAGE = $(DIST)/test-stage
2424
stage-package:
2525
$(NSINSTALL) -D $(PKG_STAGE)/jsreftest/tests/js/src/tests
2626
(cd $(srcdir) && tar $(TAR_CREATE_FLAGS) - $(TEST_FILES)) | (cd $(PKG_STAGE)/jsreftest/tests/js/src/tests && tar -xf -)
27-
$(PYTHON) $(srcdir)/jstests.py --make-manifests $(PKG_STAGE)/jsreftest/tests/js/src/tests
27+
$(PYTHON3) $(srcdir)/jstests.py --make-manifests $(PKG_STAGE)/jsreftest/tests/js/src/tests

js/src/tests/lib/manifest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import print_function
66

7+
import io
78
import os
89
import posixpath
910
import re
@@ -71,7 +72,7 @@ def create(cls, jsdir):
7172
# Read the values.
7273
val_re = re.compile(r'(TARGET_XPCOM_ABI|OS_TARGET|MOZ_DEBUG)\s*=\s*(.*)')
7374
kw = {'isdebug': False}
74-
for line in open(path):
75+
for line in io.open(path, encoding='utf-8'):
7576
m = val_re.match(line)
7677
if m:
7778
key, val = m.groups()
@@ -338,7 +339,7 @@ def _emit_manifest_at(location, relative, test_gen, depth):
338339
manifest = ["url-prefix {}jsreftest.html?test={}/".format(
339340
'../' * depth, relative)] + manifest
340341

341-
fp = open(filename, 'w')
342+
fp = io.open(filename, 'w', encoding='utf-8', newline='\n')
342343
try:
343344
fp.write('\n'.join(manifest) + '\n')
344345
finally:
@@ -378,7 +379,7 @@ def _parse_test_header(fullpath, testcase, xul_tester):
378379
This looks a bit weird. The reason is that it needs to be efficient, since
379380
it has to be done on every test
380381
"""
381-
fp = open(fullpath, 'r')
382+
fp = io.open(fullpath, 'r', encoding='utf-8')
382383
try:
383384
buf = fp.read(512)
384385
finally:
@@ -415,7 +416,7 @@ def _parse_external_manifest(filename, relpath):
415416

416417
entries = []
417418

418-
with open(filename, 'r') as fp:
419+
with io.open(filename, 'r', encoding='utf-8') as fp:
419420
manifest_re = re.compile(r'^\s*(?P<terms>.*)\s+(?P<type>include|script)\s+(?P<path>\S+)$')
420421
include_re = re.compile(r'^\s*include\s+(?P<path>\S+)$')
421422
for line in fp:

0 commit comments

Comments
 (0)