Commit 57c03ad0 authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Auto-generate tracing_resources.grd with generate_grd().

This file was previously auto-generated with a custom one-off python
script, which is no longer necessary now that generate_grd() exists.

The previously generated file was also unnecessarily using
|flattenhtml| and |allowexternalscript| Grit attributes which are
removed as part of using the new tool.

Besides the benefit of removing a one-off script, this also removes a
TODO about crbug.com/1112471 about making the one-off script work with
Python 3, which is now obsolete.

Bug: 1132403,1152343,1112471
Change-Id: I06928dcc2690b819eea1680fde23221ded94ed89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2557349
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830647}
parent 94a77e74
...@@ -2,35 +2,23 @@ ...@@ -2,35 +2,23 @@
# 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("//build/config/python.gni")
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
# generate_about_tracing puts its files in this directory
tracing_gen_dir = "$root_gen_dir/content/browser/tracing"
assert(!is_android) assert(!is_android)
# The script just writes filename with no dirs to the .grd, so we always need # The script just writes filename with no dirs to the .grd, so we always need
# this file to be in the same directory as the inputs. # this file to be in the same directory as the inputs.
tracing_grd = "$tracing_gen_dir/tracing_resources.grd" tracing_grd = "$target_gen_dir/tracing_resources.grd"
# TODO(crbug.com/1112471): Get this to run cleanly under Python 3. generate_grd("build_grd") {
python2_action("generate_tracing_grd") { grd_prefix = "tracing"
visibility = [ ":*" ] # Depend on ":resources" to get this. out_grd = tracing_grd
script = "generate_trace_viewer_grd.py" input_files = [
"about_tracing.html",
input_pages = [ "about_tracing.js",
"$tracing_gen_dir/about_tracing.html",
"$tracing_gen_dir/about_tracing.js",
] ]
inputs = input_pages input_files_base_dir = rebase_path(target_gen_dir, root_build_dir)
outputs = [ tracing_grd ]
args = rebase_path(input_pages, target_gen_dir) + [
"--output",
rebase_path(tracing_grd, root_build_dir),
]
deps = [ "//third_party/catapult/tracing:generate_about_tracing" ] deps = [ "//third_party/catapult/tracing:generate_about_tracing" ]
} }
...@@ -42,8 +30,10 @@ grit("resources") { ...@@ -42,8 +30,10 @@ grit("resources") {
outputs = [ outputs = [
"grit/tracing_resources.h", "grit/tracing_resources.h",
"grit/tracing_resources_map.cc",
"grit/tracing_resources_map.h",
"tracing_resources.pak", "tracing_resources.pak",
] ]
deps = [ ":generate_tracing_grd" ] deps = [ ":build_grd" ]
} }
#!/usr/bin/env python
# Copyright 2013 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.
"""Creates a grd file for packaging the trace-viewer files.
This file is modified from the devtools generate_devtools_grd.py file.
"""
import errno
import os
import shutil
import sys
from xml.dom import minidom
kTracingResourcePrefix = 'IDR_TRACING_'
kGrdTemplate = '''<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1"
output_all_resource_defines="false">
<outputs>
<output filename="grit/tracing_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="tracing_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<if expr="not is_android"></if>
</includes>
</release>
</grit>
'''
class ParsedArgs:
def __init__(self, source_files, output_filename):
self.source_files = source_files
self.output_filename = output_filename
def parse_args(argv):
output_position = argv.index('--output')
source_files = argv[:output_position]
return ParsedArgs(source_files, argv[output_position + 1])
def make_name_from_filename(filename):
return kTracingResourcePrefix + (os.path.splitext(filename)[1][1:]).upper()
def add_file_to_grd(grd_doc, filename):
includes_node = grd_doc.getElementsByTagName('if')[0]
includes_node.appendChild(grd_doc.createTextNode('\n '))
new_include_node = grd_doc.createElement('include')
new_include_node.setAttribute('name', make_name_from_filename(filename))
new_include_node.setAttribute('file', filename)
new_include_node.setAttribute('type', 'BINDATA')
new_include_node.setAttribute('compress', 'gzip')
new_include_node.setAttribute('flattenhtml', 'true')
if filename.endswith('.html'):
new_include_node.setAttribute('allowexternalscript', 'true')
includes_node.appendChild(new_include_node)
def main(argv):
parsed_args = parse_args(argv[1:])
output_directory = os.path.dirname(parsed_args.output_filename)
doc = minidom.parseString(kGrdTemplate)
for filename in parsed_args.source_files:
add_file_to_grd(doc, os.path.basename(filename))
with open(parsed_args.output_filename, 'w') as output_file:
output_file.write(doc.toxml(encoding='UTF-8'))
if __name__ == '__main__':
sys.exit(main(sys.argv))
...@@ -241,8 +241,9 @@ TracingUI::TracingUI(WebUI* web_ui) ...@@ -241,8 +241,9 @@ TracingUI::TracingUI(WebUI* web_ui)
WebUIDataSource* source = WebUIDataSource::Create(kChromeUITracingHost); WebUIDataSource* source = WebUIDataSource::Create(kChromeUITracingHost);
source->DisableTrustedTypesCSP(); source->DisableTrustedTypesCSP();
source->UseStringsJs(); source->UseStringsJs();
source->SetDefaultResource(IDR_TRACING_HTML); source->SetDefaultResource(IDR_TRACING_ABOUT_TRACING_HTML);
source->AddResourcePath("tracing.js", IDR_TRACING_JS); source->AddResourcePath("tracing.js", IDR_TRACING_ABOUT_TRACING_JS);
source->SetRequestFilter(base::BindRepeating(OnShouldHandleRequest), source->SetRequestFilter(base::BindRepeating(OnShouldHandleRequest),
base::BindRepeating(OnTracingRequest)); base::BindRepeating(OnTracingRequest));
WebUIDataSource::Add(browser_context, source); WebUIDataSource::Add(browser_context, source);
......
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