Commit 03ca98f1 authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Auto-generate cr_elements/ resources grdp files.

 - Add new resource_path_prefix option to generate_grd(), which
   makes it possible to generate grdp files in subfolders of the
   parent grd file.
 - Move preprocess_grit() for cr_elements/ under cr_elements/BUILD.gn
 - Add new generate_grd() target in cr_elements/
 - Remove now obsolete alias in shared_resources_data_source.cc.

Bug: 1132403
Change-Id: Ia1920b2eb799bcce325bf0087c9f3450b153b816
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2494781
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821183}
parent 38a3ea1d
......@@ -63,7 +63,6 @@ const std::map<std::string, std::string> CreatePathPrefixAliasesMap() {
{"../../views/resources/default_100_percent/common/", "images/apps/"},
{"../../views/resources/default_200_percent/common/", "images/2x/apps/"},
{"../../webui/resources/cr_components/", "cr_components/"},
{"../../webui/resources/cr_elements/", "cr_elements/"},
{"@out_folder@/gen/ui/webui/resources/", ""},
#if defined(OS_ANDROID)
// This is a temporary fix for `target_cpu = "arm64"`. See the bug for
......
......@@ -115,4 +115,5 @@ generate_grd("build_grdp") {
"polymer2/polymer-extracted.js|polymer/polymer-extracted.js",
"polymer2/polymer.html|polymer/polymer.html",
]
resource_path_prefix = "polymer/v1_0"
}
......@@ -68,4 +68,5 @@ generate_grd("build_grdp") {
]
}
input_files_base_dir = rebase_path("./components-chromium/", "//")
resource_path_prefix = "polymer/v3_0"
}
......@@ -9,5 +9,6 @@ generate_grd("build_grdp") {
out_grd = "$target_gen_dir/${grd_prefix}_resources.grdp"
input_files = [ "web-animations-next-lite.min.js" ]
input_files_base_dir = rebase_path("./sources", "//")
resource_path_rewrites = [ "web-animations-next-lite.min.js|polymer/v1_0/web-animations-js/web-animations-next-lite.min.js" ]
resource_path_rewrites = [ "web-animations-next-lite.min.js|web-animations-js/web-animations-next-lite.min.js" ]
resource_path_prefix = "polymer/v1_0"
}
......@@ -646,7 +646,7 @@
"structures": [3820],
},
"<(SHARED_INTERMEDIATE_DIR)/ui/webui/resources/webui_generated_resources.grd": {
"META": {"sizes": {"includes": [200]}},
"META": {"sizes": {"includes": [300]}},
"includes": [3830],
},
"weblayer/weblayer_resources.grd": {
......
......@@ -18,12 +18,14 @@ if (include_polymer) {
grd_prefix = "webui_generated"
out_grd = "$target_gen_dir/${grd_prefix}_resources.grd"
deps = [
"cr_elements:build_grdp",
"//third_party/polymer/v1_0:build_grdp",
"//third_party/polymer/v3_0:build_grdp",
]
grdp_files = [
"$root_gen_dir/third_party/polymer/v1_0/polymer_1_0_resources.grdp",
"$root_gen_dir/third_party/polymer/v3_0/polymer_3_0_resources.grdp",
"$root_gen_dir/ui/webui/resources/cr_elements/cr_elements_resources.grdp",
]
if (is_chromeos) {
......@@ -37,6 +39,7 @@ group("preprocess") {
deps = [
":preprocess_generated",
":preprocess_src",
"cr_elements:preprocess",
]
}
......@@ -52,7 +55,6 @@ preprocess_grit("preprocess_src") {
if (include_polymer) {
in_files += [
"cr_elements/cr_splitter/cr_splitter.js",
"cr_components/certificate_manager/certificates_browser_proxy.js",
"cr_components/certificate_manager/certificate_manager_types.js",
"cr_components/certificate_manager/certificate_provisioning_browser_proxy.js",
......@@ -103,57 +105,6 @@ preprocess_grit("preprocess_generated") {
"cr_components/customize_themes/theme_icon.js",
"cr_components/managed_footnote/managed_footnote.m.js",
"cr_components/omnibox/cr_autocomplete_match_list.js",
"cr_elements/shared_vars_css.m.js",
"cr_elements/shared_style_css.m.js",
"cr_elements/search_highlight_style_css.m.js",
"cr_elements/md_select_css.m.js",
"cr_elements/icons.m.js",
"cr_elements/hidden_style_css.m.js",
"cr_elements/cr_scrollable_behavior.m.js",
"cr_elements/cr_page_host_style_css.m.js",
"cr_elements/cr_icons_css.m.js",
"cr_elements/cr_container_shadow_behavior.m.js",
"cr_elements/action_link_css.m.js",
"cr_elements/cr_grid/cr_grid.js",
"cr_elements/cr_menu_selector/cr_menu_selector.js",
"cr_elements/cr_view_manager/cr_view_manager.m.js",
"cr_elements/cr_toolbar/cr_toolbar_selection_overlay.m.js",
"cr_elements/cr_toolbar/cr_toolbar_search_field.m.js",
"cr_elements/cr_toolbar/cr_toolbar.m.js",
"cr_elements/cr_toggle/cr_toggle.m.js",
"cr_elements/cr_toast/cr_toast.m.js",
"cr_elements/cr_toast/cr_toast_manager.m.js",
"cr_elements/cr_tabs/cr_tabs.m.js",
"cr_elements/cr_slider/cr_slider.m.js",
"cr_elements/cr_search_field/cr_search_field.m.js",
"cr_elements/cr_search_field/cr_search_field_behavior.m.js",
"cr_elements/cr_radio_group/cr_radio_group.m.js",
"cr_elements/cr_radio_button/cr_radio_button_style_css.m.js",
"cr_elements/cr_radio_button/cr_radio_button.m.js",
"cr_elements/cr_radio_button/cr_radio_button_behavior.m.js",
"cr_elements/cr_radio_button/cr_card_radio_button.m.js",
"cr_elements/cr_profile_avatar_selector/cr_profile_avatar_selector.m.js",
"cr_elements/cr_profile_avatar_selector/cr_profile_avatar_selector_grid.m.js",
"cr_elements/cr_lottie/cr_lottie.m.js",
"cr_elements/cr_link_row/cr_link_row.m.js",
"cr_elements/cr_lazy_render/cr_lazy_render.m.js",
"cr_elements/cr_input/cr_input_style_css.m.js",
"cr_elements/cr_input/cr_input.m.js",
"cr_elements/cr_icon_button/cr_icon_button.m.js",
"cr_elements/cr_fingerprint/cr_fingerprint_progress_arc.m.js",
"cr_elements/cr_fingerprint/cr_fingerprint_icon.m.js",
"cr_elements/cr_expand_button/cr_expand_button.m.js",
"cr_elements/cr_drawer/cr_drawer.m.js",
"cr_elements/cr_dialog/cr_dialog.m.js",
"cr_elements/cr_checkbox/cr_checkbox.m.js",
"cr_elements/cr_button/cr_button.m.js",
"cr_elements/cr_action_menu/cr_action_menu.m.js",
"cr_elements/find_shortcut_behavior.m.js",
"cr_elements/policy/cr_policy_indicator_behavior.m.js",
"cr_elements/policy/cr_policy_indicator.m.js",
"cr_elements/policy/cr_policy_pref_behavior.m.js",
"cr_elements/policy/cr_policy_pref_indicator.m.js",
"cr_elements/policy/cr_tooltip_icon.m.js",
"js/i18n_behavior.m.js",
"js/list_property_update_behavior.m.js",
"js/search_highlight_utils.m.js",
......@@ -215,14 +166,6 @@ preprocess_grit("preprocess_generated") {
"cr_components/chromeos/quick_unlock/setup_pin_keyboard.m.js",
"cr_components/chromeos/smb_shares/add_smb_share_dialog.m.js",
"cr_components/chromeos/smb_shares/smb_browser_proxy.m.js",
"cr_elements/chromeos/cros_color_overrides.m.js",
"cr_elements/chromeos/cr_picture/cr_camera.m.js",
"cr_elements/chromeos/cr_picture/cr_picture_list.m.js",
"cr_elements/chromeos/cr_picture/cr_picture_pane.m.js",
"cr_elements/chromeos/cr_picture/cr_picture_types.m.js",
"cr_elements/chromeos/cr_picture/icons.m.js",
"cr_elements/chromeos/cr_picture/png.m.js",
"cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.m.js",
]
}
}
......
......@@ -3,10 +3,233 @@
# found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/preprocess_grit.gni")
import("//tools/polymer/html_to_js.gni")
import("//tools/polymer/polymer.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
import("//ui/webui/resources/tools/js_modulizer.gni")
preprocess_folder = "$target_gen_dir/../preprocessed/cr_elements"
preprocess_gen_manifest = "preprocessed_gen_manifest.json"
preprocess_polymer2_manifest = "preprocessed_polymer2_manifest.json"
preprocess_src_manifest = "preprocessed_src_manifest.json"
generate_grd("build_grdp") {
grd_prefix = "cr_elements"
out_grd = "$target_gen_dir/${grd_prefix}_resources.grdp"
deps = [ ":preprocess" ]
manifest_files = [
"$target_gen_dir/$preprocess_gen_manifest",
"$target_gen_dir/$preprocess_src_manifest",
"$target_gen_dir/$preprocess_polymer2_manifest",
]
resource_path_prefix = "cr_elements"
}
group("preprocess") {
public_deps = [
":preprocess_generated",
":preprocess_polymer2",
":preprocess_src",
]
}
preprocess_grit("preprocess_src") {
in_folder = "./"
out_folder = "$preprocess_folder"
out_manifest = "$target_gen_dir/$preprocess_src_manifest"
in_files = [ "cr_splitter/cr_splitter.js" ]
}
preprocess_grit("preprocess_polymer2") {
in_folder = "./"
out_folder = "$preprocess_folder"
out_manifest = "$target_gen_dir/$preprocess_polymer2_manifest"
in_files = [
"action_link_css.html",
"cr_action_menu/cr_action_menu.html",
"cr_action_menu/cr_action_menu.js",
"cr_button/cr_button.html",
"cr_button/cr_button.js",
"cr_checkbox/cr_checkbox.html",
"cr_checkbox/cr_checkbox.js",
"cr_container_shadow_behavior.html",
"cr_container_shadow_behavior.js",
"cr_dialog/cr_dialog.html",
"cr_dialog/cr_dialog.js",
"cr_drawer/cr_drawer.html",
"cr_drawer/cr_drawer.js",
"cr_expand_button/cr_expand_button.html",
"cr_expand_button/cr_expand_button.js",
"cr_fingerprint/cr_fingerprint_icon.html",
"cr_fingerprint/cr_fingerprint_progress_arc.html",
"cr_fingerprint/cr_fingerprint_progress_arc.js",
"cr_icon_button/cr_icon_button.html",
"cr_icon_button/cr_icon_button.js",
"cr_icons_css.html",
"cr_input/cr_input.html",
"cr_input/cr_input.js",
"cr_input/cr_input_style_css.html",
"cr_lazy_render/cr_lazy_render.html",
"cr_lazy_render/cr_lazy_render.js",
"cr_link_row/cr_link_row.html",
"cr_link_row/cr_link_row.js",
"cr_lottie/cr_lottie.html",
"cr_lottie/cr_lottie.js",
"cr_page_host_style_css.html",
"cr_profile_avatar_selector/cr_profile_avatar_selector_grid.html",
"cr_profile_avatar_selector/cr_profile_avatar_selector_grid.js",
"cr_profile_avatar_selector/cr_profile_avatar_selector.html",
"cr_profile_avatar_selector/cr_profile_avatar_selector.js",
"cr_radio_button/cr_card_radio_button.html",
"cr_radio_button/cr_card_radio_button.js",
"cr_radio_button/cr_radio_button_behavior.html",
"cr_radio_button/cr_radio_button_behavior.js",
"cr_radio_button/cr_radio_button.html",
"cr_radio_button/cr_radio_button.js",
"cr_radio_button/cr_radio_button_style_css.html",
"cr_radio_group/cr_radio_group.html",
"cr_radio_group/cr_radio_group.js",
"cr_scrollable_behavior.html",
"cr_scrollable_behavior.js",
"cr_search_field/cr_search_field_behavior.html",
"cr_search_field/cr_search_field_behavior.js",
"cr_search_field/cr_search_field.html",
"cr_search_field/cr_search_field.js",
"cr_slider/cr_slider.html",
"cr_slider/cr_slider.js",
"cr_tabs/cr_tabs.html",
"cr_tabs/cr_tabs.js",
"cr_toast/cr_toast.html",
"cr_toast/cr_toast.js",
"cr_toast/cr_toast_manager.html",
"cr_toast/cr_toast_manager.js",
"cr_toggle/cr_toggle.html",
"cr_toggle/cr_toggle.js",
"cr_toolbar/cr_toolbar.html",
"cr_toolbar/cr_toolbar.js",
"cr_toolbar/cr_toolbar_search_field.html",
"cr_toolbar/cr_toolbar_search_field.js",
"cr_toolbar/cr_toolbar_selection_overlay.html",
"cr_toolbar/cr_toolbar_selection_overlay.js",
"cr_view_manager/cr_view_manager.html",
"cr_view_manager/cr_view_manager.js",
"find_shortcut_behavior.html",
"find_shortcut_behavior.js",
"hidden_style_css.html",
"icons.html",
"md_select_css.html",
"policy/cr_policy_indicator_behavior.html",
"policy/cr_policy_indicator_behavior.js",
"policy/cr_policy_indicator.html",
"policy/cr_policy_indicator.js",
"policy/cr_policy_pref_behavior.html",
"policy/cr_policy_pref_behavior.js",
"policy/cr_policy_pref_indicator.html",
"policy/cr_policy_pref_indicator.js",
"policy/cr_tooltip_icon.html",
"policy/cr_tooltip_icon.js",
"search_highlight_style_css.html",
"shared_style_css.html",
"shared_vars_css.html",
]
if (is_chromeos) {
in_files += [
"chromeos/cros_color_overrides.html",
"chromeos/cr_picture/cr_camera.html",
"chromeos/cr_picture/cr_camera.js",
"chromeos/cr_picture/cr_picture_list.html",
"chromeos/cr_picture/cr_picture_list.js",
"chromeos/cr_picture/cr_picture_pane.html",
"chromeos/cr_picture/cr_picture_pane.js",
"chromeos/cr_picture/cr_picture_types.html",
"chromeos/cr_picture/cr_picture_types.js",
"chromeos/cr_picture/icons.html",
"chromeos/cr_picture/png.html",
"chromeos/cr_picture/png.js",
"cr_searchable_drop_down/cr_searchable_drop_down.html",
"cr_searchable_drop_down/cr_searchable_drop_down.js",
]
}
}
preprocess_grit("preprocess_generated") {
deps = [ ":polymer3_elements" ]
in_folder = target_gen_dir
out_folder = "$preprocess_folder"
out_manifest = "$target_gen_dir/$preprocess_gen_manifest"
in_files = [
"action_link_css.m.js",
"cr_action_menu/cr_action_menu.m.js",
"cr_button/cr_button.m.js",
"cr_checkbox/cr_checkbox.m.js",
"cr_container_shadow_behavior.m.js",
"cr_dialog/cr_dialog.m.js",
"cr_drawer/cr_drawer.m.js",
"cr_expand_button/cr_expand_button.m.js",
"cr_fingerprint/cr_fingerprint_icon.m.js",
"cr_fingerprint/cr_fingerprint_progress_arc.m.js",
"cr_grid/cr_grid.js",
"cr_icon_button/cr_icon_button.m.js",
"cr_icons_css.m.js",
"cr_input/cr_input.m.js",
"cr_input/cr_input_style_css.m.js",
"cr_lazy_render/cr_lazy_render.m.js",
"cr_link_row/cr_link_row.m.js",
"cr_lottie/cr_lottie.m.js",
"cr_menu_selector/cr_menu_selector.js",
"cr_page_host_style_css.m.js",
"cr_profile_avatar_selector/cr_profile_avatar_selector_grid.m.js",
"cr_profile_avatar_selector/cr_profile_avatar_selector.m.js",
"cr_radio_button/cr_card_radio_button.m.js",
"cr_radio_button/cr_radio_button_behavior.m.js",
"cr_radio_button/cr_radio_button.m.js",
"cr_radio_button/cr_radio_button_style_css.m.js",
"cr_radio_group/cr_radio_group.m.js",
"cr_scrollable_behavior.m.js",
"cr_search_field/cr_search_field_behavior.m.js",
"cr_search_field/cr_search_field.m.js",
"cr_slider/cr_slider.m.js",
"cr_tabs/cr_tabs.m.js",
"cr_toast/cr_toast_manager.m.js",
"cr_toast/cr_toast.m.js",
"cr_toggle/cr_toggle.m.js",
"cr_toolbar/cr_toolbar.m.js",
"cr_toolbar/cr_toolbar_search_field.m.js",
"cr_toolbar/cr_toolbar_selection_overlay.m.js",
"cr_view_manager/cr_view_manager.m.js",
"find_shortcut_behavior.m.js",
"hidden_style_css.m.js",
"icons.m.js",
"md_select_css.m.js",
"mwb_shared_icons.js",
"mwb_shared_style.js",
"mwb_shared_vars.js",
"policy/cr_policy_indicator_behavior.m.js",
"policy/cr_policy_indicator.m.js",
"policy/cr_policy_pref_behavior.m.js",
"policy/cr_policy_pref_indicator.m.js",
"policy/cr_tooltip_icon.m.js",
"search_highlight_style_css.m.js",
"shared_style_css.m.js",
"shared_vars_css.m.js",
]
if (is_chromeos) {
in_files += [
"chromeos/cros_color_overrides.m.js",
"chromeos/cr_picture/cr_camera.m.js",
"chromeos/cr_picture/cr_picture_list.m.js",
"chromeos/cr_picture/cr_picture_pane.m.js",
"chromeos/cr_picture/cr_picture_types.m.js",
"chromeos/cr_picture/icons.m.js",
"chromeos/cr_picture/png.m.js",
"cr_searchable_drop_down/cr_searchable_drop_down.m.js",
]
}
}
group("closure_compile") {
deps = [
":cr_elements_resources",
......
This diff is collapsed.
This diff is collapsed.
......@@ -45,5 +45,11 @@ template("generate_grd") {
if (defined(invoker.resource_path_rewrites)) {
args += [ "--resource-path-rewrites" ] + invoker.resource_path_rewrites
}
if (defined(invoker.resource_path_prefix)) {
args += [
"--resource-path-prefix",
invoker.resource_path_prefix,
]
}
}
}
......@@ -77,7 +77,7 @@ GRDP_END_TEMPLATE = '</grit-part>\n'
# Generates an <include .... /> row for the given file.
def _generate_include_row(grd_prefix, filename, pathname, \
resource_path_rewrites):
resource_path_rewrites, resource_path_prefix):
name_suffix = filename.upper().replace('/', '_').replace('.', '_'). \
replace('-', '_')
name = 'IDR_%s_%s' % (grd_prefix.upper(), name_suffix)
......@@ -88,11 +88,8 @@ def _generate_include_row(grd_prefix, filename, pathname, \
resource_path = resource_path_rewrites[filename] \
if filename in resource_path_rewrites else filename
# Rewrite resource_path for third_party/polymer/.
if 'third_party/polymer/v1_0/components-chromium/' in pathname:
resource_path = 'polymer/v1_0/' + resource_path
if 'third_party/polymer/v3_0/components-chromium/' in pathname:
resource_path = 'polymer/v3_0/' + resource_path
if resource_path_prefix != None:
resource_path = resource_path_prefix + '/' + resource_path
return GRD_INCLUDE_TEMPLATE.format(
file=pathname,
......@@ -115,6 +112,7 @@ def main(argv):
parser.add_argument('--input-files-base-dir')
parser.add_argument('--grdp-files', nargs="*")
parser.add_argument('--resource-path-rewrites', nargs="*")
parser.add_argument('--resource-path-prefix')
args = parser.parse_args(argv)
grd_file = open(os.path.normpath(os.path.join(_CWD, args.out_grd)), 'w')
......@@ -140,7 +138,7 @@ def main(argv):
args.input_files_base_dir, filename).replace('\\', '/')
grd_file.write(_generate_include_row(
args.grd_prefix, filename, '${root_src_dir}/' + filepath,
resource_path_rewrites))
resource_path_rewrites, args.resource_path_prefix))
if args.manifest_files != None:
for manifest_file in args.manifest_files:
......@@ -153,7 +151,7 @@ def main(argv):
rebased_path = os.path.relpath(filepath, args.root_gen_dir)
grd_file.write(_generate_include_row(
args.grd_prefix, filename, '${root_gen_dir}/' + rebased_path,
resource_path_rewrites))
resource_path_rewrites, args.resource_path_prefix))
end_template = GRDP_END_TEMPLATE if args.out_grd.endswith('.grdp') else \
GRD_END_TEMPLATE
......
......@@ -53,7 +53,7 @@ class GenerateGrdTest(unittest.TestCase):
out_grd='test_resources.grd',
manifest_files=None, input_files=None,
input_files_base_dir=None, grdp_files=None,
resource_path_rewrites=None):
resource_path_rewrites=None, resource_path_prefix=None):
args = [
'--out-grd', os.path.join(self._out_folder, out_grd),
'--grd-prefix', 'test',
......@@ -80,6 +80,9 @@ class GenerateGrdTest(unittest.TestCase):
if (resource_path_rewrites):
args += [ '--resource-path-rewrites' ] + resource_path_rewrites
if (resource_path_prefix):
args += [ '--resource-path-prefix', resource_path_prefix ]
generate_grd.main(args)
actual_grd = self._read_out_file(out_grd)
......@@ -123,6 +126,14 @@ class GenerateGrdTest(unittest.TestCase):
input_files = [ 'images/test_svg.svg', 'test_html_in_src.html' ],
input_files_base_dir = 'test_src_dir')
def testSuccessGrdpWithResourcePathPrefix(self):
self._run_test_(
'expected_grdp_with_resource_path_prefix.grdp',
out_grd = 'test_resources.grdp',
input_files = [ 'foo.js', 'bar.svg' ],
input_files_base_dir = 'test_src_dir',
resource_path_prefix = 'baz')
def testSuccessWithRewrites(self):
self._run_test_(
'expected_grd_with_rewrites.grd',
......
<?xml version="1.0" encoding="UTF-8"?>
<grit-part>
<include name="IDR_TEST_FOO_JS" file="${root_src_dir}/test_src_dir/foo.js" resource_path="baz/foo.js" use_base_dir="false" type="chrome_html" />
<include name="IDR_TEST_BAR_SVG" file="${root_src_dir}/test_src_dir/bar.svg" resource_path="baz/bar.svg" use_base_dir="false" type="BINDATA" />
</grit-part>
......@@ -201,7 +201,6 @@ without changes to the corresponding grd file. -->
<if expr="not is_android and not is_ios">
<part file="cr_components/cr_components_resources_v3.grdp" />
<part file="cr_elements_resources_v3.grdp" />
<part file="cr_polymer_resources_v3.grdp" />
</if>
</includes>
......@@ -468,7 +467,6 @@ without changes to the corresponding grd file. -->
<if expr="not is_android and not is_ios">
<part file="cr_components/cr_components_resources.grdp" />
<part file="cr_elements_resources.grdp" />
<part file="cr_polymer_resources.grdp" />
</if>
</structures>
......
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