Bug 1606462 - mozbuild/jar.py supports Python 3 r=firefox-build-system-reviewers,mshal

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ricky Stewart 2020-01-01 00:16:01 +00:00
Родитель e71b73a1da
Коммит 3527413fa7
5 изменённых файлов: 20 добавлений и 16 удалений

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

@ -2,8 +2,9 @@
# 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
from __future__ import absolute_import, print_function, unicode_literals
import os
import six
import time
import zipfile
@ -20,7 +21,7 @@ class ZipFile(zipfile.ZipFile):
def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
lock=False):
if lock:
assert isinstance(file, basestring)
assert isinstance(file, six.text_type)
self.lockfile = lock_file(file + '.lck')
else:
self.lockfile = None
@ -90,7 +91,7 @@ class ZipFile(zipfile.ZipFile):
# Couldn't optimize, sadly, just remember the old entry for removal
self._remove.append(self.filelist.pop(i))
zipfile.ZipFile.writestr(self, zinfo, bytes)
self.filelist.sort(lambda l, r: cmp(l.header_offset, r.header_offset))
self.filelist.sort(key=lambda l: l.header_offset)
if doSeek:
self.fp.seek(self.end)
self.end = self.fp.tell()
@ -113,7 +114,7 @@ class ZipFile(zipfile.ZipFile):
self.fp = open(self.filename, 'r+b')
all = map(lambda zi: (zi, True), self.filelist) + \
map(lambda zi: (zi, False), self._remove)
all.sort(lambda l, r: cmp(l[0].header_offset, r[0].header_offset))
all.sort(key=lambda l: l[0].header_offset)
# empty _remove for multiple closes
self._remove = []

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

@ -8,7 +8,7 @@ processing jar.mn files.
See the documentation for jar.mn on MDC for further details on the format.
'''
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import sys
import os
@ -18,7 +18,7 @@ import six
import logging
from time import localtime
from MozZipFile import ZipFile
from cStringIO import StringIO
from six import BytesIO
from mozbuild.preprocessor import Preprocessor
from mozbuild.action.buildlist import addEntriesToListFile
@ -43,7 +43,7 @@ class ZipEntry(object):
def __init__(self, name, zipfile):
self._zipfile = zipfile
self._name = name
self._inner = StringIO()
self._inner = BytesIO()
def write(self, content):
'''Append the given content to this zip entry'''
@ -59,7 +59,7 @@ class ZipEntry(object):
def getModTime(aPath):
if not os.path.isfile(aPath):
return 0
return localtime(0)
mtime = os.stat(aPath).st_mtime
return localtime(mtime)
@ -325,7 +325,7 @@ class JarMaker(object):
elif self.relativesrcdir:
self.localedirs = \
self.generateLocaleDirs(self.relativesrcdir)
if isinstance(infile, basestring):
if isinstance(infile, six.text_type):
logging.info('processing ' + infile)
self.sourcedirs.append(_normpath(os.path.dirname(infile)))
pp = self.pp.clone()
@ -505,7 +505,7 @@ class JarMaker(object):
info = self.jarfile.getinfo(aPath)
return info.date_time
except Exception:
return 0
return localtime(0)
def getOutput(self, name):
return ZipEntry(name, self.jarfile)
@ -608,4 +608,5 @@ def main(args=None):
infile = sys.stdin
else:
(infile, ) = args
infile = six.ensure_text(infile)
jm.makeJar(infile, options.d)

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

@ -3,6 +3,7 @@ subsuite = mozbuild
[test_base.py]
[test_expression.py]
[test_jarmaker.py]
[test_licenses.py]
[test_line_endings.py]
[test_makeutil.py]

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

@ -39,5 +39,4 @@ skip-if = (os == "win")
[test_artifact_cache.py]
[test_containers.py]
[test_dotproperties.py]
[test_jarmaker.py]
[test_util.py]

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

@ -11,7 +11,8 @@ import os.path
from filecmp import dircmp
from tempfile import mkdtemp
from shutil import rmtree, copy2
from StringIO import StringIO
import six
from six import StringIO
from zipfile import ZipFile
import mozunit
@ -74,7 +75,7 @@ def symlinks_supported(path):
# Add 1 for a trailing backslash if necessary, and 1 for the terminating
# null character.
volpath = ctypes.create_string_buffer(len(path) + 2)
rv = GetVolumePathName(path, volpath, len(volpath))
rv = GetVolumePathName(six.ensure_binary(path), volpath, len(volpath))
if rv == 0:
raise WinError()
@ -92,7 +93,8 @@ def symlinks_supported(path):
def _getfileinfo(path):
"""Return information for the given file. This only works on Windows."""
fh = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, None, OPEN_EXISTING, 0, None)
fh = CreateFile(six.ensure_binary(path), GENERIC_READ, FILE_SHARE_READ,
None, OPEN_EXISTING, 0, None)
if fh is None:
raise WinError()
info = BY_HANDLE_FILE_INFORMATION()
@ -129,7 +131,7 @@ class _TreeDiff(dircmp):
rv['diff_files'] += map(lambda l: basepath.format(l), dc.diff_files)
rv['funny'] += map(lambda l: basepath.format(l), dc.common_funny)
rv['funny'] += map(lambda l: basepath.format(l), dc.funny_files)
for subdir, _dc in dc.subdirs.iteritems():
for subdir, _dc in six.iteritems(dc.subdirs):
self._fillDiff(_dc, rv, basepath.format(subdir + "/{0}"))
def allResults(self, left, right):
@ -305,7 +307,7 @@ class TestJarMaker(unittest.TestCase):
('hoge', 'foo', '2'): ('qux', 'foo', '2'),
('hoge', 'baz'): ('qux', 'baz'),
}
for dest, src in expected_symlinks.iteritems():
for dest, src in six.iteritems(expected_symlinks):
srcpath = os.path.join(self.srcdir, *src)
destpath = os.path.join(self.builddir, 'chrome', 'test', 'dir',
*dest)