Commit 3eff2f26 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

Move make_cssom_types.py to build/scripts/core/css/.

This patch moves:
  - build/scripts/make_cssom_types.py ->
    build/scripts/core/css/make_cssom_types.py

  - build/scripts/templates/CSSOMTypes.cpp.tmpl ->
    build/scripts/core/css/templates/CSSOMTypes.cpp.tmpl

  - build/scripts/templates/CSSOMKeywords.cpp.tmpl ->
    build/scripts/core/css/templates/CSSOMKeywords.cpp.tmpl

We append 'build/scripts' to the system path in
make_cssom_types.py so that it can import modules such as
json5_generator.

We also add a new GN template "code_generator" to be used by
the new style generators. There are some additional changes
to make the linter happy.

This patch does not change behaviour.

Bug: 732657
Change-Id: I07bb1042cf548ef8795a04833f8224ad1ffe232c
Reviewed-on: https://chromium-review.googlesource.com/558587
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487349}
parent 75a18c2b
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
# 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 os
import sys import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
import css_properties import css_properties
import json5_generator import json5_generator
...@@ -21,33 +23,33 @@ class CSSOMTypesWriter(css_properties.CSSProperties): ...@@ -21,33 +23,33 @@ class CSSOMTypesWriter(css_properties.CSSProperties):
def __init__(self, json5_file_path): def __init__(self, json5_file_path):
super(CSSOMTypesWriter, self).__init__(json5_file_path) super(CSSOMTypesWriter, self).__init__(json5_file_path)
for property in self._properties.values(): for property_ in self._properties.values():
types = [] types = []
# Expand types # Expand types
for singleType in property['typedom_types']: for single_type in property_['typedom_types']:
if singleType == 'Image': if single_type == 'Image':
types.append('URLImage') types.append('URLImage')
else: else:
types.append(singleType) types.append(single_type)
property['typedom_types'] = types property_['typedom_types'] = types
# Generate Keyword ID values from keywords. # Generate Keyword ID values from keywords.
property['keywordIDs'] = map( property_['keywordIDs'] = map(
enum_for_css_keyword, property['keywords']) enum_for_css_keyword, property_['keywords'])
self._outputs = { self._outputs = {
'CSSOMTypes.cpp': self.generate_types, 'CSSOMTypes.cpp': self.generate_types,
'CSSOMKeywords.cpp': self.generate_keywords, 'CSSOMKeywords.cpp': self.generate_keywords,
} }
@template_expander.use_jinja('templates/CSSOMTypes.cpp.tmpl') @template_expander.use_jinja('core/css/templates/CSSOMTypes.cpp.tmpl')
def generate_types(self): def generate_types(self):
return { return {
'input_files': self._input_files, 'input_files': self._input_files,
'properties': self._properties, 'properties': self._properties,
} }
@template_expander.use_jinja('templates/CSSOMKeywords.cpp.tmpl') @template_expander.use_jinja('core/css/templates/CSSOMKeywords.cpp.tmpl')
def generate_keywords(self): def generate_keywords(self):
return { return {
'input_files': self._input_files, 'input_files': self._input_files,
......
...@@ -79,6 +79,8 @@ make_core_generated_deps = [ ...@@ -79,6 +79,8 @@ make_core_generated_deps = [
"//third_party/WebKit/Source/core:core_event_interfaces", "//third_party/WebKit/Source/core:core_event_interfaces",
] ]
# TODO(shend): Remove this once everything that uses this switches over to
# the 'code_generator' template instead.
# Template to run most of scripts that process "*.in" files. # Template to run most of scripts that process "*.in" files.
# script: script to run. # script: script to run.
# in_files: ".in" files to pass to the script # in_files: ".in" files to pass to the script
...@@ -129,6 +131,56 @@ template("process_in_files") { ...@@ -129,6 +131,56 @@ template("process_in_files") {
} }
} }
# Template to run code generators in build/scripts/.
# script: the path to the script to run.
# json_inputs: ".json5" files to pass to the generator.
# templates: ".tmpl" files that this generator depends on.
# other_inputs: (optional) other input files the generator depends on
# defaults to "scripts_for_json5_files" (if specified, we assume
# that the contents of "scripts_for_json5_files" are included in
# this list).
# outputs: expected results. Note that the directory of the 0th item in this
# list will be taken to be the output path.
# other_args: (optional) other arguments to pass to the script.
# deps [optional]:
# Depenendencies. If unspecified defaults to make_core_generated_deps.
template("code_generator") {
action(target_name) {
script = invoker.script
inputs = invoker.json_inputs + invoker.templates
if (defined(invoker.other_inputs)) {
inputs += invoker.other_inputs
} else {
inputs += scripts_for_json5_files
}
outputs = invoker.outputs
# Extract the directory to write files to.
output_dir = get_path_info(outputs[0], "dir")
args = rebase_path(invoker.json_inputs, root_build_dir) + [
"--output_dir",
rebase_path(output_dir, root_build_dir),
]
if (is_mac && !use_system_xcode) {
args += [
"--developer_dir",
hermetic_xcode_path,
]
}
if (defined(invoker.other_args)) {
args += invoker.other_args
}
if (defined(invoker.deps)) {
deps = invoker.deps
} else {
deps = make_core_generated_deps
}
forward_variables_from(invoker, [ "visibility" ])
}
}
# Template for scripts using css_properties.py. This is a special case of # Template for scripts using css_properties.py. This is a special case of
# process_in_files. # process_in_files.
# outputs: expected results # outputs: expected results
......
...@@ -666,11 +666,12 @@ css_properties("make_core_generated_style_builder") { ...@@ -666,11 +666,12 @@ css_properties("make_core_generated_style_builder") {
] ]
} }
css_properties("make_core_generated_cssom_types") { code_generator("make_core_generated_cssom_types") {
script = "../build/scripts/make_cssom_types.py" script = "../build/scripts/core/css/make_cssom_types.py"
other_inputs = [ json_inputs = [ "css/CSSProperties.json5" ]
"../build/scripts/templates/CSSOMKeywords.cpp.tmpl", templates = [
"../build/scripts/templates/CSSOMTypes.cpp.tmpl", "../build/scripts/core/css/templates/CSSOMKeywords.cpp.tmpl",
"../build/scripts/core/css/templates/CSSOMTypes.cpp.tmpl",
] ]
outputs = [ outputs = [
"$blink_core_output_dir/CSSOMKeywords.cpp", "$blink_core_output_dir/CSSOMKeywords.cpp",
......
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