mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-13 07:24:47 +00:00
Bug 1610944 - configure/test_toolchain_configure.py and configure/test_toolchain_helpers.py support Python 3 r=firefox-build-system-reviewers,mshal
Differential Revision: https://phabricator.services.mozilla.com/D60743 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
583661abdb
commit
3003ade6dd
@ -234,6 +234,7 @@ def rust_triple_alias(host_or_target, host_or_target_c_compiler):
|
||||
@imports('os')
|
||||
@imports(_from='mozbuild.configure.util', _import='LineIO')
|
||||
@imports(_from='mozbuild.shellutil', _import='quote')
|
||||
@imports(_from='six', _import='ensure_binary')
|
||||
@imports(_from='tempfile', _import='mkstemp')
|
||||
@imports(_from='textwrap', _import='dedent')
|
||||
def rust_target(rustc, host_or_target, compiler_info,
|
||||
@ -360,7 +361,7 @@ def rust_triple_alias(host_or_target, host_or_target_c_compiler):
|
||||
# Check to see whether our rustc has a reasonably functional stdlib
|
||||
# for our chosen target.
|
||||
target_arg = '--target=' + rustc_target
|
||||
in_fd, in_path = mkstemp(prefix='conftest', suffix='.rs')
|
||||
in_fd, in_path = mkstemp(prefix='conftest', suffix='.rs', text=True)
|
||||
out_fd, out_path = mkstemp(prefix='conftest', suffix='.rlib')
|
||||
os.close(out_fd)
|
||||
try:
|
||||
@ -369,7 +370,7 @@ def rust_triple_alias(host_or_target, host_or_target_c_compiler):
|
||||
with LineIO(lambda l: log.debug('| %s', l)) as out:
|
||||
out.write(source)
|
||||
|
||||
os.write(in_fd, source)
|
||||
os.write(in_fd, ensure_binary(source))
|
||||
os.close(in_fd)
|
||||
|
||||
cmd = [
|
||||
|
@ -381,6 +381,7 @@ def try_preprocess(compiler, language, source):
|
||||
_import='kernel_preprocessor_checks')
|
||||
@imports(_from='mozbuild.configure.constants',
|
||||
_import='OS_preprocessor_checks')
|
||||
@imports(_from='six', _import='iteritems')
|
||||
@imports(_from='textwrap', _import='dedent')
|
||||
@imports(_from='__builtin__', _import='Exception')
|
||||
def get_compiler_info(compiler, language):
|
||||
@ -430,7 +431,7 @@ def get_compiler_info(compiler, language):
|
||||
('KERNEL', kernel_preprocessor_checks),
|
||||
('OS', OS_preprocessor_checks),
|
||||
):
|
||||
for n, (value, condition) in enumerate(preprocessor_checks.iteritems()):
|
||||
for n, (value, condition) in enumerate(iteritems(preprocessor_checks)):
|
||||
check += dedent('''\
|
||||
#%(if)s %(condition)s
|
||||
%%%(name)s "%(value)s"
|
||||
@ -463,7 +464,7 @@ def get_compiler_info(compiler, language):
|
||||
# have non-ASCII characters. Treat the output as bytearray.
|
||||
data = {}
|
||||
for line in result.splitlines():
|
||||
if line.startswith(b'%'):
|
||||
if line.startswith('%'):
|
||||
k, _, v = line.partition(' ')
|
||||
k = k.lstrip('%')
|
||||
data[k] = v.replace(' ', '').lstrip('"').rstrip('"')
|
||||
|
@ -197,6 +197,7 @@ def find_program(file, paths=None):
|
||||
|
||||
@imports('os')
|
||||
@imports(_from='mozbuild.configure.util', _import='LineIO')
|
||||
@imports(_from='six', _import='ensure_binary')
|
||||
@imports(_from='tempfile', _import='mkstemp')
|
||||
def try_invoke_compiler(compiler, language, source, flags=None, onerror=None):
|
||||
flags = flags or []
|
||||
@ -210,7 +211,7 @@ def try_invoke_compiler(compiler, language, source, flags=None, onerror=None):
|
||||
'C++': '.cpp',
|
||||
}[language]
|
||||
|
||||
fd, path = mkstemp(prefix='conftest.', suffix=suffix)
|
||||
fd, path = mkstemp(prefix='conftest.', suffix=suffix, text=True)
|
||||
try:
|
||||
source = source.encode('ascii', 'replace')
|
||||
|
||||
@ -218,7 +219,7 @@ def try_invoke_compiler(compiler, language, source, flags=None, onerror=None):
|
||||
with LineIO(lambda l: log.debug('| %s', l)) as out:
|
||||
out.write(source)
|
||||
|
||||
os.write(fd, source)
|
||||
os.write(fd, ensure_binary(source))
|
||||
os.close(fd)
|
||||
cmd = compiler + list(flags) + [path]
|
||||
kwargs = {'onerror': onerror}
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import buildconfig
|
||||
from collections import defaultdict
|
||||
import os
|
||||
from six import StringIO
|
||||
import sys
|
||||
import yaml
|
||||
from collections import defaultdict
|
||||
from io import BytesIO
|
||||
from mozbuild.preprocessor import Preprocessor
|
||||
from mozbuild.util import ensureParentDir, FileAvoidWrite
|
||||
|
||||
@ -349,7 +349,7 @@ def emit_code(fd, pref_list_filename):
|
||||
if buildconfig.substs.get('MOZ_DEBUG'):
|
||||
pp.context['DEBUG'] = '1'
|
||||
|
||||
pp.out = BytesIO()
|
||||
pp.out = StringIO()
|
||||
pp.do_filter('substitution')
|
||||
pp.do_include(pref_list_filename)
|
||||
|
||||
|
@ -22,7 +22,7 @@ value :
|
||||
| \w+ # string identifier or value;
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import sys
|
||||
import os
|
||||
@ -628,7 +628,7 @@ class Preprocessor:
|
||||
except Exception:
|
||||
# XXX do real error reporting
|
||||
raise Preprocessor.Error(self, 'SYNTAX_ERR', args)
|
||||
if type(val) == str:
|
||||
if isinstance(val, six.text_type) or isinstance(val, six.binary_type):
|
||||
# we're looking for a number value, strings are false
|
||||
val = False
|
||||
if not val:
|
||||
@ -639,7 +639,6 @@ class Preprocessor:
|
||||
self.ifStates[-1] = self.disableLevel
|
||||
else:
|
||||
self.ifStates.append(self.disableLevel)
|
||||
pass
|
||||
|
||||
def do_ifdef(self, args, replace=False):
|
||||
if self.disableLevel and not replace:
|
||||
@ -655,7 +654,6 @@ class Preprocessor:
|
||||
self.ifStates[-1] = self.disableLevel
|
||||
else:
|
||||
self.ifStates.append(self.disableLevel)
|
||||
pass
|
||||
|
||||
def do_ifndef(self, args, replace=False):
|
||||
if self.disableLevel and not replace:
|
||||
@ -671,7 +669,6 @@ class Preprocessor:
|
||||
self.ifStates[-1] = self.disableLevel
|
||||
else:
|
||||
self.ifStates.append(self.disableLevel)
|
||||
pass
|
||||
|
||||
def do_else(self, args, ifState=2):
|
||||
self.ensure_not_else()
|
||||
@ -715,7 +712,7 @@ class Preprocessor:
|
||||
|
||||
def vsubst(v):
|
||||
if v in self.context:
|
||||
return str(self.context[v])
|
||||
return six.text_type(self.context[v])
|
||||
return ''
|
||||
for i in range(1, len(lst), 2):
|
||||
lst[i] = vsubst(lst[i])
|
||||
@ -770,7 +767,7 @@ class Preprocessor:
|
||||
def repl(matchobj):
|
||||
varname = matchobj.group('VAR')
|
||||
if varname in self.context:
|
||||
return str(self.context[varname])
|
||||
return six.text_type(self.context[varname])
|
||||
if fatal:
|
||||
raise Preprocessor.Error(self, 'UNDEFINED_VAR', varname)
|
||||
return matchobj.group(0)
|
||||
@ -793,7 +790,7 @@ class Preprocessor:
|
||||
self.checkLineNumbers = False
|
||||
if isName:
|
||||
try:
|
||||
args = str(args)
|
||||
args = six.text_type(args)
|
||||
if filters:
|
||||
args = self.applyFilters(args)
|
||||
if not os.path.isabs(args):
|
||||
@ -802,7 +799,7 @@ class Preprocessor:
|
||||
except Preprocessor.Error:
|
||||
raise
|
||||
except Exception:
|
||||
raise Preprocessor.Error(self, 'FILE_NOT_FOUND', str(args))
|
||||
raise Preprocessor.Error(self, 'FILE_NOT_FOUND', six.text_type(args))
|
||||
self.checkLineNumbers = bool(re.search('\.(js|jsm|java|webidl)(?:\.in)?$', args.name))
|
||||
oldFile = self.context['FILE']
|
||||
oldLine = self.context['LINE']
|
||||
@ -844,7 +841,7 @@ class Preprocessor:
|
||||
self.do_include(args)
|
||||
|
||||
def do_error(self, args):
|
||||
raise Preprocessor.Error(self, 'Error: ', str(args))
|
||||
raise Preprocessor.Error(self, 'Error: ', six.text_type(args))
|
||||
|
||||
|
||||
def preprocess(includes=[sys.stdin], defines={},
|
||||
|
@ -6,8 +6,8 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from StringIO import StringIO
|
||||
import six
|
||||
from six import StringIO
|
||||
|
||||
from mozunit import main
|
||||
|
||||
@ -222,18 +222,18 @@ def CLANGXX(version):
|
||||
CLANG_3_3 = CLANG('3.3.0') + DEFAULT_C99
|
||||
CLANGXX_3_3 = CLANGXX('3.3.0')
|
||||
CLANG_4_0 = CLANG('4.0.2') + DEFAULT_C11 + {
|
||||
'__has_attribute(diagnose_if)': '1',
|
||||
'__has_attribute(diagnose_if)': 1,
|
||||
}
|
||||
CLANGXX_4_0 = CLANGXX('4.0.2') + SUPPORTS_GNUXX1Z + {
|
||||
'__has_attribute(diagnose_if)': '1',
|
||||
'__has_attribute(diagnose_if)': 1,
|
||||
}
|
||||
CLANG_5_0 = CLANG('5.0.1') + DEFAULT_C11 + {
|
||||
'__has_attribute(diagnose_if)': '1',
|
||||
'__has_warning("-Wunguarded-availability")': '1',
|
||||
'__has_attribute(diagnose_if)': 1,
|
||||
'__has_warning("-Wunguarded-availability")': 1,
|
||||
}
|
||||
CLANGXX_5_0 = CLANGXX('5.0.1') + SUPPORTS_GNUXX17 + {
|
||||
'__has_attribute(diagnose_if)': '1',
|
||||
'__has_warning("-Wunguarded-availability")': '1',
|
||||
'__has_attribute(diagnose_if)': 1,
|
||||
'__has_warning("-Wunguarded-availability")': 1,
|
||||
}
|
||||
DEFAULT_CLANG = CLANG_5_0
|
||||
DEFAULT_CLANGXX = CLANGXX_5_0
|
||||
@ -415,6 +415,7 @@ class BaseToolchainTest(BaseConfigureTest):
|
||||
result = {}
|
||||
try:
|
||||
self.out.truncate(0)
|
||||
self.out.seek(0)
|
||||
compiler = sandbox._value_for(sandbox[var])
|
||||
# Add var on both ends to make it clear which of the
|
||||
# variables is failing the test when that happens.
|
||||
@ -667,7 +668,7 @@ class LinuxToolchainTest(BaseToolchainTest):
|
||||
# We'll try gcc and clang, but since there is no gcc (gcc-x.y doesn't
|
||||
# count), find clang.
|
||||
paths = {
|
||||
k: v for k, v in self.PATHS.iteritems()
|
||||
k: v for k, v in six.iteritems(self.PATHS)
|
||||
if os.path.basename(k) not in ('gcc', 'g++')
|
||||
}
|
||||
self.do_toolchain_test(paths, {
|
||||
@ -704,7 +705,7 @@ class LinuxToolchainTest(BaseToolchainTest):
|
||||
# Even if there are gcc-x.y or clang-x.y compilers available, we
|
||||
# don't try them. This could be considered something to improve.
|
||||
paths = {
|
||||
k: v for k, v in self.PATHS.iteritems()
|
||||
k: v for k, v in six.iteritems(self.PATHS)
|
||||
if os.path.basename(k) not in ('gcc', 'g++', 'clang', 'clang++')
|
||||
}
|
||||
self.do_toolchain_test(paths, {
|
||||
@ -909,7 +910,7 @@ class OSXToolchainTest(BaseToolchainTest):
|
||||
def test_not_gcc(self):
|
||||
# We won't pick GCC if it's the only thing available.
|
||||
paths = {
|
||||
k: v for k, v in self.PATHS.iteritems()
|
||||
k: v for k, v in six.iteritems(self.PATHS)
|
||||
if os.path.basename(k) not in ('clang', 'clang++')
|
||||
}
|
||||
self.do_toolchain_test(paths, {
|
||||
@ -1037,7 +1038,7 @@ class WindowsToolchainTest(BaseToolchainTest):
|
||||
def test_gcc(self):
|
||||
# We'll pick GCC if msvc and clang-cl can't be found.
|
||||
paths = {
|
||||
k: v for k, v in self.PATHS.iteritems()
|
||||
k: v for k, v in six.iteritems(self.PATHS)
|
||||
if os.path.basename(k) not in ('cl', 'clang-cl')
|
||||
}
|
||||
self.do_toolchain_test(paths, {
|
||||
@ -1056,7 +1057,7 @@ class WindowsToolchainTest(BaseToolchainTest):
|
||||
def test_clang(self):
|
||||
# We'll pick clang if nothing else is found.
|
||||
paths = {
|
||||
k: v for k, v in self.PATHS.iteritems()
|
||||
k: v for k, v in six.iteritems(self.PATHS)
|
||||
if os.path.basename(k) not in ('cl', 'clang-cl', 'gcc')
|
||||
}
|
||||
self.do_toolchain_test(paths, {
|
||||
|
@ -74,7 +74,7 @@ class CompilerPreprocessor(Preprocessor):
|
||||
def repl(matchobj):
|
||||
varname = matchobj.group('VAR')
|
||||
if varname in self.context:
|
||||
result = str(self.context[varname])
|
||||
result = six.text_type(self.context[varname])
|
||||
# The C preprocessor inserts whitespaces around expanded
|
||||
# symbols.
|
||||
start, end = matchobj.span('VAR')
|
||||
@ -104,8 +104,8 @@ class TestCompilerPreprocessor(unittest.TestCase):
|
||||
|
||||
def test_normalization(self):
|
||||
pp = CompilerPreprocessor({
|
||||
'__has_attribute(bar)': '1',
|
||||
'__has_warning("-Wc++98-foo")': '1',
|
||||
'__has_attribute(bar)': 1,
|
||||
'__has_warning("-Wc++98-foo")': 1,
|
||||
})
|
||||
pp.out = StringIO()
|
||||
input = StringIO(dedent('''\
|
||||
@ -161,7 +161,7 @@ class TestCompilerPreprocessor(unittest.TestCase):
|
||||
input.name = 'foo'
|
||||
pp.do_include(input)
|
||||
|
||||
self.assertEquals('IFDEF_A\nIF_A\nIF_B\nIF_NOT_C\n', pp.out.getvalue())
|
||||
self.assertEquals('IFDEF_A\nIF_A\nIF_NOT_B\nIF_NOT_C\n', pp.out.getvalue())
|
||||
|
||||
|
||||
class FakeCompiler(dict):
|
||||
|
@ -6,6 +6,8 @@ subsuite = mozbuild
|
||||
[configure/test_configure.py]
|
||||
[configure/test_moz_configure.py]
|
||||
[configure/test_options.py]
|
||||
[configure/test_toolchain_configure.py]
|
||||
[configure/test_toolchain_helpers.py]
|
||||
[configure/test_util.py]
|
||||
[controller/test_ccachestats.py]
|
||||
[controller/test_clobber.py]
|
||||
|
@ -20,8 +20,6 @@ skip-if = (os == "win")
|
||||
[compilation/test_warnings.py]
|
||||
[configure/lint.py]
|
||||
[configure/test_lint.py]
|
||||
[configure/test_toolchain_configure.py]
|
||||
[configure/test_toolchain_helpers.py]
|
||||
[configure/test_toolkit_moz_configure.py]
|
||||
[frontend/test_context.py]
|
||||
[frontend/test_emitter.py]
|
||||
|
Loading…
x
Reference in New Issue
Block a user