mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Backed out changeset 54f82c735487 (bug 1613263) for causing diff artifact bustages in generated-files.diff.txt CLOSED TREE
This commit is contained in:
parent
5059d9b44d
commit
b1e3726298
@ -4,12 +4,7 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
import inspect
|
||||
import io
|
||||
import os
|
||||
from six import (
|
||||
BytesIO,
|
||||
StringIO,
|
||||
)
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import TextTestRunner as _TestRunner, TestResult as _TestResult
|
||||
@ -29,6 +24,8 @@ except ImportError:
|
||||
build = MozbuildObject.from_environment(cwd=here)
|
||||
topsrcdir = build.topsrcdir
|
||||
|
||||
StringIO = six.StringIO
|
||||
|
||||
'''Helper to make python unit tests report the way that the Mozilla
|
||||
unit test infrastructure expects tests to report.
|
||||
|
||||
@ -116,30 +113,21 @@ class MozTestRunner(_TestRunner):
|
||||
return result
|
||||
|
||||
|
||||
def _mocked_file(cls):
|
||||
'''Create a mocked file class that inherits from the given class.
|
||||
'''
|
||||
class MockedFile(cls):
|
||||
def __init__(self, context, filename, content):
|
||||
self.context = context
|
||||
self.name = filename
|
||||
cls.__init__(self, content)
|
||||
class MockedFile(StringIO):
|
||||
def __init__(self, context, filename, content=''):
|
||||
self.context = context
|
||||
self.name = filename
|
||||
StringIO.__init__(self, content)
|
||||
|
||||
def close(self):
|
||||
self.context.files[self.name] = self.getvalue()
|
||||
cls.close(self)
|
||||
def close(self):
|
||||
self.context.files[self.name] = self.getvalue()
|
||||
StringIO.close(self)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.close()
|
||||
|
||||
return MockedFile
|
||||
|
||||
|
||||
MockedStringFile = _mocked_file(StringIO)
|
||||
MockedBytesFile = _mocked_file(BytesIO)
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.close()
|
||||
|
||||
|
||||
def normcase(path):
|
||||
@ -154,60 +142,6 @@ def normcase(path):
|
||||
return path
|
||||
|
||||
|
||||
class _MockBaseOpen(object):
|
||||
'''Callable that acts like the open() function; see MockedOpen for more
|
||||
info.
|
||||
'''
|
||||
def __init__(self, open, files):
|
||||
self.open = open
|
||||
self.files = files
|
||||
|
||||
def __call__(self, name, mode='r', buffering=None, encoding=None):
|
||||
# open() can be called with an integer "name" (i.e. a file descriptor).
|
||||
# We don't generally do this in our codebase, but internal Python
|
||||
# libraries sometimes do and we want to handle that cleanly.
|
||||
if isinstance(name, int):
|
||||
return self.open(name, mode=mode, buffering=buffering,
|
||||
encoding=encoding)
|
||||
# buffering is ignored.
|
||||
absname = normcase(os.path.abspath(name))
|
||||
if 'w' in mode:
|
||||
file = self._mocked_file(absname, mode)
|
||||
elif absname in self.files:
|
||||
content = self.files[absname]
|
||||
if content is None:
|
||||
raise IOError(2, 'No such file or directory')
|
||||
file = self._mocked_file(absname, mode, content)
|
||||
elif 'a' in mode:
|
||||
read_mode = 'rb' if 'b' in mode else 'r'
|
||||
file = self._mocked_file(
|
||||
absname, mode, self.open(name, read_mode).read())
|
||||
else:
|
||||
file = self.open(name, mode)
|
||||
if 'a' in mode:
|
||||
file.seek(0, os.SEEK_END)
|
||||
return file
|
||||
|
||||
def _mocked_file(self, name, mode, content=None):
|
||||
raise NotImplementedError('subclass must implement')
|
||||
|
||||
|
||||
class _MockPy2Open(_MockBaseOpen):
|
||||
def _mocked_file(self, name, mode, content=None):
|
||||
content = six.ensure_binary(content or b'')
|
||||
return MockedBytesFile(self, name, content)
|
||||
|
||||
|
||||
class _MockOpen(_MockBaseOpen):
|
||||
def _mocked_file(self, name, mode, content=None):
|
||||
if 'b' in mode:
|
||||
content = six.ensure_binary(content or b'')
|
||||
return MockedBytesFile(self, name, content)
|
||||
else:
|
||||
content = six.ensure_text(content or u'')
|
||||
return MockedStringFile(self, name, content)
|
||||
|
||||
|
||||
class MockedOpen(object):
|
||||
'''
|
||||
Context manager diverting the open builtin such that opening files
|
||||
@ -236,16 +170,31 @@ class MockedOpen(object):
|
||||
for name, content in files.items():
|
||||
self.files[normcase(os.path.abspath(name))] = content
|
||||
|
||||
def __call__(self, name, mode='r', buffering=None, encoding=None):
|
||||
# buffering is ignored.
|
||||
absname = normcase(os.path.abspath(name))
|
||||
if 'w' in mode:
|
||||
file = MockedFile(self, absname)
|
||||
elif absname in self.files:
|
||||
content = self.files[absname]
|
||||
if content is None:
|
||||
raise IOError(2, 'No such file or directory')
|
||||
file = MockedFile(self, absname, content)
|
||||
elif 'a' in mode:
|
||||
file = MockedFile(self, absname, self.open(name, 'r').read())
|
||||
else:
|
||||
file = self.open(name, mode)
|
||||
if 'a' in mode:
|
||||
file.seek(0, os.SEEK_END)
|
||||
return file
|
||||
|
||||
def __enter__(self):
|
||||
import six.moves.builtins
|
||||
self.open = six.moves.builtins.open
|
||||
self.io_open = io.open
|
||||
self._orig_path_exists = os.path.exists
|
||||
self._orig_path_isdir = os.path.isdir
|
||||
self._orig_path_isfile = os.path.isfile
|
||||
builtin_cls = _MockPy2Open if six.PY2 else _MockOpen
|
||||
six.moves.builtins.open = builtin_cls(self.open, self.files)
|
||||
io.open = _MockOpen(self.io_open, self.files)
|
||||
six.moves.builtins.open = self
|
||||
os.path.exists = self._wrapped_exists
|
||||
os.path.isdir = self._wrapped_isdir
|
||||
os.path.isfile = self._wrapped_isfile
|
||||
@ -253,7 +202,6 @@ class MockedOpen(object):
|
||||
def __exit__(self, type, value, traceback):
|
||||
import six.moves.builtins
|
||||
six.moves.builtins.open = self.open
|
||||
io.open = self.io_open
|
||||
os.path.exists = self._orig_path_exists
|
||||
os.path.isdir = self._orig_path_isdir
|
||||
os.path.isfile = self._orig_path_isfile
|
||||
|
@ -10,17 +10,16 @@ See the documentation for jar.mn on MDC for further details on the format.
|
||||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import errno
|
||||
import io
|
||||
import logging
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import re
|
||||
import six
|
||||
from six import BytesIO
|
||||
import sys
|
||||
import logging
|
||||
from time import localtime
|
||||
|
||||
from MozZipFile import ZipFile
|
||||
from six import BytesIO
|
||||
|
||||
from mozbuild.preprocessor import Preprocessor
|
||||
from mozbuild.action.buildlist import addEntriesToListFile
|
||||
from mozbuild.util import ensure_bytes
|
||||
@ -468,8 +467,8 @@ class JarMaker(object):
|
||||
self._seen_output.add(out)
|
||||
|
||||
if e.preprocess:
|
||||
outf = outHelper.getOutput(out, mode='w')
|
||||
inf = io.open(realsrc, encoding='utf-8')
|
||||
outf = outHelper.getOutput(out)
|
||||
inf = open(realsrc)
|
||||
pp = self.pp.clone()
|
||||
if src[-4:] == '.css':
|
||||
pp.setMarker('%')
|
||||
@ -508,7 +507,7 @@ class JarMaker(object):
|
||||
except Exception:
|
||||
return localtime(0)
|
||||
|
||||
def getOutput(self, name, mode='wb'):
|
||||
def getOutput(self, name):
|
||||
return ZipEntry(name, self.jarfile)
|
||||
|
||||
class OutputHelper_flat(object):
|
||||
@ -523,7 +522,7 @@ class JarMaker(object):
|
||||
def getDestModTime(self, aPath):
|
||||
return getModTime(os.path.join(self.basepath, aPath))
|
||||
|
||||
def getOutput(self, name, mode='wb'):
|
||||
def getOutput(self, name):
|
||||
out = self.ensureDirFor(name)
|
||||
|
||||
# remove previous link or file
|
||||
@ -532,10 +531,7 @@ class JarMaker(object):
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
if 'b' in mode:
|
||||
return io.open(out, mode)
|
||||
else:
|
||||
return io.open(out, mode, encoding='utf-8', newline='\n')
|
||||
return open(out, 'wb')
|
||||
|
||||
def ensureDirFor(self, name):
|
||||
out = os.path.join(self.basepath, name)
|
||||
|
@ -24,14 +24,12 @@ value :
|
||||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import errno
|
||||
import io
|
||||
from optparse import OptionParser
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
import sys
|
||||
|
||||
from optparse import OptionParser
|
||||
import errno
|
||||
from mozbuild.makeutil import Makefile
|
||||
|
||||
# hack around win32 mangling our line endings
|
||||
@ -494,7 +492,7 @@ class Preprocessor:
|
||||
except OSError as error:
|
||||
if error.errno != errno.EEXIST:
|
||||
raise
|
||||
return io.open(path, 'w', encoding='utf-8')
|
||||
return open(path, 'wb')
|
||||
|
||||
p = self.getCommandLineParser()
|
||||
options, args = p.parse_args(args=args)
|
||||
@ -516,7 +514,7 @@ class Preprocessor:
|
||||
|
||||
if args:
|
||||
for f in args:
|
||||
with io.open(f, 'rU', encoding='utf-8') as input:
|
||||
with open(f, 'rU') as input:
|
||||
self.processFile(input=input, output=out)
|
||||
if depfile:
|
||||
mk = Makefile()
|
||||
@ -806,7 +804,7 @@ class Preprocessor:
|
||||
args = self.applyFilters(args)
|
||||
if not os.path.isabs(args):
|
||||
args = os.path.join(self.curdir, args)
|
||||
args = io.open(args, 'rU', encoding='utf-8')
|
||||
args = open(args, 'rU')
|
||||
except Preprocessor.Error:
|
||||
raise
|
||||
except Exception:
|
||||
@ -861,7 +859,7 @@ def preprocess(includes=[sys.stdin], defines={},
|
||||
pp = Preprocessor(defines=defines,
|
||||
marker=marker)
|
||||
for f in includes:
|
||||
with io.open(f, 'rU', encoding='utf-8') as input:
|
||||
with open(f, 'rU') as input:
|
||||
pp.processFile(input=input, output=output)
|
||||
return pp.includes
|
||||
|
||||
|
@ -151,8 +151,11 @@ class TestBuild(unittest.TestCase):
|
||||
test_path = os.sep.join(('$SRCDIR', 'python', 'mozbuild', 'mozbuild',
|
||||
'test', 'backend', 'data', 'build')) + os.sep
|
||||
|
||||
# We want unicode instances out of the files, because having plain str
|
||||
# makes assertEqual diff output in case of error extra verbose because
|
||||
# of the difference in type.
|
||||
result = {
|
||||
p: f.open(mode='r').read()
|
||||
p: f.open().read().decode('utf-8')
|
||||
for p, f in FileFinder(mozpath.join(config.topobjdir, 'dist'))
|
||||
}
|
||||
self.assertTrue(len(result))
|
||||
|
Loading…
Reference in New Issue
Block a user