Commit 885fd1b3 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

move_blink_source.py: Update renamed basenames in Blink *.py.

Affected *.py are mainly for C++-code generators.  This will fix #include
paths in generated code.

_update_basename() replaces only basenames of checked-in files. So we
need to update V8Foo.h individually.

Bug: 578345, 760462
Change-Id: I65ebabc2d11f2a50d60bd11b9242adaffc4030c5
Reviewed-on: https://chromium-review.googlesource.com/662877
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501539}
parent 998abc09
...@@ -19,7 +19,8 @@ from v8_methods import method_filters ...@@ -19,7 +19,8 @@ from v8_methods import method_filters
import v8_utilities import v8_utilities
from v8_utilities import capitalize from v8_utilities import capitalize
from utilities import (idl_filename_to_component, is_valid_component_dependency, from utilities import (idl_filename_to_component, is_valid_component_dependency,
format_remove_duplicates, format_blink_cpp_source_code) format_remove_duplicates, format_blink_cpp_source_code,
to_snake_case)
# Path handling for libraries and templates # Path handling for libraries and templates
# Paths have to be normalized because Jinja uses the exact template path to # Paths have to be normalized because Jinja uses the exact template path to
...@@ -96,12 +97,18 @@ def initialize_jinja_env(cache_dir): ...@@ -96,12 +97,18 @@ def initialize_jinja_env(cache_dir):
return jinja_env return jinja_env
def normalize_and_sort_includes(include_paths): def normalize_and_sort_includes(include_paths, snake_case):
normalized_include_paths = [] normalized_include_paths = []
for include_path in include_paths: for include_path in include_paths:
match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path)) match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path))
if match: if match:
include_path = match.group(1) include_path = match.group(1)
if snake_case:
match = re.search(r'/([^/]+)\.h$', include_path)
if match:
name = match.group(1)
if name.lower() != name and name != 'RuntimeEnabledFeatures' and name != 'OriginTrials':
include_path = include_path[0:match.start(1)] + to_snake_case(name) + '.h'
normalized_include_paths.append(include_path) normalized_include_paths.append(include_path)
return sorted(normalized_include_paths) return sorted(normalized_include_paths)
...@@ -116,11 +123,12 @@ def render_template(template, context): ...@@ -116,11 +123,12 @@ def render_template(template, context):
class CodeGeneratorBase(object): class CodeGeneratorBase(object):
"""Base class for jinja-powered jinja template generation. """Base class for jinja-powered jinja template generation.
""" """
def __init__(self, generator_name, info_provider, cache_dir, output_dir): def __init__(self, generator_name, info_provider, cache_dir, output_dir, snake_case):
self.generator_name = generator_name self.generator_name = generator_name
self.info_provider = info_provider self.info_provider = info_provider
self.jinja_env = initialize_jinja_env(cache_dir) self.jinja_env = initialize_jinja_env(cache_dir)
self.output_dir = output_dir self.output_dir = output_dir
self.snake_case_generated_files = snake_case
self.set_global_type_info() self.set_global_type_info()
def should_generate_code(self, definitions): def should_generate_code(self, definitions):
...@@ -143,7 +151,7 @@ class CodeGeneratorBase(object): ...@@ -143,7 +151,7 @@ class CodeGeneratorBase(object):
# Add includes for any dependencies # Add includes for any dependencies
template_context['header_includes'] = normalize_and_sort_includes( template_context['header_includes'] = normalize_and_sort_includes(
template_context['header_includes']) template_context['header_includes'], self.snake_case_generated_files)
for include_path in include_paths: for include_path in include_paths:
if component: if component:
...@@ -151,7 +159,7 @@ class CodeGeneratorBase(object): ...@@ -151,7 +159,7 @@ class CodeGeneratorBase(object):
assert is_valid_component_dependency(component, dependency) assert is_valid_component_dependency(component, dependency)
includes.add(include_path) includes.add(include_path)
template_context['cpp_includes'] = normalize_and_sort_includes(includes) template_context['cpp_includes'] = normalize_and_sort_includes(includes, self.snake_case_generated_files)
header_text = render_template(header_template, template_context) header_text = render_template(header_template, template_context)
cpp_text = render_template(cpp_template, template_context) cpp_text = render_template(cpp_template, template_context)
......
...@@ -135,9 +135,8 @@ class CodeGeneratorV8Base(CodeGeneratorBase): ...@@ -135,9 +135,8 @@ class CodeGeneratorV8Base(CodeGeneratorBase):
"""Base class for v8 bindings generator and IDL dictionary impl generator""" """Base class for v8 bindings generator and IDL dictionary impl generator"""
def __init__(self, info_provider, cache_dir, output_dir, snake_case): def __init__(self, info_provider, cache_dir, output_dir, snake_case):
CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir, output_dir) CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir, output_dir, snake_case)
self.typedef_resolver = TypedefResolver(info_provider) self.typedef_resolver = TypedefResolver(info_provider)
self.snake_case_generated_files = snake_case
def generate_code(self, definitions, definition_name): def generate_code(self, definitions, definition_name):
"""Returns .h/.cpp code as ((path, content)...).""" """Returns .h/.cpp code as ((path, content)...)."""
...@@ -305,8 +304,8 @@ class CodeGeneratorUnionType(CodeGeneratorBase): ...@@ -305,8 +304,8 @@ class CodeGeneratorUnionType(CodeGeneratorBase):
CodeGeneratorDictionaryImpl. It assumes that all union types are already CodeGeneratorDictionaryImpl. It assumes that all union types are already
collected. It doesn't process idl files directly. collected. It doesn't process idl files directly.
""" """
def __init__(self, info_provider, cache_dir, output_dir, target_component): def __init__(self, info_provider, cache_dir, output_dir, snake_case, target_component):
CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir, output_dir) CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir, output_dir, snake_case)
self.target_component = target_component self.target_component = target_component
# The code below duplicates parts of TypedefResolver. We do not use it # The code below duplicates parts of TypedefResolver. We do not use it
# directly because IdlUnionType is not a type defined in # directly because IdlUnionType is not a type defined in
...@@ -325,7 +324,7 @@ class CodeGeneratorUnionType(CodeGeneratorBase): ...@@ -325,7 +324,7 @@ class CodeGeneratorUnionType(CodeGeneratorBase):
template_context['header_includes'].append( template_context['header_includes'].append(
self.info_provider.include_path_for_export) self.info_provider.include_path_for_export)
template_context['header_includes'] = normalize_and_sort_includes( template_context['header_includes'] = normalize_and_sort_includes(
template_context['header_includes']) template_context['header_includes'], self.snake_case_generated_files)
template_context['code_generator'] = self.generator_name template_context['code_generator'] = self.generator_name
template_context['exported'] = self.info_provider.specifier_for_export template_context['exported'] = self.info_provider.specifier_for_export
snake_base_name = to_snake_case(shorten_union_name(union_type)) snake_base_name = to_snake_case(shorten_union_name(union_type))
...@@ -367,8 +366,8 @@ class CodeGeneratorUnionType(CodeGeneratorBase): ...@@ -367,8 +366,8 @@ class CodeGeneratorUnionType(CodeGeneratorBase):
class CodeGeneratorCallbackFunction(CodeGeneratorBase): class CodeGeneratorCallbackFunction(CodeGeneratorBase):
def __init__(self, info_provider, cache_dir, output_dir, target_component): def __init__(self, info_provider, cache_dir, output_dir, snake_case, target_component):
CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir, output_dir) CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir, output_dir, snake_case)
self.target_component = target_component self.target_component = target_component
self.typedef_resolver = TypedefResolver(info_provider) self.typedef_resolver = TypedefResolver(info_provider)
...@@ -383,7 +382,7 @@ class CodeGeneratorCallbackFunction(CodeGeneratorBase): ...@@ -383,7 +382,7 @@ class CodeGeneratorCallbackFunction(CodeGeneratorBase):
template_context['header_includes'].append( template_context['header_includes'].append(
self.info_provider.include_path_for_export) self.info_provider.include_path_for_export)
template_context['header_includes'] = normalize_and_sort_includes( template_context['header_includes'] = normalize_and_sort_includes(
template_context['header_includes']) template_context['header_includes'], self.snake_case_generated_files)
template_context['code_generator'] = MODULE_PYNAME template_context['code_generator'] = MODULE_PYNAME
header_text = render_template(header_template, template_context) header_text = render_template(header_template, template_context)
cpp_text = render_template(cpp_template, template_context) cpp_text = render_template(cpp_template, template_context)
......
...@@ -239,9 +239,9 @@ class InterfaceContextBuilder(object): ...@@ -239,9 +239,9 @@ class InterfaceContextBuilder(object):
class CodeGeneratorWebAgentAPI(CodeGeneratorBase): class CodeGeneratorWebAgentAPI(CodeGeneratorBase):
def __init__(self, info_provider, cache_dir, output_dir, _): def __init__(self, info_provider, cache_dir, output_dir, snake_case):
CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider,
cache_dir, output_dir) cache_dir, output_dir, snake_case)
self.type_resolver = TypeResolver(info_provider.interfaces_info) self.type_resolver = TypeResolver(info_provider.interfaces_info)
self.typedef_resolver = TypedefResolver(info_provider) self.typedef_resolver = TypedefResolver(info_provider)
......
...@@ -142,7 +142,7 @@ def conditional_features_info(info_provider, reader, idl_filenames, target_compo ...@@ -142,7 +142,7 @@ def conditional_features_info(info_provider, reader, idl_filenames, target_compo
return features_for_type, types_for_feature, includes return features_for_type, types_for_feature, includes
def conditional_features_context(generator_name, feature_info): def conditional_features_context(generator_name, feature_info, snake_case):
context = {'code_generator': generator_name} context = {'code_generator': generator_name}
# Unpack the feature info tuple. # Unpack the feature info tuple.
...@@ -160,7 +160,7 @@ def conditional_features_context(generator_name, feature_info): ...@@ -160,7 +160,7 @@ def conditional_features_context(generator_name, feature_info):
# here because the ContextFeatureSettings code needs it. # here because the ContextFeatureSettings code needs it.
'bindings/core/v8/V8Window.h', 'bindings/core/v8/V8Window.h',
]) ])
context['includes'] = normalize_and_sort_includes(includes) context['includes'] = normalize_and_sort_includes(includes, snake_case)
# For each interface, collect a list of bindings installation functions to # For each interface, collect a list of bindings installation functions to
# call, organized by conditional feature. # call, organized by conditional feature.
...@@ -218,7 +218,7 @@ def generate_conditional_features(info_provider, options, idl_filenames): ...@@ -218,7 +218,7 @@ def generate_conditional_features(info_provider, options, idl_filenames):
# Convert that mapping into the context required for the Jinja2 templates. # Convert that mapping into the context required for the Jinja2 templates.
template_context = conditional_features_context( template_context = conditional_features_context(
MODULE_PYNAME, feature_info) MODULE_PYNAME, feature_info, options.snake_case_generated_files)
# Generate and write out the header file # Generate and write out the header file
header_text = render_template(jinja_env.get_template( header_text = render_template(jinja_env.get_template(
......
...@@ -159,6 +159,7 @@ def generate_union_type_containers(code_generator_class, info_provider, ...@@ -159,6 +159,7 @@ def generate_union_type_containers(code_generator_class, info_provider,
info_provider, info_provider,
options.cache_directory, options.cache_directory,
options.output_directory, options.output_directory,
options.snake_case_generated_files,
options.target_component) options.target_component)
output_code_list = generator.generate_code() output_code_list = generator.generate_code()
for output_path, output_code in output_code_list: for output_path, output_code in output_code_list:
...@@ -171,6 +172,7 @@ def generate_callback_function_impl(code_generator_class, info_provider, ...@@ -171,6 +172,7 @@ def generate_callback_function_impl(code_generator_class, info_provider,
info_provider, info_provider,
options.cache_directory, options.cache_directory,
options.output_directory, options.output_directory,
options.snake_case_generated_files,
options.target_component) options.target_component)
output_code_list = generator.generate_code() output_code_list = generator.generate_code()
for output_path, output_code in output_code_list: for output_path, output_code in output_code_list:
......
...@@ -51,6 +51,7 @@ class FileType(object): ...@@ -51,6 +51,7 @@ class FileType(object):
DEPS = 4 DEPS = 4
MOJOM = 5 MOJOM = 5
TYPEMAP = 6 TYPEMAP = 6
BLINK_BUILD_PY = 7
@staticmethod @staticmethod
def detect(path): def detect(path):
...@@ -63,6 +64,8 @@ class FileType(object): ...@@ -63,6 +64,8 @@ class FileType(object):
return FileType.MOJOM return FileType.MOJOM
if basename.endswith('.typemap'): if basename.endswith('.typemap'):
return FileType.TYPEMAP return FileType.TYPEMAP
if basename.endswith('.py') and 'third_party/WebKit/Source/build' in path.replace('\\', '/'):
return FileType.BLINK_BUILD_PY
if basename.endswith(('.gn', '.gni')): if basename.endswith(('.gn', '.gni')):
path = path.replace('\\', '/') path = path.replace('\\', '/')
if 'third_party/WebKit' in path or 'third_party/blink' in path: if 'third_party/WebKit' in path or 'third_party/blink' in path:
...@@ -102,9 +105,6 @@ class MoveBlinkSource(object): ...@@ -102,9 +105,6 @@ class MoveBlinkSource(object):
self._append_unless_upper_dir_exists(dirs, self._fs.join(self._repo_root, 'third_party', 'WebKit', 'public')) self._append_unless_upper_dir_exists(dirs, self._fs.join(self._repo_root, 'third_party', 'WebKit', 'public'))
self._update_cpp_includes_in_directories(dirs) self._update_cpp_includes_in_directories(dirs)
# TODO(tkent): Update basenames in generated files;
# bindings/scripts/*.py, build/scripts/*.py.
# Content update for individual files # Content update for individual files
self._update_single_file_content('third_party/WebKit/Source/config.gni', self._update_single_file_content('third_party/WebKit/Source/config.gni',
[('snake_case_source_files = false', [('snake_case_source_files = false',
...@@ -207,6 +207,12 @@ class MoveBlinkSource(object): ...@@ -207,6 +207,12 @@ class MoveBlinkSource(object):
content = content.replace('//third_party/WebKit/public', '//third_party/blink/renderer/public') content = content.replace('//third_party/WebKit/public', '//third_party/blink/renderer/public')
return self._update_basename(content) return self._update_basename(content)
def _update_blink_build_py(self, content):
# We don't prepend 'third_party/blink/renderer/' to matched basenames
# because it won't affect build and manual update after the great mv is
# enough.
return self._update_basename(content)
def _update_basename(self, content): def _update_basename(self, content):
return self._basename_re.sub(lambda match: self._basename_map[match.group(1)], content) return self._basename_re.sub(lambda match: self._basename_map[match.group(1)], content)
...@@ -221,7 +227,7 @@ class MoveBlinkSource(object): ...@@ -221,7 +227,7 @@ class MoveBlinkSource(object):
dirs.append(new_dir) dirs.append(new_dir)
def _update_file_content(self): def _update_file_content(self):
_log.info('Find *.gn, *.mojom, *.typemap, DEPS, and OWNERS ...') _log.info('Find *.gn, *.mojom, *.py, *.typemap, DEPS, and OWNERS ...')
files = self._fs.files_under( files = self._fs.files_under(
self._repo_root, dirs_to_skip=['.git', 'out'], file_filter=self._filter_file) self._repo_root, dirs_to_skip=['.git', 'out'], file_filter=self._filter_file)
_log.info('Scan contents of %d files ...', len(files)) _log.info('Scan contents of %d files ...', len(files))
...@@ -242,6 +248,8 @@ class MoveBlinkSource(object): ...@@ -242,6 +248,8 @@ class MoveBlinkSource(object):
content = self._update_mojom(content) content = self._update_mojom(content)
elif file_type == FileType.TYPEMAP: elif file_type == FileType.TYPEMAP:
content = self._update_typemap(content) content = self._update_typemap(content)
elif file_type == FileType.BLINK_BUILD_PY:
content = self._update_blink_build_py(content)
if original_content == content: if original_content == content:
continue continue
......
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