Commit 2f79d543 authored by Nico Weber's avatar Nico Weber

various small tweaks to blink's gperf use

* make gperf.py call generate_gperf() both when it's invoked via
  use_jinja_gperf_template() as well as when it's called directly
  as a standalone script

* make generate_gperf() do massaging of gperf's output to remove
  uses of the `register` keyword (needed to build with -std=c++17)
  and replace `/*FALLTHROUGH*/` with real FALLTHROUGH statements
  (needed for -Wimplicit-fallthrough)

* remove now-unneeded suppressions for -Wdeprecated-register

* remove TODO about removing gperf.py; that's from a time when the
  script was 1 non-comment line long

* bump check_output() requirement in comment to 3.4 (since that added
  the input= parameter)

* add missing dependency on gperf.py to build steps calling it
  through the jinja interface, so that these edges rerun when
  gperf.py gets modified

* add a comment mentioning gperf.py at the start of the generated
  outputs

* make :character_data not call gperf.py since it doesn't use gperf,
  and make it use compiled_action() instead which is made for
  exactly character_data's use case

No intended behavior change.

Bug: 752720,177475
Change-Id: I56372729bb47787e2d41a5dff2f30804574770f0
Reviewed-on: https://chromium-review.googlesource.com/891141
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533269}
parent 2ade6a08
......@@ -14,12 +14,6 @@
#pragma warning(disable : 4302 4311)
#endif
#if defined(__clang__)
#pragma clang diagnostic push
// TODO(thakis): Remove once we use a gperf that no longer produces "register".
#pragma clang diagnostic ignored "-Wdeprecated-register"
#endif
namespace blink {
namespace {
......@@ -48,10 +42,6 @@ struct Property;
{% endfor %}
%%
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
const Property* FindDescriptor(const char* str, unsigned int len) {
return AtRuleDescriptorHash::findDescriptorImpl(str, len);
}
......
......@@ -14,12 +14,6 @@
#pragma warning(disable : 4302 4311)
#endif
#if defined(__clang__)
#pragma clang diagnostic push
// TODO(thakis): Remove once we use a gperf that no longer produces "register".
#pragma clang diagnostic ignored "-Wdeprecated-register"
#endif
namespace blink {
static const char valueListStringPool[] = {
{% for keyword in value_keywords %}
......@@ -53,10 +47,6 @@ struct Value;
{% endfor %}
%%
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
const Value* FindValue(const char* str, unsigned int len) {
return CSSValueKeywordsHash::findValueImpl(str, len);
}
......
......@@ -4,24 +4,18 @@
# Invokes gperf for the GN build.
# Usage: gperf.py [--developer_dir PATH_TO_XCODE] gperf ...
# TODO(brettw) this can be removed once the run_executable rules have been
# checked in for the GN build.
import argparse
import os
import re
import subprocess
import sys
import template_expander
def generate_gperf(gperf_path, gperf_input, extra_args=None):
# FIXME: If we could depend on Python 2.7, we would use
def generate_gperf(gperf_path, gperf_input, gperf_args):
# FIXME: If we could depend on Python 3.4, we would use
# subprocess.check_output
gperf_args = [gperf_path, '--key-positions=*', '-P', '-n']
gperf_args.extend(['-m', '50']) # Pick best of 50 attempts.
gperf_args.append('-D') # Allow duplicate hashes -> More compact code.
if extra_args:
gperf_args.extend(extra_args)
# If gperf isn't in the path we get an OSError. We don't want to use
# the normal solution of shell=True (as this has to run on many
......@@ -29,11 +23,23 @@ def generate_gperf(gperf_path, gperf_input, extra_args=None):
# CalledProcessError like subprocess would do when shell=True is set.
try:
gperf = subprocess.Popen(
gperf_args,
[gperf_path] + gperf_args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True)
return gperf.communicate(gperf_input)[0]
gperf_output = gperf.communicate(gperf_input)[0]
# Massage gperf output to be more palatable for modern compilers.
# TODO(thakis): Upstream these to gperf so we don't need massaging.
# `register` is deprecated in C++11 and removed in C++17, so remove
# it from gperf's output.
# https://savannah.gnu.org/bugs/index.php?53029
gperf_output = re.sub(r'\bregister ', '', gperf_output)
# -Wimplicit-fallthrough needs an explicit fallthrough statement,
# so replace gperf's /*FALLTHROUGH*/ comment with the statement.
# https://savannah.gnu.org/bugs/index.php?53028
gperf_output = gperf_output.replace('/*FALLTHROUGH*/', ' FALLTHROUGH;')
script = 'third_party/WebKit/Source/build/scripts/gperf.py'
return '// Generated by %s\n' % script + gperf_output
except OSError:
raise subprocess.CalledProcessError(
127, gperf_args, output='Command not found.')
......@@ -48,7 +54,12 @@ def use_jinja_gperf_template(template_path, gperf_extra_args=None):
gperf_path = parameters['gperf_path']
gperf_input = template_expander.apply_template(template_path,
parameters)
return generate_gperf(gperf_path, gperf_input, gperf_extra_args)
gperf_args = ['--key-positions=*', '-P', '-n']
gperf_args.extend(['-m', '50']) # Pick best of 50 attempts.
gperf_args.append('-D') # Allow duplicate hashes -> More compact code.
if gperf_extra_args:
gperf_args.extend(gperf_extra_args)
return generate_gperf(gperf_path, gperf_input, gperf_args)
generator_internal.func_name = generator.func_name
return generator_internal
return wrapper
......@@ -57,11 +68,21 @@ def use_jinja_gperf_template(template_path, gperf_extra_args=None):
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--developer_dir", required=False)
parser.add_argument("--output-file")
args, unknownargs = parser.parse_known_args()
if args.developer_dir:
os.environ['DEVELOPER_DIR'] = args.developer_dir
subprocess.check_call(unknownargs)
gperf_path, gperf_args = unknownargs[0], unknownargs[1:]
infile = None
for arg in gperf_args:
if os.path.isfile(arg):
assert infile is None, 'duplicate inputs? %s, %s' % (infile, arg)
infile = arg
assert infile is not None, 'no input found'
open(args.output_file, 'wb').write(
generate_gperf(gperf_path, open(infile).read(), gperf_args))
if __name__ == '__main__':
main()
......@@ -18,12 +18,6 @@
#pragma warning(disable : 4302 4311)
#endif
#if defined(__clang__)
#pragma clang diagnostic push
// TODO(thakis): Remove once we use a gperf that no longer produces "register".
#pragma clang diagnostic ignored "-Wdeprecated-register"
#endif
namespace blink {
%}
%struct-type
......@@ -43,10 +37,6 @@ struct Property;
{{property_to_enum_map}}
%%
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
const Property* FindProperty(const char* str, unsigned int len) {
return {{class_name}}Hash::findPropertyImpl(str, len);
}
......
......@@ -1098,6 +1098,7 @@ css_properties("make_core_generated_css_shorthand_property_classes") {
css_properties("make_core_generated_css_property_names") {
script = "../build/scripts/make_css_property_names.py"
other_inputs = [
"../build/scripts/gperf.py",
"../build/scripts/templates/CSSPropertyNames.cpp.tmpl",
"../build/scripts/templates/CSSPropertyNames.h.tmpl",
]
......@@ -1110,6 +1111,7 @@ css_properties("make_core_generated_css_property_names") {
code_generator("make_core_generated_atrule_names") {
script = "../build/scripts/core/css/parser/make_atrule_names.py"
json_inputs = [ "css/parser/AtRuleNames.json5" ]
other_inputs = [ "../build/scripts/gperf.py" ]
templates = [
"../build/scripts/core/css/parser/templates/AtRuleDescriptors.cpp.tmpl",
"../build/scripts/core/css/parser/templates/AtRuleDescriptors.h.tmpl",
......@@ -1177,6 +1179,7 @@ code_generator("make_core_generated_css_value_keywords") {
"css/CSSValueKeywords.json5",
"css/SVGCSSValueKeywords.json5",
]
other_inputs = [ "../build/scripts/gperf.py" ]
templates = [
"../build/scripts/core/css/templates/CSSValueKeywords.cpp.tmpl",
"../build/scripts/core/css/templates/CSSValueKeywords.h.tmpl",
......
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//build/compiled_action.gni")
import("//build/config/features.gni")
import("//build/config/jumbo.gni")
import("//build/config/ui.gni")
......@@ -93,26 +94,12 @@ action("color_data") {
]
}
action("character_data") {
script = "../build/scripts/gperf.py"
deps = [
":character_data_generator($host_toolchain)",
]
output_file = "$blink_platform_output_dir/CharacterPropertyData.cpp"
compiled_action("character_data") {
tool = ":character_data_generator"
outputs = [
output_file,
]
# Find character_data_generator, which is generated in a different directory
# when cross-compile.
generator = "./" + rebase_path(
get_label_info(":character_data_generator($host_toolchain)",
"root_out_dir") + "/character_data_generator",
root_build_dir)
args = [
generator,
rebase_path(output_file, root_build_dir),
"$blink_platform_output_dir/CharacterPropertyData.cpp",
]
args = rebase_path(outputs, root_build_dir)
}
action("instrumentation_probes") {
......
......@@ -4,12 +4,6 @@
namespace blink {
#if defined(__clang__)
#pragma clang diagnostic push
// TODO(thakis): Remove once we use a gperf that no longer produces "register".
#pragma clang diagnostic ignored "-Wdeprecated-register"
#endif
%}
%struct-type
struct NamedColor;
......@@ -176,10 +170,6 @@ yellow, 0xffffff00
yellowgreen, 0xff9acd32
%%
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
const struct NamedColor* FindColor(const char* str, unsigned len) {
return ColorDataHash::findColorImpl(str, len);
}
......
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