Commit f972406b authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

Make optimize_webui work for non-default toolchain

This CL makes the optimize_webui work with non-default toolchain by
avoiding assuming that the gen directory will always be out/gen.

Bug: 1129223
Change-Id: I575474c2ef983008979329706a029115fe34c9c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419717
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#814032}
parent b40b3733
......@@ -57,6 +57,8 @@ template("optimize_webui") {
rebase_path(target_gen_dir, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--gen_dir_relpath",
rebase_path(root_gen_dir, root_build_dir),
]
args += [ "--js_out_files" ] + invoker.js_out_files
......
......@@ -165,7 +165,7 @@ def _update_dep_file(in_folder, args, manifest):
# pass it information about the location of the directories and files to exclude
# from the bundle.
def _generate_rollup_config(tmp_out_dir, path_to_plugin, in_path, host,
excludes):
excludes, gen_dir_relpath):
rollup_config_file = os.path.join(tmp_out_dir, 'rollup.config.js')
excludes_string = '[\'' + '\', \''.join(excludes) + '\']'
with open(rollup_config_file, 'w') as f:
......@@ -174,7 +174,7 @@ def _generate_rollup_config(tmp_out_dir, path_to_plugin, in_path, host,
f.write('export default({\n')
f.write(' plugins: [ plugin(\'%s\', \'%s\', \'%s\', \'%s\', %s) ]\n' % (
_SRC_PATH.replace('\\', '/'),
os.path.join(_CWD, 'gen').replace('\\', '/'),
os.path.join(_CWD, gen_dir_relpath).replace('\\', '/'),
in_path.replace('\\', '/'), host, excludes_string))
f.write('});')
f.close()
......@@ -213,7 +213,8 @@ def _bundle_v3(tmp_out_dir, in_path, out_path, manifest_out_path, args,
path_to_plugin = os.path.join(
os.path.abspath(_HERE_PATH), 'tools', 'rollup_plugin.js')
rollup_config_file = _generate_rollup_config(tmp_out_dir, path_to_plugin,
in_path, args.host, excludes)
in_path, args.host, excludes,
args.gen_dir_relpath)
rollup_args = [os.path.join(in_path, f) for f in args.js_module_in_files]
# Confirm names are as expected. This is necessary to avoid having to replace
......@@ -379,6 +380,9 @@ def main(argv):
parser.add_argument('--js_out_files', nargs='*', required=True)
parser.add_argument('--out_folder', required=True)
parser.add_argument('--js_module_in_files', nargs='*')
parser.add_argument('--gen_dir_relpath', default='gen', help='Path of the '
'gen directory relative to the out/. If running in the default '
'toolchain, the path is gen, otherwise $toolchain_name/gen')
args = parser.parse_args(argv)
# Either JS module input files (for Polymer 3) or HTML input and output files
......
......@@ -81,13 +81,13 @@ import './element_in_dir/element_in_dir.js';
<script type="module" src="ui.js"></script>
''')
def _write_v3_files_with_resources_to_src_dir(self):
def _write_v3_files_with_resources_to_src_dir(self, gen_dir='gen'):
resources_path = os.path.join(
_HERE_DIR.replace('\\', '/'), 'gen', 'ui', 'webui', 'resources',
_HERE_DIR.replace('\\', '/'), gen_dir, 'ui', 'webui', 'resources',
'preprocessed', 'js', 'fake_resource.js')
os.makedirs(os.path.dirname(resources_path))
self._tmp_dirs.append('gen')
self._tmp_dirs.append(gen_dir)
with open(resources_path, 'w') as tmp_file:
tmp_file.write("alert('hello from shared resource');")
......@@ -179,6 +179,24 @@ import './element_in_dir/element_in_dir.js';
'../gen/ui/webui/resources/preprocessed/js/fake_resource.js'),
depfile_d)
def testV3OptimizeWithResourcesInNonDefaultToolchain(self):
self._write_v3_files_with_resources_to_src_dir(gen_dir='ash_clang_64/gen')
args = [
'--js_module_in_files', 'ui.js',
'--js_out_files', 'ui.rollup.js',
'--gen_dir_relpath', 'ash_clang_64/gen',
]
self._run_optimize(args)
ui_rollup_js = self._read_out_file('ui.rollup.js')
self.assertIn('hello from shared resource', ui_rollup_js)
depfile_d = self._read_out_file('depfile.d')
self.assertIn(
os.path.normpath(
'../ash_clang_64/gen/ui/webui/resources/preprocessed/js/'
'fake_resource.js'), depfile_d)
def testV3MultiBundleOptimize(self):
self._write_v3_files_to_src_dir()
self._write_file_to_src_dir('lazy_element.js',
......
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