Commit 0a9a940c authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files app: Generate main_modules.html for running as JS modules

Bug: 1133186
Change-Id: I65e1a8acdf573ce233b9d78bcdc213f12cb1109e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2639431
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845530}
parent 3de63e30
......@@ -374,6 +374,7 @@ preprocess_if_expr("preprocess_generated") {
"//ui/file_manager/base/js:modulize",
"//ui/file_manager/externs:modulize",
"//ui/file_manager/externs/background:modulize",
"//ui/file_manager/file_manager:gen_main_html",
"//ui/file_manager/file_manager/background/js:modulize",
"//ui/file_manager/file_manager/common/js:modulize",
"//ui/file_manager/file_manager/cws_widget:modulize",
......@@ -408,8 +409,9 @@ generate_grd("build_grd") {
"file_manager/foreground/elements/files_toggle_ripple.m.js",
"file_manager/foreground/js/deferred_elements.m.rollup.js",
"file_manager/foreground/js/main.m.rollup.js",
"file_manager/foreground/js/shared.m.rollup.js",
"file_manager/foreground/js/metadata_dispatcher.m.rollup.js",
"file_manager/foreground/js/shared.m.rollup.js",
"file_manager/main_modules.html",
"video_player/js/main.m.rollup.js",
"video_player/js/main_background.m.rollup.js",
......
# Copyright 2021 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.
#
# Lint as: python3
"""Generate Files app main_modules.html based on the main.html"""
from __future__ import print_function
import fileinput
import optparse
import os
import shutil
import sys
_MAIN = ' <script type="module" src="foreground/js/main.m.js"></script>\n'
def GenerateHtml(source, target):
"""Copy source file to target with edits, then add BUILD time stamp."""
# Copy source (main.html) file to the target (main.html) file.
shutil.copyfile(source, target)
# Edit the target file.
main_included = False
for line in fileinput.input(target, inplace=True):
# Ignore all <script> and <link rel="import">.
if '<script' in line or 'rel="import"' in line:
if main_included:
continue
else:
line = ''
sys.stdout.write(_MAIN)
main_included = True
sys.stdout.write(line)
# Create a BUILD time stamp for the target file.
open(target + '.stamp', 'a').close()
def main(args):
parser = optparse.OptionParser()
parser.add_option('--source', help='Files app main.html source file.')
parser.add_option('--target', help='Target fianl main.html for output.')
options, _ = parser.parse_args(args)
if options.source and options.target:
GenerateHtml(options.source, options.target)
return
raise ValueError('Usage: all arguments are required.')
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
......@@ -4,6 +4,24 @@
import("//ui/webui/resources/tools/generate_grd.gni")
action("gen_main_html") {
inputs = [ "main.html" ]
script = "//ui/file_manager/base/gn/gen_main_html.py"
args = [
"--source",
rebase_path("//ui/file_manager/file_manager/main.html", root_build_dir),
"--target",
rebase_path("$target_gen_dir/main_modules.html", root_build_dir),
]
outputs = [
"$target_gen_dir/main_modules.html",
"$target_gen_dir/main_modules.html.stamp",
]
}
generated_static_grdp = "$target_gen_dir/static_resources.grdp"
generate_grd("build_static_grdp") {
......
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