WebUI: Delete preprocess_grit
Removing in favor of the more limited preprocess_if_expr. Change-Id: I2f7d237a6697489e6d45f72968e0d662f40d8bdc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574929 Commit-Queue: dpapad <dpapad@chromium.org> Reviewed-by: dpapad <dpapad@chromium.org> Cr-Commit-Position: refs/heads/master@{#834165}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
fbde314f81
commit
26188a2d65
@ -15,8 +15,6 @@ def RunUnittests(input_api, output_api):
|
||||
input_api,
|
||||
output_api, [
|
||||
input_api.os_path.join('grit', 'test_suite_all.py'),
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(),
|
||||
'preprocess_grit_test.py'),
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(),
|
||||
'preprocess_if_expr_test.py')
|
||||
],
|
||||
|
@ -1,53 +0,0 @@
|
||||
# Copyright 2020 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.
|
||||
|
||||
# This tool is no longer supported. Use preprocess_if_expr instead, which
|
||||
# also generates manifests and preprocesses <if expr> but does not also
|
||||
# inline <include>s (which are deprecated).
|
||||
|
||||
import("//build/config/python.gni")
|
||||
import("//tools/grit/grit_defines.gni")
|
||||
|
||||
template("preprocess_grit") {
|
||||
# TODO(crbug.com/1112471): Get this to run cleanly under Python 3.
|
||||
python2_action(target_name) {
|
||||
script = "//tools/grit/preprocess_grit.py"
|
||||
|
||||
if (defined(invoker.deps)) {
|
||||
deps = invoker.deps
|
||||
}
|
||||
|
||||
inputs = []
|
||||
outputs = []
|
||||
foreach(in_file, invoker.in_files) {
|
||||
inputs += [ invoker.in_folder + "/" + in_file ]
|
||||
outputs += [ invoker.out_folder + "/" + in_file ]
|
||||
}
|
||||
|
||||
args = [
|
||||
"--in-folder",
|
||||
rebase_path(invoker.in_folder, root_build_dir),
|
||||
"--out-folder",
|
||||
rebase_path(invoker.out_folder, root_build_dir),
|
||||
"--in-files",
|
||||
] + invoker.in_files + grit_defines
|
||||
|
||||
if (defined(invoker.defines)) {
|
||||
foreach(define, invoker.defines) {
|
||||
args += [
|
||||
"-D",
|
||||
define,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (defined(invoker.out_manifest)) {
|
||||
args += [
|
||||
"--out-manifest",
|
||||
rebase_path(invoker.out_manifest, root_build_dir),
|
||||
]
|
||||
outputs += [ invoker.out_manifest ]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
# Copyright 2020 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.
|
||||
|
||||
import argparse
|
||||
import errno
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import grit.format.html_inline
|
||||
import grit.node.base
|
||||
import grit.util
|
||||
|
||||
_CWD = os.getcwd()
|
||||
|
||||
|
||||
class PreprocessNode(grit.node.base.Node):
|
||||
def __init__(self):
|
||||
super(PreprocessNode, self).__init__()
|
||||
|
||||
def ProcessFile(self, filepath):
|
||||
return grit.format.html_inline.InlineToString(
|
||||
filepath,
|
||||
self,
|
||||
preprocess_only=True,
|
||||
allow_external_script=False,
|
||||
strip_whitespace=False,
|
||||
rewrite_function=None,
|
||||
filename_expansion_function=None)
|
||||
|
||||
def EvaluateCondition(self, expr):
|
||||
return grit.node.base.Node.EvaluateExpression(expr, self.defines,
|
||||
self.target_platform, {})
|
||||
|
||||
def SetDefines(self, defines):
|
||||
self.defines = defines
|
||||
|
||||
def SetTargetPlatform(self, target_platform):
|
||||
self.target_platform = target_platform
|
||||
|
||||
@staticmethod
|
||||
def Construct(defines, target_platform):
|
||||
node = PreprocessNode()
|
||||
node.SetDefines(defines)
|
||||
node.SetTargetPlatform(target_platform or sys.platform)
|
||||
return node
|
||||
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--in-folder', required=True)
|
||||
parser.add_argument('--out-folder', required=True)
|
||||
parser.add_argument('--out-manifest')
|
||||
parser.add_argument('--in-files', required=True, nargs="*")
|
||||
parser.add_argument('-D', '--defines', nargs="*", action='append')
|
||||
parser.add_argument('-E', '--environment')
|
||||
parser.add_argument('-t', '--target')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
in_folder = os.path.normpath(os.path.join(_CWD, args.in_folder))
|
||||
out_folder = os.path.normpath(os.path.join(_CWD, args.out_folder))
|
||||
|
||||
defines = {}
|
||||
for define_arg in args.defines:
|
||||
define, = define_arg
|
||||
name, val = grit.util.ParseDefine(define)
|
||||
defines[name] = val
|
||||
|
||||
node = PreprocessNode.Construct(defines, args.target)
|
||||
|
||||
for input_file in args.in_files:
|
||||
output = node.ProcessFile(os.path.join(in_folder, input_file))
|
||||
|
||||
out_path = os.path.join(out_folder, input_file)
|
||||
out_dir = os.path.dirname(out_path)
|
||||
assert out_dir.startswith(out_folder), \
|
||||
'Cannot preprocess files to locations not under %s.' % out_dir
|
||||
try:
|
||||
os.makedirs(out_dir)
|
||||
except OSError as e:
|
||||
# Ignore directory exists errors. This can happen if two build rules
|
||||
# for overlapping directories hit the makedirs line at the same time.
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
with io.open(out_path, mode='wb') as f:
|
||||
f.write(output.encode('utf-8'))
|
||||
|
||||
if args.out_manifest:
|
||||
manifest_data = {}
|
||||
manifest_data['base_dir'] = '%s' % args.out_folder
|
||||
manifest_data['files'] = args.in_files
|
||||
manifest_file = open(
|
||||
os.path.normpath(os.path.join(_CWD, args.out_manifest)), 'wb')
|
||||
json.dump(manifest_data, manifest_file)
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
@ -1,49 +0,0 @@
|
||||
# Copyright 2020 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.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import preprocess_grit
|
||||
|
||||
_HERE_DIR = os.path.dirname(__file__)
|
||||
|
||||
|
||||
class PreprocessGritTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self._out_folder = None
|
||||
|
||||
def tearDown(self):
|
||||
if self._out_folder:
|
||||
shutil.rmtree(self._out_folder)
|
||||
|
||||
def _read_out_file(self, file_name):
|
||||
assert self._out_folder
|
||||
return open(os.path.join(self._out_folder, file_name), 'r').read()
|
||||
|
||||
def _run_test(self, defines, file_name):
|
||||
assert not self._out_folder
|
||||
self._out_folder = tempfile.mkdtemp(dir=_HERE_DIR)
|
||||
preprocess_grit.main([
|
||||
'--in-folder',
|
||||
os.path.join(_HERE_DIR, 'preprocess_tests'),
|
||||
'--out-folder',
|
||||
self._out_folder,
|
||||
'--in-files',
|
||||
file_name,
|
||||
] + defines)
|
||||
|
||||
def testPreprocess(self):
|
||||
self._run_test(['-D', 'foo', '-D', 'bar'], 'test_with_ifexpr.js')
|
||||
actual = self._read_out_file('test_with_ifexpr.js')
|
||||
self.assertIn('I should be included in HTML', actual)
|
||||
self.assertIn('I should be included in JS', actual)
|
||||
self.assertNotIn('I should be excluded from HTML', actual)
|
||||
self.assertNotIn('I should be excluded from JS', actual)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user