Commit 2091ad5f authored by rbpotter's avatar rbpotter Committed by Commit Bot

WebUI: Generate manifest files from optimize_webui

Change optimize_webui to generate a manifest file when an |out_manifest|
argument is provided.

Started from:
https://chromium-review.googlesource.com/c/chromium/src/+/2443211
by dpapad@

Bug: 1132403
Change-Id: Ia80c4d2c004ec4414c500c407e2d2c8d187ff847
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463962Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815777}
parent 08ab4773
...@@ -86,6 +86,14 @@ template("optimize_webui") { ...@@ -86,6 +86,14 @@ template("optimize_webui") {
inputs += [ "//chrome/browser/resources/tools/rollup_plugin.js" ] inputs += [ "//chrome/browser/resources/tools/rollup_plugin.js" ]
args += [ "--js_module_in_files" ] + invoker.js_module_in_files args += [ "--js_module_in_files" ] + invoker.js_module_in_files
} }
if (defined(invoker.out_manifest)) {
args += [
"--out-manifest",
rebase_path(invoker.out_manifest, root_build_dir),
]
outputs += [ invoker.out_manifest ]
}
} }
} }
......
...@@ -380,6 +380,7 @@ def main(argv): ...@@ -380,6 +380,7 @@ def main(argv):
parser.add_argument('--js_out_files', nargs='*', required=True) parser.add_argument('--js_out_files', nargs='*', required=True)
parser.add_argument('--out_folder', required=True) parser.add_argument('--out_folder', required=True)
parser.add_argument('--js_module_in_files', nargs='*') parser.add_argument('--js_module_in_files', nargs='*')
parser.add_argument('--out-manifest')
parser.add_argument('--gen_dir_relpath', default='gen', help='Path of the ' parser.add_argument('--gen_dir_relpath', default='gen', help='Path of the '
'gen directory relative to the out/. If running in the default ' 'gen directory relative to the out/. If running in the default '
'toolchain, the path is gen, otherwise $toolchain_name/gen') 'toolchain, the path is gen, otherwise $toolchain_name/gen')
...@@ -411,6 +412,16 @@ def main(argv): ...@@ -411,6 +412,16 @@ def main(argv):
'polymer-bundler could not find files for the following URLs:\n' + 'polymer-bundler could not find files for the following URLs:\n' +
'\n'.join(manifest['_missing'])) '\n'.join(manifest['_missing']))
# Output a manifest file that will be used to auto-generate a grd file later.
if args.out_manifest:
manifest_data = {}
manifest_data['base_dir'] = '%s' % args.out_folder
manifest_data['files'] = manifest.keys()
manifest_file = open(
os.path.normpath(os.path.join(_CWD, args.out_manifest)), 'wb')
json.dump(manifest_data, manifest_file)
_update_dep_file(args.input, args, manifest) _update_dep_file(args.input, args, manifest)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import json
import optimize_webui import optimize_webui
import os import os
import shutil import shutil
...@@ -10,14 +11,15 @@ import tempfile ...@@ -10,14 +11,15 @@ import tempfile
import unittest import unittest
_CWD = os.getcwd()
_HERE_DIR = os.path.dirname(__file__) _HERE_DIR = os.path.dirname(__file__)
class OptimizeWebUiTest(unittest.TestCase): class OptimizeWebUiTest(unittest.TestCase):
def setUp(self): def setUp(self):
self._out_folder = None
self._tmp_dirs = [] self._tmp_dirs = []
self._tmp_src_dir = None self._tmp_src_dir = None
self._out_folder = self._create_tmp_dir()
def tearDown(self): def tearDown(self):
for tmp_dir in self._tmp_dirs: for tmp_dir in self._tmp_dirs:
...@@ -45,8 +47,6 @@ class OptimizeWebUiTest(unittest.TestCase): ...@@ -45,8 +47,6 @@ class OptimizeWebUiTest(unittest.TestCase):
return open(os.path.join(self._out_folder, file_name), 'r').read() return open(os.path.join(self._out_folder, file_name), 'r').read()
def _run_optimize(self, input_args): def _run_optimize(self, input_args):
assert not self._out_folder
self._out_folder = self._create_tmp_dir()
# TODO(dbeam): make it possible to _run_optimize twice? Is that useful? # TODO(dbeam): make it possible to _run_optimize twice? Is that useful?
args = input_args + [ args = input_args + [
'--depfile', os.path.join(self._out_folder, 'depfile.d'), '--depfile', os.path.join(self._out_folder, 'depfile.d'),
...@@ -209,6 +209,7 @@ import './element_in_dir/element_in_dir.js'; ...@@ -209,6 +209,7 @@ import './element_in_dir/element_in_dir.js';
args = [ args = [
'--js_module_in_files', 'ui.js', 'lazy.js', '--js_module_in_files', 'ui.js', 'lazy.js',
'--js_out_files', 'ui.rollup.js', 'lazy.rollup.js', 'shared.rollup.js', '--js_out_files', 'ui.rollup.js', 'lazy.rollup.js', 'shared.rollup.js',
'--out-manifest', os.path.join(self._out_folder, 'out_manifest.json'),
] ]
self._run_optimize(args) self._run_optimize(args)
...@@ -234,5 +235,15 @@ import './element_in_dir/element_in_dir.js'; ...@@ -234,5 +235,15 @@ import './element_in_dir/element_in_dir.js';
depfile_d = self._read_out_file('depfile.d') depfile_d = self._read_out_file('depfile.d')
self.assertIn('lazy_element.js', depfile_d) self.assertIn('lazy_element.js', depfile_d)
manifest = json.loads(self._read_out_file('out_manifest.json'))
self.assertEquals(3, len(manifest['files']))
self.assertTrue('lazy.rollup.js' in manifest['files'])
self.assertTrue('ui.rollup.js' in manifest['files'])
self.assertTrue('shared.rollup.js' in manifest['files'])
self.assertEquals(
os.path.relpath(self._out_folder, _CWD).replace('\\', '/'),
os.path.relpath(manifest['base_dir'], _CWD).replace('\\', '/'))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
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