Commit a62dcc82 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Supersize: Fix archive producing different results for the same input

A) Removes gzip header
B) Fixes sort key for string literals

Bug: 779895
Change-Id: Ia1c9872c42c5564134215b0973d5d9e27dcf966d
Reviewed-on: https://chromium-review.googlesource.com/746377Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512854}
parent 3705fe7e
......@@ -42,13 +42,11 @@ import paths
_MAX_SAME_NAME_ALIAS_COUNT = 40 # 50kb is basically negligable.
def _OpenMaybeGz(path, mode=None):
def _OpenMaybeGz(path):
"""Calls `gzip.open()` if |path| ends in ".gz", otherwise calls `open()`."""
if path.endswith('.gz'):
if mode and 'w' in mode:
return gzip.GzipFile(path, mode, 1)
return gzip.open(path, mode)
return open(path, mode or 'r')
return gzip.open(path, 'rb')
return open(path, 'rb')
def _StripLinkerAddedSymbolPrefixes(raw_symbols):
......@@ -390,7 +388,7 @@ def _CreateMergeStringsReplacements(merge_string_syms,
logging.debug('Created %d string literal symbols', sum(len(x) for x in ret))
logging.debug('Sorting string literals')
for symbols in ret:
symbols.sort(key=lambda x: x.address)
symbols.sort(key=lambda x: (x.address, -x.size))
logging.debug('Deduping string literals')
num_removed = 0
......
......@@ -6,6 +6,7 @@
import cStringIO
import calendar
import contextlib
import datetime
import gzip
import json
......@@ -187,10 +188,18 @@ def _LoadSizeInfoFromFile(file_obj, size_path):
size_path=size_path)
@contextlib.contextmanager
def _OpenGzipForWrite(path):
# Open in a way that doesn't set any gzip header fields.
with open(path, 'wb') as f:
with gzip.GzipFile(filename='', mode='wb', fileobj=f, mtime=0) as fz:
yield fz
def SaveSizeInfo(size_info, path):
"""Saves |size_info| to |path}."""
if os.environ.get('SUPERSIZE_MEASURE_GZIP') == '1':
with gzip.open(path, 'wb') as f:
with _OpenGzipForWrite(path) as f:
_SaveSizeInfoToFile(size_info, f)
else:
# It is seconds faster to do gzip in a separate step. 6s -> 3.5s.
......@@ -199,7 +208,7 @@ def SaveSizeInfo(size_info, path):
logging.debug('Serialization complete. Gzipping...')
stringio.seek(0)
with gzip.open(path, 'wb') as f:
with _OpenGzipForWrite(path) as f:
shutil.copyfileobj(stringio, f)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment