Bug 1542963 - Insert unicode_literals into python/mozbuild/mozpack and called mozbuild/* files. r=firefox-build-system-reviewers,chmanchester

Lint python/mozbuild/{mozbuild,mozpack}.

This makes sure we use byte strings (type(b'')) in many places.
This also has a few places where we know we want unicode, by enforcing it.

This code also has a few places where we call into windows API's which expect either all args to be unicode,
or all args to be bytestrings (not-unicode) so make sure those calls align.

This is the most risky of the stack, since there are some mach commands and codepaths that are neither excercised in automation
nor excercised in tests.

Differential Revision: https://phabricator.services.mozilla.com/D26645

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Justin Wood 2019-05-28 14:23:25 +00:00
Родитель 8127e912fb
Коммит 80df2896d2
31 изменённых файлов: 293 добавлений и 259 удалений

Просмотреть файл

@ -21,6 +21,7 @@ from cStringIO import StringIO
from mozbuild.preprocessor import Preprocessor
from mozbuild.action.buildlist import addEntriesToListFile
from mozbuild.util import ensure_bytes
from mozpack.files import FileFinder
import mozpack.path as mozpath
if sys.platform == 'win32':
@ -560,7 +561,7 @@ class JarMaker(object):
os.symlink(src, out)
else:
# On Win32, use ctypes to create a hardlink
rv = CreateHardLink(out, src, None)
rv = CreateHardLink(ensure_bytes(out), ensure_bytes(src), None)
if rv == 0:
raise WinError()

Просмотреть файл

@ -13,7 +13,10 @@ import tarfile
import subprocess
import mozpack.path as mozpath
from mozbuild.repackaging.application_ini import get_application_ini_value
from mozbuild.util import ensureParentDir
from mozbuild.util import (
ensureParentDir,
ensure_bytes,
)
_BCJ_OPTIONS = {
@ -75,6 +78,8 @@ def repackage_mar(topsrcdir, package, mar, output, mar_format='lzma', arch=None)
# make_full_update.sh is a bash script, and Windows needs to
# explicitly call out the shell to execute the script from Python.
cmd.insert(0, env['MOZILLABUILD'] + '/msys/bin/bash.exe')
# in py2 env needs str not unicode.
env = {ensure_bytes(k): ensure_bytes(v) for k, v in env.iteritems()}
subprocess.check_call(cmd, env=env)
finally:

Просмотреть файл

@ -1393,3 +1393,15 @@ def patch_main():
return cmdline
orig_command_line = forking.get_command_line
forking.get_command_line = my_get_command_line
def ensure_bytes(value):
if isinstance(value, basestring):
return value.encode('utf8')
return value
def ensure_unicode(value):
if isinstance(value, type(b'')):
return value.decode('utf8')
return value

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import bz2
import gzip

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import re
from distutils.version import LooseVersion

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import re
import os

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
import stat

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import buildconfig
import errno

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import sys
from contextlib import contextmanager

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
import struct

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import errno
import inspect
@ -15,7 +15,11 @@ import uuid
import mozbuild.makeutil as makeutil
from itertools import chain
from mozbuild.preprocessor import Preprocessor
from mozbuild.util import FileAvoidWrite
from mozbuild.util import (
FileAvoidWrite,
ensure_bytes,
ensure_unicode,
)
from mozpack.executables import (
is_executable,
may_strip,
@ -83,7 +87,7 @@ class Dest(object):
'''
def __init__(self, path):
self.path = path
self.path = ensure_unicode(path)
self.mode = None
@property
@ -193,12 +197,12 @@ class BaseFile(object):
else:
# Ensure the file is always created
if not dest.exists():
dest.write('')
dest.write(b'')
shutil.copyfileobj(self.open(), dest)
return True
src = self.open()
copy_content = ''
copy_content = b''
while True:
dest_content = dest.read(32768)
src_content = src.read(32768)
@ -255,7 +259,7 @@ class File(BaseFile):
'''
def __init__(self, path):
self.path = path
self.path = ensure_unicode(path)
@property
def mode(self):
@ -512,8 +516,8 @@ class PreprocessedFile(BaseFile):
def __init__(self, path, depfile_path, marker, defines, extra_depends=None,
silence_missing_directive_warnings=False):
self.path = path
self.depfile = depfile_path
self.path = ensure_unicode(path)
self.depfile = ensure_unicode(depfile_path)
self.marker = marker
self.defines = defines
self.extra_depends = list(extra_depends or [])
@ -706,9 +710,12 @@ class ManifestFile(BaseFile):
Return a file-like object allowing to read() the serialized content of
the manifest.
'''
return BytesIO(''.join('%s\n' % e.rebase(self._base)
for e in chain(self._entries,
self._interfaces)))
return BytesIO(
ensure_bytes(
''.join(
'%s\n' % e.rebase(self._base)
for e in chain(self._entries, self._interfaces)
)))
def __iter__(self):
'''
@ -738,8 +745,8 @@ class MinifiedProperties(BaseFile):
Return a file-like object allowing to read() the minified content of
the properties file.
'''
return BytesIO(''.join(l for l in self._file.open().readlines()
if not l.startswith('#')))
return BytesIO(b''.join(l for l in self._file.open().readlines()
if not l.startswith(b'#')))
class MinifiedJavaScript(BaseFile):

Просмотреть файл

@ -27,7 +27,7 @@
# do not wish to do so, delete this exception statement from your
# version.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import mercurial.error as error
import mercurial.hg as hg

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from io import BytesIO
import struct
@ -15,7 +15,10 @@ from zipfile import (
)
from collections import OrderedDict
import mozpack.path as mozpath
from mozbuild.util import memoize
from mozbuild.util import (
memoize,
ensure_bytes,
)
JAR_STORED = ZIP_STORED
@ -129,14 +132,14 @@ class JarStruct(object):
data = data[:size]
if isinstance(data, memoryview):
data = data.tobytes()
return struct.unpack('<' + format, data)[0], size
return struct.unpack(b'<' + format, data)[0], size
def serialize(self):
'''
Serialize the data structure according to the data structure definition
from self.STRUCT.
'''
serialized = struct.pack('<I', self.signature)
serialized = struct.pack(b'<I', self.signature)
sizes = dict((t, name) for name, t in self.STRUCT.iteritems()
if t not in JarStruct.TYPE_MAPPING)
for name, t in self.STRUCT.iteritems():
@ -146,9 +149,9 @@ class JarStruct(object):
value = len(self[sizes[name]])
else:
value = self[name]
serialized += struct.pack('<' + format, value)
serialized += struct.pack(b'<' + format, value)
else:
serialized += self[name]
serialized += ensure_bytes(self[name])
return serialized
@property

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozbuild.preprocessor import Preprocessor
import re

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozpack.chrome.manifest import (
Manifest,

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
'''
Replace localized parts of a packaged directory with data from a langpack

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import mozpack.path as mozpath
from mozpack.files import (
@ -158,8 +158,8 @@ class UnpackFinder(BaseFinder):
Return whether the given BaseFile looks like a ZIP/Jar.
'''
header = file.open().read(8)
return len(header) == 8 and (header[0:2] == 'PK' or
header[4:6] == 'PK')
return len(header) == 8 and (header[0:2] == b'PK' or
header[4:6] == b'PK')
def _unjarize(self, entry, relpath):
'''

Просмотреть файл

@ -8,7 +8,7 @@ separators (always use forward slashes).
Also contains a few additional utilities not found in :py:mod:`os.path`.
'''
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import ctypes
import posixpath

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import sys

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import hashlib
import os

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import unittest
import mozunit

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import unittest
import mozunit

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozpack.copier import (
FileCopier,
@ -42,21 +42,21 @@ class BaseTestFileRegistry(MatchTestTemplate):
def do_test_file_registry(self, registry):
self.registry = registry
self.registry.add('foo', GeneratedFile('foo'))
bar = GeneratedFile('bar')
self.registry.add('foo', GeneratedFile(b'foo'))
bar = GeneratedFile(b'bar')
self.registry.add('bar', bar)
self.assertEqual(self.registry.paths(), ['foo', 'bar'])
self.assertEqual(self.registry['bar'], bar)
self.assertRaises(ErrorMessage, self.registry.add, 'foo',
GeneratedFile('foo2'))
GeneratedFile(b'foo2'))
self.assertRaises(ErrorMessage, self.registry.remove, 'qux')
self.assertRaises(ErrorMessage, self.registry.add, 'foo/bar',
GeneratedFile('foobar'))
GeneratedFile(b'foobar'))
self.assertRaises(ErrorMessage, self.registry.add, 'foo/bar/baz',
GeneratedFile('foobar'))
GeneratedFile(b'foobar'))
self.assertEqual(self.registry.paths(), ['foo', 'bar'])
@ -81,7 +81,7 @@ class BaseTestFileRegistry(MatchTestTemplate):
self.registry.remove('foo/qux')
self.assertEqual(self.registry.paths(), ['bar', 'foo/bar', 'foo/baz'])
self.registry.add('foo/qux', GeneratedFile('fooqux'))
self.registry.add('foo/qux', GeneratedFile(b'fooqux'))
self.assertEqual(self.registry.paths(), ['bar', 'foo/bar', 'foo/baz',
'foo/qux'])
self.registry.remove('foo/b*')
@ -98,28 +98,28 @@ class BaseTestFileRegistry(MatchTestTemplate):
# Can't add a file if it requires a directory in place of a
# file we also require.
self.registry.add('foo', GeneratedFile('foo'))
self.registry.add('foo', GeneratedFile(b'foo'))
self.assertRaises(ErrorMessage, self.registry.add, 'foo/bar',
GeneratedFile('foobar'))
GeneratedFile(b'foobar'))
# Can't add a file if we already have a directory there.
self.registry.add('bar/baz', GeneratedFile('barbaz'))
self.registry.add('bar/baz', GeneratedFile(b'barbaz'))
self.assertRaises(ErrorMessage, self.registry.add, 'bar',
GeneratedFile('bar'))
GeneratedFile(b'bar'))
# Bump the count of things that require bar/ to 2.
self.registry.add('bar/zot', GeneratedFile('barzot'))
self.registry.add('bar/zot', GeneratedFile(b'barzot'))
self.assertRaises(ErrorMessage, self.registry.add, 'bar',
GeneratedFile('bar'))
GeneratedFile(b'bar'))
# Drop the count of things that require bar/ to 1.
self.registry.remove('bar/baz')
self.assertRaises(ErrorMessage, self.registry.add, 'bar',
GeneratedFile('bar'))
GeneratedFile(b'bar'))
# Drop the count of things that require bar/ to 0.
self.registry.remove('bar/zot')
self.registry.add('bar/zot', GeneratedFile('barzot'))
self.registry.add('bar/zot', GeneratedFile(b'barzot'))
class TestFileRegistry(BaseTestFileRegistry, unittest.TestCase):
@ -142,16 +142,16 @@ class TestFileRegistry(BaseTestFileRegistry, unittest.TestCase):
def test_required_directories(self):
self.registry = FileRegistry()
self.registry.add('foo', GeneratedFile('foo'))
self.registry.add('foo', GeneratedFile(b'foo'))
self.assertEqual(self.registry.required_directories(), set())
self.registry.add('bar/baz', GeneratedFile('barbaz'))
self.registry.add('bar/baz', GeneratedFile(b'barbaz'))
self.assertEqual(self.registry.required_directories(), {'bar'})
self.registry.add('bar/zot', GeneratedFile('barzot'))
self.registry.add('bar/zot', GeneratedFile(b'barzot'))
self.assertEqual(self.registry.required_directories(), {'bar'})
self.registry.add('bar/zap/zot', GeneratedFile('barzapzot'))
self.registry.add('bar/zap/zot', GeneratedFile(b'barzapzot'))
self.assertEqual(self.registry.required_directories(), {'bar', 'bar/zap'})
self.registry.remove('bar/zap/zot')
@ -163,7 +163,7 @@ class TestFileRegistry(BaseTestFileRegistry, unittest.TestCase):
self.registry.remove('bar/zot')
self.assertEqual(self.registry.required_directories(), set())
self.registry.add('x/y/z', GeneratedFile('xyz'))
self.registry.add('x/y/z', GeneratedFile(b'xyz'))
self.assertEqual(self.registry.required_directories(), {'x', 'x/y'})
@ -175,8 +175,8 @@ class TestFileRegistrySubtree(BaseTestFileRegistry, unittest.TestCase):
def create_registry(self):
registry = FileRegistry()
registry.add('foo/bar', GeneratedFile('foo/bar'))
registry.add('baz/qux', GeneratedFile('baz/qux'))
registry.add('foo/bar', GeneratedFile(b'foo/bar'))
registry.add('baz/qux', GeneratedFile(b'baz/qux'))
return FileRegistrySubtree('base/root', registry)
def test_file_registry_subtree(self):
@ -205,12 +205,12 @@ class TestFileCopier(TestWithTmpDir):
def test_file_copier(self):
copier = FileCopier()
copier.add('foo/bar', GeneratedFile('foobar'))
copier.add('foo/qux', GeneratedFile('fooqux'))
copier.add('foo/deep/nested/directory/file', GeneratedFile('fooz'))
copier.add('bar', GeneratedFile('bar'))
copier.add('qux/foo', GeneratedFile('quxfoo'))
copier.add('qux/bar', GeneratedFile(''))
copier.add('foo/bar', GeneratedFile(b'foobar'))
copier.add('foo/qux', GeneratedFile(b'fooqux'))
copier.add('foo/deep/nested/directory/file', GeneratedFile(b'fooz'))
copier.add('bar', GeneratedFile(b'bar'))
copier.add('qux/foo', GeneratedFile(b'quxfoo'))
copier.add('qux/bar', GeneratedFile(b''))
result = copier.copy(self.tmpdir)
self.assertEqual(self.all_files(self.tmpdir), set(copier.paths()))
@ -224,7 +224,7 @@ class TestFileCopier(TestWithTmpDir):
self.assertEqual(result.removed_directories, set())
copier.remove('foo')
copier.add('test', GeneratedFile('test'))
copier.add('test', GeneratedFile(b'test'))
result = copier.copy(self.tmpdir)
self.assertEqual(self.all_files(self.tmpdir), set(copier.paths()))
self.assertEqual(self.all_dirs(self.tmpdir), set(['qux']))
@ -241,7 +241,7 @@ class TestFileCopier(TestWithTmpDir):
dest = self.tmppath('dest')
copier = FileCopier()
copier.add('foo/bar/baz', GeneratedFile('foobarbaz'))
copier.add('foo/bar/baz', GeneratedFile(b'foobarbaz'))
os.makedirs(self.tmppath('dest/foo'))
dummy = self.tmppath('dummy')
@ -271,7 +271,7 @@ class TestFileCopier(TestWithTmpDir):
dest = self.tmppath('dest')
copier = FileCopier()
copier.add('foo/bar/baz', GeneratedFile('foobarbaz'))
copier.add('foo/bar/baz', GeneratedFile(b'foobarbaz'))
os.makedirs(self.tmppath('dest/foo'))
dummy = self.tmppath('dummy')
@ -345,14 +345,14 @@ class TestFileCopier(TestWithTmpDir):
os.chmod(self.tmpdir, 0o400)
copier = FileCopier()
copier.add('dummy', GeneratedFile('content'))
copier.add('dummy', GeneratedFile(b'content'))
result = copier.copy(self.tmpdir)
self.assertEqual(result.removed_files_count, 1)
self.assertFalse(os.path.exists(p))
def test_no_remove(self):
copier = FileCopier()
copier.add('foo', GeneratedFile('foo'))
copier.add('foo', GeneratedFile(b'foo'))
with open(self.tmppath('bar'), 'a'):
pass
@ -375,7 +375,7 @@ class TestFileCopier(TestWithTmpDir):
def test_no_remove_empty_directories(self):
copier = FileCopier()
copier.add('foo', GeneratedFile('foo'))
copier.add('foo', GeneratedFile(b'foo'))
with open(self.tmppath('bar'), 'a'):
pass
@ -430,10 +430,10 @@ class TestFileCopier(TestWithTmpDir):
dest = self.tmppath('dest')
copier = FileCopier()
copier.add('foo/bar/baz', GeneratedFile('foobarbaz'))
copier.add('foo/bar/qux', GeneratedFile('foobarqux'))
copier.add('foo/hoge/fuga', GeneratedFile('foohogefuga'))
copier.add('foo/toto/tata', GeneratedFile('footototata'))
copier.add('foo/bar/baz', GeneratedFile(b'foobarbaz'))
copier.add('foo/bar/qux', GeneratedFile(b'foobarqux'))
copier.add('foo/hoge/fuga', GeneratedFile(b'foohogefuga'))
copier.add('foo/toto/tata', GeneratedFile(b'footototata'))
os.makedirs(os.path.join(dest, 'bar'))
with open(os.path.join(dest, 'bar', 'bar'), 'w') as fh:
@ -450,7 +450,7 @@ class TestFileCopier(TestWithTmpDir):
{'foo/bar', 'foo/hoge', 'foo/toto', 'bar'})
copier2 = FileCopier()
copier2.add('foo/hoge/fuga', GeneratedFile('foohogefuga'))
copier2.add('foo/hoge/fuga', GeneratedFile(b'foohogefuga'))
# We expect only files copied from the first copier to be removed,
# not the extra file that was there beforehand.
@ -480,24 +480,24 @@ class TestJarrer(unittest.TestCase):
def test_jarrer(self):
copier = Jarrer()
copier.add('foo/bar', GeneratedFile('foobar'))
copier.add('foo/qux', GeneratedFile('fooqux'))
copier.add('foo/deep/nested/directory/file', GeneratedFile('fooz'))
copier.add('bar', GeneratedFile('bar'))
copier.add('qux/foo', GeneratedFile('quxfoo'))
copier.add('qux/bar', GeneratedFile(''))
copier.add('foo/bar', GeneratedFile(b'foobar'))
copier.add('foo/qux', GeneratedFile(b'fooqux'))
copier.add('foo/deep/nested/directory/file', GeneratedFile(b'fooz'))
copier.add('bar', GeneratedFile(b'bar'))
copier.add('qux/foo', GeneratedFile(b'quxfoo'))
copier.add('qux/bar', GeneratedFile(b''))
dest = MockDest()
copier.copy(dest)
self.check_jar(dest, copier)
copier.remove('foo')
copier.add('test', GeneratedFile('test'))
copier.add('test', GeneratedFile(b'test'))
copier.copy(dest)
self.check_jar(dest, copier)
copier.remove('test')
copier.add('test', GeneratedFile('replaced-content'))
copier.add('test', GeneratedFile(b'replaced-content'))
copier.copy(dest)
self.check_jar(dest, copier)
@ -516,8 +516,8 @@ class TestJarrer(unittest.TestCase):
def test_jarrer_compress(self):
copier = Jarrer()
copier.add('foo/bar', GeneratedFile('ffffff'))
copier.add('foo/qux', GeneratedFile('ffffff'), compress=False)
copier.add('foo/bar', GeneratedFile(b'ffffff'))
copier.add('foo/qux', GeneratedFile(b'ffffff'), compress=False)
dest = MockDest()
copier.copy(dest)

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozpack.errors import (
errors,

Просмотреть файл

@ -2,9 +2,12 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozbuild.util import ensureParentDir
from mozbuild.util import (
ensureParentDir,
ensure_bytes,
)
from mozpack.errors import (
ErrorMessage,
@ -57,7 +60,6 @@ import mozfile
import mozunit
import os
import random
import string
import sys
import tarfile
import mozpack.path as mozpath
@ -161,18 +163,20 @@ class TestDest(TestWithTmpDir):
self.assertEqual(dest.read(), 'qux')
rand = ''.join(random.choice(string.letters) for i in xrange(131597))
rand = b''.join(random.choice(
b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in xrange(131597))
samples = [
'',
'test',
'fooo',
'same',
'same',
'Different and longer',
b'',
b'test',
b'fooo',
b'same',
b'same',
b'Different and longer',
rand,
rand,
rand[:-1] + '_',
'test'
rand[:-1] + b'_',
b'test',
]
@ -629,7 +633,7 @@ class TestGeneratedFile(TestWithTmpDir):
Test whether GeneratedFile.open returns an appropriately reset file
object.
'''
content = ''.join(samples)
content = b''.join(samples)
f = GeneratedFile(content)
self.assertEqual(content[:42], f.open().read(42))
self.assertEqual(content, f.open().read())
@ -642,21 +646,21 @@ class TestGeneratedFile(TestWithTmpDir):
dest = self.tmppath('dest')
# Initial copy
f = GeneratedFile('test')
f = GeneratedFile(b'test')
f.copy(dest)
# Ensure subsequent copies won't trigger writes
f.copy(DestNoWrite(dest))
self.assertEqual('test', open(dest, 'rb').read())
self.assertEqual(b'test', open(dest, 'rb').read())
# When using a new instance with the same content, no copy should occur
f = GeneratedFile('test')
f = GeneratedFile(b'test')
f.copy(DestNoWrite(dest))
self.assertEqual('test', open(dest, 'rb').read())
self.assertEqual(b'test', open(dest, 'rb').read())
# Double check that under conditions where a copy occurs, we would get
# an exception.
f = GeneratedFile('fooo')
f = GeneratedFile(b'fooo')
self.assertRaises(RuntimeError, f.copy, DestNoWrite(dest))
def test_generated_file_function(self):
@ -670,29 +674,29 @@ class TestGeneratedFile(TestWithTmpDir):
def content():
data['num_calls'] += 1
return 'content'
return b'content'
f = GeneratedFile(content)
self.assertEqual(data['num_calls'], 0)
f.copy(dest)
self.assertEqual(data['num_calls'], 1)
self.assertEqual('content', open(dest, 'rb').read())
self.assertEqual('content', f.open().read())
self.assertEqual('content', f.read())
self.assertEqual(len('content'), f.size())
self.assertEqual(b'content', open(dest, 'rb').read())
self.assertEqual(b'content', f.open().read())
self.assertEqual(b'content', f.read())
self.assertEqual(len(b'content'), f.size())
self.assertEqual(data['num_calls'], 1)
f.content = 'modified'
f.content = b'modified'
f.copy(dest)
self.assertEqual(data['num_calls'], 1)
self.assertEqual('modified', open(dest, 'rb').read())
self.assertEqual('modified', f.open().read())
self.assertEqual('modified', f.read())
self.assertEqual(len('modified'), f.size())
self.assertEqual(b'modified', open(dest, 'rb').read())
self.assertEqual(b'modified', f.open().read())
self.assertEqual(b'modified', f.read())
self.assertEqual(len(b'modified'), f.size())
f.content = content
self.assertEqual(data['num_calls'], 1)
self.assertEqual('content', f.read())
self.assertEqual(b'content', f.read())
self.assertEqual(data['num_calls'], 2)
@ -709,8 +713,9 @@ class TestDeflatedFile(TestWithTmpDir):
contents = {}
with JarWriter(src) as jar:
for content in samples:
name = ''.join(random.choice(string.letters)
for i in xrange(8))
name = b''.join(random.choice(
b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in xrange(8))
jar.add(name, content, compress=True)
contents[name] = content
@ -725,7 +730,7 @@ class TestDeflatedFile(TestWithTmpDir):
object.
'''
src = self.tmppath('src.jar')
content = ''.join(samples)
content = b''.join(samples)
with JarWriter(src) as jar:
jar.add('content', content)
@ -742,9 +747,9 @@ class TestDeflatedFile(TestWithTmpDir):
dest = self.tmppath('dest')
with JarWriter(src) as jar:
jar.add('test', 'test')
jar.add('test2', 'test')
jar.add('fooo', 'fooo')
jar.add('test', b'test')
jar.add('test2', b'test')
jar.add('fooo', b'fooo')
jar = JarReader(src)
# Initial copy
@ -753,13 +758,13 @@ class TestDeflatedFile(TestWithTmpDir):
# Ensure subsequent copies won't trigger writes
f.copy(DestNoWrite(dest))
self.assertEqual('test', open(dest, 'rb').read())
self.assertEqual(b'test', open(dest, 'rb').read())
# When using a different file with the same content, no copy should
# occur
f = DeflatedFile(jar['test2'])
f.copy(DestNoWrite(dest))
self.assertEqual('test', open(dest, 'rb').read())
self.assertEqual(b'test', open(dest, 'rb').read())
# Double check that under conditions where a copy occurs, we would get
# an exception.
@ -865,12 +870,12 @@ foo2_xpt = GeneratedFile(
class TestMinifiedProperties(TestWithTmpDir):
def test_minified_properties(self):
propLines = [
'# Comments are removed',
'foo = bar',
'',
'# Another comment',
b'# Comments are removed',
b'foo = bar',
b'',
b'# Another comment',
]
prop = GeneratedFile('\n'.join(propLines))
prop = GeneratedFile(b'\n'.join(propLines))
self.assertEqual(MinifiedProperties(prop).open().readlines(),
['foo = bar\n', '\n'])
open(self.tmppath('prop'), 'wb').write('\n'.join(propLines))
@ -882,15 +887,15 @@ class TestMinifiedProperties(TestWithTmpDir):
class TestMinifiedJavaScript(TestWithTmpDir):
orig_lines = [
'// Comment line',
'let foo = "bar";',
'var bar = true;',
'',
'// Another comment',
b'// Comment line',
b'let foo = "bar";',
b'var bar = true;',
b'',
b'// Another comment',
]
def test_minified_javascript(self):
orig_f = GeneratedFile('\n'.join(self.orig_lines))
orig_f = GeneratedFile(b'\n'.join(self.orig_lines))
min_f = MinifiedJavaScript(orig_f)
mini_lines = min_f.open().readlines()
@ -906,7 +911,7 @@ class TestMinifiedJavaScript(TestWithTmpDir):
]
def test_minified_verify_success(self):
orig_f = GeneratedFile('\n'.join(self.orig_lines))
orig_f = GeneratedFile(b'\n'.join(self.orig_lines))
min_f = MinifiedJavaScript(orig_f,
verify_command=self._verify_command('0'))
@ -915,7 +920,7 @@ class TestMinifiedJavaScript(TestWithTmpDir):
self.assertTrue(len(mini_lines) < len(self.orig_lines))
def test_minified_verify_failure(self):
orig_f = GeneratedFile('\n'.join(self.orig_lines))
orig_f = GeneratedFile(b'\n'.join(self.orig_lines))
errors.out = StringIO()
min_f = MinifiedJavaScript(orig_f,
verify_command=self._verify_command('1'))
@ -1097,7 +1102,7 @@ class TestFileFinder(MatchTestTemplate, TestWithTmpDir):
class TestJarFinder(MatchTestTemplate, TestWithTmpDir):
def add(self, path):
self.jar.add(path, path, compress=True)
self.jar.add(path, ensure_bytes(path), compress=True)
def do_check(self, pattern, result):
do_check(self, self.finder, pattern, result)
@ -1190,10 +1195,11 @@ class TestMercurialRevisionFinder(MatchTestTemplate, TestWithTmpDir):
def _client(self):
configs = (
'ui.username="Dummy User <dummy@example.com>"',
# b'' because py2 needs !unicode
b'ui.username="Dummy User <dummy@example.com>"',
)
client = hglib.open(self.tmpdir, encoding='UTF-8',
client = hglib.open(self.tmpdir,
encoding=b'UTF-8', # b'' because py2 needs !unicode
configs=configs)
self._clients.append(client)
return client

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozpack.files import FileFinder
from mozpack.mozjar import (
@ -95,25 +95,25 @@ class TestDeflater(unittest.TestCase):
def test_deflater_no_compress(self):
deflater = Deflater(False)
deflater.write(self.wrap('abc'))
deflater.write(self.wrap(b'abc'))
self.assertFalse(deflater.compressed)
self.assertEqual(deflater.uncompressed_size, 3)
self.assertEqual(deflater.compressed_size, deflater.uncompressed_size)
self.assertEqual(deflater.compressed_data, 'abc')
self.assertEqual(deflater.compressed_data, b'abc')
self.assertEqual(deflater.crc32, 0x352441c2)
def test_deflater_compress_no_gain(self):
deflater = Deflater(True)
deflater.write(self.wrap('abc'))
deflater.write(self.wrap(b'abc'))
self.assertFalse(deflater.compressed)
self.assertEqual(deflater.uncompressed_size, 3)
self.assertEqual(deflater.compressed_size, deflater.uncompressed_size)
self.assertEqual(deflater.compressed_data, 'abc')
self.assertEqual(deflater.compressed_data, b'abc')
self.assertEqual(deflater.crc32, 0x352441c2)
def test_deflater_compress(self):
deflater = Deflater(True)
deflater.write(self.wrap('aaaaaaaaaaaaanopqrstuvwxyz'))
deflater.write(self.wrap(b'aaaaaaaaaaaaanopqrstuvwxyz'))
self.assertTrue(deflater.compressed)
self.assertEqual(deflater.uncompressed_size, 26)
self.assertNotEqual(deflater.compressed_size,
@ -122,7 +122,7 @@ class TestDeflater(unittest.TestCase):
# The CRC is the same as when not compressed
deflater = Deflater(False)
self.assertFalse(deflater.compressed)
deflater.write(self.wrap('aaaaaaaaaaaaanopqrstuvwxyz'))
deflater.write(self.wrap(b'aaaaaaaaaaaaanopqrstuvwxyz'))
self.assertEqual(deflater.crc32, 0xd46b97ed)
def test_deflater_empty(self):
@ -143,25 +143,25 @@ class TestJar(unittest.TestCase):
def test_jar(self):
s = MockDest()
with JarWriter(fileobj=s) as jar:
jar.add('foo', 'foo')
self.assertRaises(JarWriterError, jar.add, 'foo', 'bar')
jar.add('bar', 'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz', False)
jar.add('baz\\backslash', 'aaaaaaaaaaaaaaa')
jar.add('foo', b'foo')
self.assertRaises(JarWriterError, jar.add, 'foo', b'bar')
jar.add('bar', b'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('baz/qux', b'aaaaaaaaaaaaanopqrstuvwxyz', False)
jar.add('baz\\backslash', b'aaaaaaaaaaaaaaa')
files = [j for j in JarReader(fileobj=s)]
self.assertEqual(files[0].filename, 'foo')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), 'foo')
self.assertEqual(files[0].read(), b'foo')
self.assertEqual(files[1].filename, 'bar')
self.assertTrue(files[1].compressed)
self.assertEqual(files[1].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[1].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].filename, 'baz/qux')
self.assertFalse(files[2].compressed)
self.assertEqual(files[2].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
if os.sep == '\\':
self.assertEqual(files[3].filename, 'baz/backslash',
@ -172,24 +172,24 @@ class TestJar(unittest.TestCase):
s = MockDest()
with JarWriter(fileobj=s, compress=False) as jar:
jar.add('bar', 'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('foo', 'foo')
jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz', True)
jar.add('bar', b'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('foo', b'foo')
jar.add('baz/qux', b'aaaaaaaaaaaaanopqrstuvwxyz', True)
jar = JarReader(fileobj=s)
files = [j for j in jar]
self.assertEqual(files[0].filename, 'bar')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[0].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[1].filename, 'foo')
self.assertFalse(files[1].compressed)
self.assertEqual(files[1].read(), 'foo')
self.assertEqual(files[1].read(), b'foo')
self.assertEqual(files[2].filename, 'baz/qux')
self.assertTrue(files[2].compressed)
self.assertEqual(files[2].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertTrue('bar' in jar)
self.assertTrue('foo' in jar)
@ -224,9 +224,9 @@ class TestJar(unittest.TestCase):
def test_rejar(self):
s = MockDest()
with JarWriter(fileobj=s) as jar:
jar.add('foo', 'foo')
jar.add('bar', 'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz', False)
jar.add('foo', b'foo')
jar.add('bar', b'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('baz/qux', b'aaaaaaaaaaaaanopqrstuvwxyz', False)
new = MockDest()
with JarWriter(fileobj=new) as jar:
@ -238,15 +238,15 @@ class TestJar(unittest.TestCase):
self.assertEqual(files[0].filename, 'foo')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), 'foo')
self.assertEqual(files[0].read(), b'foo')
self.assertEqual(files[1].filename, 'bar')
self.assertTrue(files[1].compressed)
self.assertEqual(files[1].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[1].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].filename, 'baz/qux')
self.assertTrue(files[2].compressed)
self.assertEqual(files[2].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
self.assertEqual(files[2].read(), b'aaaaaaaaaaaaanopqrstuvwxyz')
def test_add_from_finder(self):
s = MockDest()
@ -260,28 +260,28 @@ class TestJar(unittest.TestCase):
self.assertEqual(files[0].filename, 'test_data')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), 'test_data')
self.assertEqual(files[0].read(), b'test_data')
class TestPreload(unittest.TestCase):
def test_preload(self):
s = MockDest()
with JarWriter(fileobj=s) as jar:
jar.add('foo', 'foo')
jar.add('bar', 'abcdefghijklmnopqrstuvwxyz')
jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz')
jar.add('foo', b'foo')
jar.add('bar', b'abcdefghijklmnopqrstuvwxyz')
jar.add('baz/qux', b'aaaaaaaaaaaaanopqrstuvwxyz')
jar = JarReader(fileobj=s)
self.assertEqual(jar.last_preloaded, None)
with JarWriter(fileobj=s) as jar:
jar.add('foo', 'foo')
jar.add('bar', 'abcdefghijklmnopqrstuvwxyz')
jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz')
jar.preload(['baz/qux', 'bar'])
jar.add('foo', b'foo')
jar.add('bar', b'abcdefghijklmnopqrstuvwxyz')
jar.add('baz/qux', b'aaaaaaaaaaaaanopqrstuvwxyz')
jar.preload(['baz/qux', b'bar'])
jar = JarReader(fileobj=s)
self.assertEqual(jar.last_preloaded, 'bar')
self.assertEqual(jar.last_preloaded, b'bar')
files = [j for j in jar]
self.assertEqual(files[0].filename, 'baz/qux')

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import unittest
import mozunit
@ -147,26 +147,26 @@ class TestSimplePackager(unittest.TestCase):
curdir = os.path.abspath(os.curdir)
file = GeneratedFileWithPath(os.path.join(curdir, 'foo',
'bar.manifest'),
'resource bar bar/\ncontent bar bar/')
b'resource bar bar/\ncontent bar bar/')
with errors.context('manifest', 1):
packager.add('foo/bar.manifest', file)
file = GeneratedFileWithPath(os.path.join(curdir, 'foo',
'baz.manifest'),
'resource baz baz/')
b'resource baz baz/')
with errors.context('manifest', 2):
packager.add('bar/baz.manifest', file)
with errors.context('manifest', 3):
packager.add('qux/qux.manifest',
GeneratedFile(''.join([
'resource qux qux/\n',
'binary-component qux.so\n',
GeneratedFile(b''.join([
b'resource qux qux/\n',
b'binary-component qux.so\n',
])))
bar_xpt = GeneratedFile('bar.xpt')
qux_xpt = GeneratedFile('qux.xpt')
foo_html = GeneratedFile('foo_html')
bar_html = GeneratedFile('bar_html')
bar_xpt = GeneratedFile(b'bar.xpt')
qux_xpt = GeneratedFile(b'qux.xpt')
foo_html = GeneratedFile(b'foo_html')
bar_html = GeneratedFile(b'bar_html')
with errors.context('manifest', 4):
packager.add('foo/bar.xpt', bar_xpt)
with errors.context('manifest', 5):
@ -174,9 +174,9 @@ class TestSimplePackager(unittest.TestCase):
packager.add('foo/bar/bar.html', bar_html)
file = GeneratedFileWithPath(os.path.join(curdir, 'foo.manifest'),
''.join([
'manifest foo/bar.manifest\n',
'manifest bar/baz.manifest\n',
b''.join([
b'manifest foo/bar.manifest\n',
b'manifest bar/baz.manifest\n',
]))
with errors.context('manifest', 6):
packager.add('foo.manifest', file)
@ -185,68 +185,68 @@ class TestSimplePackager(unittest.TestCase):
file = GeneratedFileWithPath(os.path.join(curdir, 'addon',
'chrome.manifest'),
'resource hoge hoge/')
b'resource hoge hoge/')
with errors.context('manifest', 8):
packager.add('addon/chrome.manifest', file)
install_rdf = GeneratedFile('<RDF></RDF>')
install_rdf = GeneratedFile(b'<RDF></RDF>')
with errors.context('manifest', 9):
packager.add('addon/install.rdf', install_rdf)
with errors.context('manifest', 10):
packager.add('addon2/install.rdf', install_rdf)
packager.add('addon2/chrome.manifest',
GeneratedFile('binary-component addon2.so'))
GeneratedFile(b'binary-component addon2.so'))
with errors.context('manifest', 11):
packager.add('addon3/install.rdf', install_rdf)
packager.add('addon3/chrome.manifest', GeneratedFile(
'manifest components/components.manifest'))
b'manifest components/components.manifest'))
packager.add('addon3/components/components.manifest',
GeneratedFile('binary-component addon3.so'))
GeneratedFile(b'binary-component addon3.so'))
with errors.context('manifest', 12):
install_rdf_addon4 = GeneratedFile(
'<RDF>\n<...>\n<em:unpack>true</em:unpack>\n<...>\n</RDF>')
b'<RDF>\n<...>\n<em:unpack>true</em:unpack>\n<...>\n</RDF>')
packager.add('addon4/install.rdf', install_rdf_addon4)
with errors.context('manifest', 13):
install_rdf_addon5 = GeneratedFile(
'<RDF>\n<...>\n<em:unpack>false</em:unpack>\n<...>\n</RDF>')
b'<RDF>\n<...>\n<em:unpack>false</em:unpack>\n<...>\n</RDF>')
packager.add('addon5/install.rdf', install_rdf_addon5)
with errors.context('manifest', 14):
install_rdf_addon6 = GeneratedFile(
'<RDF>\n<... em:unpack=true>\n<...>\n</RDF>')
b'<RDF>\n<... em:unpack=true>\n<...>\n</RDF>')
packager.add('addon6/install.rdf', install_rdf_addon6)
with errors.context('manifest', 15):
install_rdf_addon7 = GeneratedFile(
'<RDF>\n<... em:unpack=false>\n<...>\n</RDF>')
b'<RDF>\n<... em:unpack=false>\n<...>\n</RDF>')
packager.add('addon7/install.rdf', install_rdf_addon7)
with errors.context('manifest', 16):
install_rdf_addon8 = GeneratedFile(
'<RDF>\n<... em:unpack="true">\n<...>\n</RDF>')
b'<RDF>\n<... em:unpack="true">\n<...>\n</RDF>')
packager.add('addon8/install.rdf', install_rdf_addon8)
with errors.context('manifest', 17):
install_rdf_addon9 = GeneratedFile(
'<RDF>\n<... em:unpack="false">\n<...>\n</RDF>')
b'<RDF>\n<... em:unpack="false">\n<...>\n</RDF>')
packager.add('addon9/install.rdf', install_rdf_addon9)
with errors.context('manifest', 18):
install_rdf_addon10 = GeneratedFile(
'<RDF>\n<... em:unpack=\'true\'>\n<...>\n</RDF>')
b'<RDF>\n<... em:unpack=\'true\'>\n<...>\n</RDF>')
packager.add('addon10/install.rdf', install_rdf_addon10)
with errors.context('manifest', 19):
install_rdf_addon11 = GeneratedFile(
'<RDF>\n<... em:unpack=\'false\'>\n<...>\n</RDF>')
b'<RDF>\n<... em:unpack=\'false\'>\n<...>\n</RDF>')
packager.add('addon11/install.rdf', install_rdf_addon11)
we_manifest = GeneratedFile(
'{"manifest_version": 2, "name": "Test WebExtension", "version": "1.0"}')
b'{"manifest_version": 2, "name": "Test WebExtension", "version": "1.0"}')
# hybrid and hybrid2 are both bootstrapped extensions with
# embedded webextensions, they differ in the order in which
# the manifests are added to the packager.
@ -265,7 +265,7 @@ class TestSimplePackager(unittest.TestCase):
with errors.context('manifest', 24):
packager.add('webextension/manifest.json', we_manifest)
non_we_manifest = GeneratedFile('{"not a webextension": true}')
non_we_manifest = GeneratedFile(b'{"not a webextension": true}')
with errors.context('manifest', 25):
packager.add('nonwebextension/manifest.json', non_we_manifest)
@ -357,12 +357,12 @@ class TestSimplePackager(unittest.TestCase):
# includes a manifest inside bar/.
packager = SimplePackager(formatter)
packager.add('base.manifest', GeneratedFile(
'manifest foo/bar.manifest\n'
'manifest bar/baz.manifest\n'
b'manifest foo/bar.manifest\n'
b'manifest bar/baz.manifest\n'
))
packager.add('foo/bar.manifest', GeneratedFile('resource bar bar'))
packager.add('bar/baz.manifest', GeneratedFile('resource baz baz'))
packager.add('bar/install.rdf', GeneratedFile(''))
packager.add('foo/bar.manifest', GeneratedFile(b'resource bar bar'))
packager.add('bar/baz.manifest', GeneratedFile(b'resource baz baz'))
packager.add('bar/install.rdf', GeneratedFile(b''))
with self.assertRaises(ErrorMessage) as e:
packager.close()
@ -376,12 +376,12 @@ class TestSimplePackager(unittest.TestCase):
# bar/.
packager = SimplePackager(formatter)
packager.add('base.manifest', GeneratedFile(
'manifest foo/bar.manifest\n'
'manifest bar/baz.manifest\n'
b'manifest foo/bar.manifest\n'
b'manifest bar/baz.manifest\n'
))
packager.add('foo/bar.manifest', GeneratedFile('resource bar bar'))
packager.add('bar/baz.manifest', GeneratedFile('resource baz baz'))
packager.add('bar/chrome.manifest', GeneratedFile('resource baz baz'))
packager.add('foo/bar.manifest', GeneratedFile(b'resource bar bar'))
packager.add('bar/baz.manifest', GeneratedFile(b'resource baz baz'))
packager.add('bar/chrome.manifest', GeneratedFile(b'resource baz baz'))
with self.assertRaises(ErrorMessage) as e:
packager.close()
@ -395,30 +395,30 @@ class TestSimplePackager(unittest.TestCase):
# the same directory. This shouldn't error out.
packager = SimplePackager(formatter)
packager.add('base.manifest', GeneratedFile(
'manifest foo/bar.manifest\n'
b'manifest foo/bar.manifest\n'
))
packager.add('foo/bar.manifest', GeneratedFile('resource bar bar'))
packager.add('bar/baz.manifest', GeneratedFile('resource baz baz'))
packager.add('foo/bar.manifest', GeneratedFile(b'resource bar bar'))
packager.add('bar/baz.manifest', GeneratedFile(b'resource baz baz'))
packager.add('bar/chrome.manifest',
GeneratedFile('manifest baz.manifest'))
GeneratedFile(b'manifest baz.manifest'))
packager.close()
class TestSimpleManifestSink(unittest.TestCase):
def test_simple_manifest_parser(self):
formatter = MockFormatter()
foobar = GeneratedFile('foobar')
foobaz = GeneratedFile('foobaz')
fooqux = GeneratedFile('fooqux')
foozot = GeneratedFile('foozot')
foobar = GeneratedFile(b'foobar')
foobaz = GeneratedFile(b'foobaz')
fooqux = GeneratedFile(b'fooqux')
foozot = GeneratedFile(b'foozot')
finder = MockFinder({
'bin/foo/bar': foobar,
'bin/foo/baz': foobaz,
'bin/foo/qux': fooqux,
'bin/foo/zot': foozot,
'bin/foo/chrome.manifest': GeneratedFile('resource foo foo/'),
'bin/foo/chrome.manifest': GeneratedFile(b'resource foo foo/'),
'bin/chrome.manifest':
GeneratedFile('manifest foo/chrome.manifest'),
GeneratedFile(b'manifest foo/chrome.manifest'),
})
parser = SimpleManifestSink(finder, formatter)
component0 = Component('component0')

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import mozunit
import unittest
@ -58,22 +58,22 @@ CONTENTS = {
ManifestContent('app/chrome/addons/addon2/chrome', 'addon2', 'foo/bar/'),
],
'files': {
'chrome/f/oo/bar/baz': GeneratedFile('foobarbaz'),
'chrome/f/oo/baz': GeneratedFile('foobaz'),
'chrome/f/oo/qux': GeneratedFile('fooqux'),
'components/foo.so': GeneratedFile('foo.so'),
'chrome/f/oo/bar/baz': GeneratedFile(b'foobarbaz'),
'chrome/f/oo/baz': GeneratedFile(b'foobaz'),
'chrome/f/oo/qux': GeneratedFile(b'fooqux'),
'components/foo.so': GeneratedFile(b'foo.so'),
'components/foo.xpt': foo_xpt,
'components/bar.xpt': bar_xpt,
'foo': GeneratedFile('foo'),
'app/chrome/foo/foo': GeneratedFile('appfoo'),
'app/components/foo.js': GeneratedFile('foo.js'),
'addon0/chrome/foo/bar/baz': GeneratedFile('foobarbaz'),
'foo': GeneratedFile(b'foo'),
'app/chrome/foo/foo': GeneratedFile(b'appfoo'),
'app/components/foo.js': GeneratedFile(b'foo.js'),
'addon0/chrome/foo/bar/baz': GeneratedFile(b'foobarbaz'),
'addon0/components/foo.xpt': foo2_xpt,
'addon0/components/bar.xpt': bar_xpt,
'addon1/chrome/foo/bar/baz': GeneratedFile('foobarbaz'),
'addon1/chrome/foo/bar/baz': GeneratedFile(b'foobarbaz'),
'addon1/components/foo.xpt': foo2_xpt,
'addon1/components/bar.xpt': bar_xpt,
'app/chrome/addons/addon2/chrome/foo/bar/baz': GeneratedFile('foobarbaz'),
'app/chrome/addons/addon2/chrome/foo/bar/baz': GeneratedFile(b'foobarbaz'),
'app/chrome/addons/addon2/components/foo.xpt': foo2_xpt,
'app/chrome/addons/addon2/components/bar.xpt': bar_xpt,
},
@ -275,7 +275,7 @@ CONTENTS_WITH_BASE = {
}
EXTRA_CONTENTS = {
'extra/file': GeneratedFile('extra file'),
'extra/file': GeneratedFile(b'extra file'),
}
CONTENTS_WITH_BASE['files'].update(EXTRA_CONTENTS)
@ -408,7 +408,7 @@ class TestFormatters(TestErrors, unittest.TestCase):
])
f.add_base('')
f.add_base('app')
f.add(mozpath.join(base, path), GeneratedFile(''))
f.add(mozpath.join(base, path), GeneratedFile(b''))
if f.copier.contains(mozpath.join(base, path)):
return False
self.assertTrue(f.copier.contains(mozpath.join(base, 'omni.foo')))

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import unittest
import mozunit
@ -23,16 +23,16 @@ from mozpack.packager.formats import FlatFormatter
class TestL10NRepack(unittest.TestCase):
def test_l10n_repack(self):
foo = GeneratedFile('foo')
foobar = GeneratedFile('foobar')
qux = GeneratedFile('qux')
bar = GeneratedFile('bar')
baz = GeneratedFile('baz')
dict_aa = GeneratedFile('dict_aa')
dict_bb = GeneratedFile('dict_bb')
dict_cc = GeneratedFile('dict_cc')
barbaz = GeneratedFile('barbaz')
lst = GeneratedFile('foo\nbar')
foo = GeneratedFile(b'foo')
foobar = GeneratedFile(b'foobar')
qux = GeneratedFile(b'qux')
bar = GeneratedFile(b'bar')
baz = GeneratedFile(b'baz')
dict_aa = GeneratedFile(b'dict_aa')
dict_bb = GeneratedFile(b'dict_bb')
dict_cc = GeneratedFile(b'dict_cc')
barbaz = GeneratedFile(b'barbaz')
lst = GeneratedFile(b'foo\nbar')
app_finder = MockFinder({
'bar/foo': foo,
'chrome/foo/foobar': foobar,
@ -59,11 +59,11 @@ class TestL10NRepack(unittest.TestCase):
})
app_finder.jarlogs = {}
app_finder.base = 'app'
foo_l10n = GeneratedFile('foo_l10n')
qux_l10n = GeneratedFile('qux_l10n')
baz_l10n = GeneratedFile('baz_l10n')
barbaz_l10n = GeneratedFile('barbaz_l10n')
lst_l10n = GeneratedFile('foo\nqux')
foo_l10n = GeneratedFile(b'foo_l10n')
qux_l10n = GeneratedFile(b'qux_l10n')
baz_l10n = GeneratedFile(b'baz_l10n')
barbaz_l10n = GeneratedFile(b'barbaz_l10n')
lst_l10n = GeneratedFile(b'foo\nqux')
l10n_finder = MockFinder({
'chrome/qux-l10n/qux.properties': qux_l10n,
'chrome/qux-l10n/baz/baz.properties': baz_l10n,

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import mozunit
from mozpack.packager.formats import (

Просмотреть файл

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
from mozpack.path import (
relpath,