Commit 1b4225a7 authored by Hector Carmona's avatar Hector Carmona Committed by Commit Bot

Revert "Add brotli compression to grit"

This reverts commit a0d64f3d.

Reason for revert: Suspecting this CL of breaking generate_build_files step in Mac ASan 64 Builder.

First failure here: https://ci.chromium.org/p/chromium/builders/ci/Mac%20ASan%2064%20Builder/86877

Original change's description:
> Add brotli compression to grit
> 
> -Add the "compress='brotli'" flag option in grdp files
> -Grit will now automatically brotli compress if flag is included
> -Previous Cl that was split into this one:
> https://chromium-review.googlesource.com/c/chromium/src/+/1660352
> 
> 
> Bug: 826858
> Change-Id: I010ad1650394e4bdd58e066486b161cf74f2fff5
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1692234
> Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#675763}

TBR=dbeam@chromium.org,dpapad@chromium.org,agrieve@chromium.org,tiborg@chromium.org,smaier@chromium.org,jacqueschen@google.com

Change-Id: I724ed738b56529fe4b4ac1c2ad3e0b9adbee9671
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 826858
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1693809Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675839}
parent a889847f
......@@ -28,7 +28,6 @@
../grit/grit/lazy_re.py
../grit/grit/node/__init__.py
../grit/grit/node/base.py
../grit/grit/node/brotli_util.py
../grit/grit/node/include.py
../grit/grit/node/message.py
../grit/grit/node/misc.py
......
......@@ -15,8 +15,3 @@ ENCODING_CHECK = u'm\u00f6l'
CONSTANT_LANGUAGE = 'x_constant'
FAKE_BIDI = 'fake-bidi'
# Magic number added to the header of resources brotli compressed by grit. Used
# to easily identify resources as being brotli compressed. See
# ui/base/resource/resource_bundle.h for decompression usage.
BROTLI_CONST = '\x1e\x9b'
\ No newline at end of file
......@@ -7,17 +7,13 @@
import ast
import os
import struct
import subprocess
import sys
import types
from xml.sax import saxutils
from grit import constants
from grit import clique
from grit import exception
from grit import util
from grit.node import brotli_util
import grit.format.gzip_string
......@@ -606,34 +602,18 @@ class Node(object):
Args:
data: The data to compressed.
Returns:
The data in gzipped or brotli compressed format. If the format was unknown
then this returns the data uncompressed.
The data in compressed format. If the format was unknown then this returns
the data uncompressed.
'''
if self.attrs.get('compress') == 'gzip':
# We only use rsyncable compression on Linux.
# We exclude ChromeOS since ChromeOS bots are Linux based but do not have
# the --rsyncable option built in for gzip. See crbug.com/617950.
if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines:
return grit.format.gzip_string.GzipStringRsyncable(data)
return grit.format.gzip_string.GzipString(data)
elif self.attrs.get('compress') == 'brotli':
# The length of the uncompressed data as 8 bytes little-endian.
size_bytes = struct.pack("<q", len(data))
data = brotli_util.BrotliCompress(data)
# BROTLI_CONST is prepended to brotli decompressed data in order to
# easily check if a resource has been brotli compressed.
# The length of the uncompressed data is also appended to the start,
# truncated to 6 bytes, little-endian. size_bytes is 8 bytes,
# need to truncate further to 6.
formatter = '%ds %dx %ds' % (6, 2, len(size_bytes)-8)
return constants.BROTLI_CONST + b''.join(struct.unpack(formatter, size_bytes)) + data
elif self.attrs.get('compress') == 'false':
if self.attrs.get('compress') != 'gzip':
return data
else:
raise Exception('Invalid value for compression')
# We only use rsyncable compression on Linux.
# We exclude ChromeOS since ChromeOS bots are Linux based but do not have
# the --rsyncable option built in for gzip. See crbug.com/617950.
if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines:
return grit.format.gzip_string.GzipStringRsyncable(data)
return grit.format.gzip_string.GzipString(data)
class ContentNode(Node):
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Framework for compressing resources using Brotli."""
import subprocess
__brotli_executable = None
def SetBrotliCommand(brotli):
# brotli is a list. In production it contains the path to the Brotli executable.
# During testing it contains [python, mock_brotli.py] for testing on Windows.
global __brotli_executable
__brotli_executable = brotli
def BrotliCompress(data):
if not __brotli_executable:
raise Exception('__brotli_executable not defined!')
compress = subprocess.Popen(__brotli_executable + ['-', '-f'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return compress.communicate(data)[0]
#!/usr/bin/env python
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Mock Brotli Executable for testing purposes."""
import sys
sys.stdout.write('This has been mock compressed!')
......@@ -17,11 +17,8 @@ import platform
import tempfile
import unittest
import StringIO
import struct
from grit import constants
from grit import util
from grit.node import brotli_util
from grit.node import empty
from grit.node import misc
from grit.node import structure
......@@ -107,57 +104,27 @@ class StructureUnittest(unittest.TestCase):
<structure name="TEST_TXT" file="test_text.txt"
compress="gzip" type="chrome_html" />
</structures>''', base_dir=test_data_root)
node, = root.GetChildrenOfType(structure.StructureNode)
node.RunPreSubstitutionGatherer()
compressed = node.GetDataPackValue(lang='en', encoding=1)
struct, = root.GetChildrenOfType(structure.StructureNode)
struct.RunPreSubstitutionGatherer()
compressed = struct.GetDataPackValue(lang='en', encoding=1)
decompressed_data = zlib.decompress(compressed, 16 + zlib.MAX_WBITS)
self.assertEqual(util.ReadFile(
os.path.join(test_data_root, 'test_text.txt'), util.BINARY),
os.path.join(test_data_root, "test_text.txt"), util.BINARY),
decompressed_data)
def testCompressBrotli(self):
test_data_root = util.PathFromRoot('grit/testdata')
root = util.ParseGrdForUnittest(
'''
<structures>
<structure name="TEST_TXT" file="test_text.txt"
compress="brotli" type="chrome_html" />
</structures>''',
base_dir=test_data_root)
node, = root.GetChildrenOfType(structure.StructureNode)
node.RunPreSubstitutionGatherer()
# Using the mock brotli decompression executable.
brotli_util.SetBrotliCommand([sys.executable,
os.path.join(os.path.dirname(__file__),
'mock_brotli.py')])
compressed = node.GetDataPackValue(lang='en', encoding=1)
# Assert that the first two bytes in compressed format is BROTLI_CONST.
self.assertEqual(constants.BROTLI_CONST, compressed[0:2])
# Compare the actual size of the uncompressed test data with
# the size appended during compression.
actual_size = len(util.ReadFile(
os.path.join(test_data_root, 'test_text.txt'), util.BINARY))
uncompress_size = struct.unpack('<i', compressed[2:6])[0]
uncompress_size += struct.unpack('<h', compressed[6:8])[0] << 4*8
self.assertEqual(actual_size, uncompress_size)
self.assertEqual('This has been mock compressed!', compressed[8:])
def testNotCompressed(self):
test_data_root = util.PathFromRoot('grit/testdata')
root = util.ParseGrdForUnittest('''
<structures>
<structure name="TEST_TXT" file="test_text.txt" type="chrome_html" />
</structures>''', base_dir=test_data_root)
node, = root.GetChildrenOfType(structure.StructureNode)
node.RunPreSubstitutionGatherer()
data = node.GetDataPackValue(lang='en', encoding=1)
struct, = root.GetChildrenOfType(structure.StructureNode)
struct.RunPreSubstitutionGatherer()
data = struct.GetDataPackValue(lang='en', encoding=1)
self.assertEqual(util.ReadFile(
os.path.join(test_data_root, 'test_text.txt'), util.BINARY), data)
os.path.join(test_data_root, "test_text.txt"), util.BINARY), data)
if __name__ == '__main__':
......
......@@ -16,7 +16,6 @@ from grit import grd_reader
from grit import shortcuts
from grit import util
from grit.format import minifier
from grit.node import brotli_util
from grit.node import include
from grit.node import message
from grit.node import structure
......@@ -132,10 +131,6 @@ Options:
minified Javascript to standard output. A non-zero exit
status will be taken as indicating failure.
--brotli The full path to the brotli executable generated by
third_party/brotli/BUILD.gn, required if any entries use
compress="brotli".
Conditional inclusion of resources only affects the output of files which
control which resources get linked into a binary, e.g. it affects .rc files
meant for compilation but it does not affect resource header files (that define
......@@ -161,13 +156,16 @@ are exported to translation interchange files (e.g. XMB files), etc.
depend_on_stamp = False
js_minifier = None
replace_ellipsis = True
brotli = None
(own_opts, args) = getopt.getopt(
args, 'a:p:o:D:E:f:w:t:',
('depdir=', 'depfile=', 'assert-file-list=', 'help',
'output-all-resource-defines', 'no-output-all-resource-defines',
'no-replace-ellipsis', 'depend-on-stamp', 'js-minifier=',
'write-only-new=', 'whitelist-support', 'brotli='))
(own_opts, args) = getopt.getopt(args, 'a:p:o:D:E:f:w:t:',
('depdir=','depfile=','assert-file-list=',
'help',
'output-all-resource-defines',
'no-output-all-resource-defines',
'no-replace-ellipsis',
'depend-on-stamp',
'js-minifier=',
'write-only-new=',
'whitelist-support'))
for (key, val) in own_opts:
if key == '-a':
assert_output_files.append(val)
......@@ -207,8 +205,6 @@ are exported to translation interchange files (e.g. XMB files), etc.
js_minifier = val
elif key == '--whitelist-support':
whitelist_support = True
elif key == '--brotli':
brotli = [os.path.abspath(val)]
elif key == '--help':
self.ShowUsage()
sys.exit(0)
......@@ -231,8 +227,6 @@ are exported to translation interchange files (e.g. XMB files), etc.
if js_minifier:
minifier.SetJsMinifier(js_minifier)
brotli_util.SetBrotliCommand(brotli)
self.write_only_new = write_only_new
self.res = grd_reader.Parse(opts.input,
......
......@@ -348,16 +348,6 @@ template("grit") {
depfile = "$depfile_dir/${grit_output_name}_stamp.d"
outputs = [ "${depfile}.stamp" ] + grit_outputs + pak_info_outputs
b_tool = "//third_party/brotli:brotli" + "($host_toolchain)"
brotli_executable = get_label_info(b_tool, "root_out_dir") + "/" +
get_label_info(b_tool, "name")
if (host_os == "win") {
brotli_executable += ".exe"
}
inputs += [ brotli_executable ]
args = [
"-i",
source_path,
......@@ -370,8 +360,6 @@ template("grit") {
rebase_path(depfile, root_build_dir),
"--write-only-new=1",
"--depend-on-stamp",
"--brotli",
rebase_path(brotli_executable, root_build_dir),
] + grit_defines
# Add extra defines with -D flags.
......@@ -453,7 +441,6 @@ template("grit") {
}
deps = [
"//third_party/brotli:brotli($host_toolchain)",
"//tools/grit:grit_sources",
]
if (defined(invoker.deps)) {
......
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