Commit e7565039 authored by Yashar Dabiran's avatar Yashar Dabiran Committed by Commit Bot

[1 of 5] Add runtime_enabled_features.pickle

This CL is part of the efforts to add |RuntimeEnabled| IDL attribute
support for origin trial features.

Design doc for the overall change:
https://docs.google.com/document/d/1Qog5qwZ-6Rfx10AKkJxN-LrwhCw_GJ1xdLoQSnpsT1Q

This CL writes all runtime features (defined in runtime_enabled_features.json5)
to a file to be able to access them during the bindings generation.

Bug: 934451
Change-Id: I839d7893af89e0e687feaf5888e699c1efb15c67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1557868
Commit-Queue: Yashar Dabiran <yashard@google.com>
Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649779}
parent ac56421f
......@@ -38,7 +38,9 @@ import template_expander
# We want exactly the same parsing as RuntimeFeatureWriter
# but generate different files.
class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter):
class InternalRuntimeFlagsWriter(make_runtime_features.BaseRuntimeFeatureWriter):
class_name = 'InternalRuntimeFlags'
file_basename = 'internal_runtime_flags'
def __init__(self, json5_file_path, output_dir):
super(InternalRuntimeFlagsWriter, self).__init__(json5_file_path, output_dir)
......
......@@ -37,7 +37,7 @@ import template_expander
# We want exactly the same parsing as RuntimeFeatureWriter
# but generate different files.
class OriginTrialsWriter(make_runtime_features.RuntimeFeatureWriter):
class OriginTrialsWriter(make_runtime_features.BaseRuntimeFeatureWriter):
file_basename = 'origin_trials'
def __init__(self, json5_file_path, output_dir):
......
......@@ -28,6 +28,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import copy
import cPickle as pickle
import os
import sys
from blinkbuild.name_style_converter import NameStyleConverter
......@@ -36,15 +38,19 @@ import json5_generator
import template_expander
class RuntimeFeatureWriter(json5_generator.Writer):
class_name = 'RuntimeEnabledFeatures'
file_basename = 'runtime_enabled_features'
class BaseRuntimeFeatureWriter(json5_generator.Writer):
# |class_name| should be passed as a template input to generate the target
# class. Set this variable if the template generates a class.
class_name = None
# |file_basename| must be set by subclasses since it is used to generate
# the header guard.
file_basename = None
def __init__(self, json5_file_path, output_dir):
super(RuntimeFeatureWriter, self).__init__(json5_file_path, output_dir)
self._outputs = {(self.file_basename + '.h'): self.generate_header,
(self.file_basename + '.cc'): self.generate_implementation,
}
super(BaseRuntimeFeatureWriter, self).__init__(json5_file_path, output_dir)
# Subclasses should add generated output files and their contents to this dict.
self._outputs = {}
assert self.file_basename
self._features = self.json5_file.name_dictionaries
# Dependency graph specified by 'depends_on' attribute.
......@@ -100,6 +106,41 @@ class RuntimeFeatureWriter(json5_generator.Writer):
platforms = self.json5_file.parameters['status']['valid_keys']
return [platform for platform in platforms if platform != 'default']
class RuntimeFeatureWriter(BaseRuntimeFeatureWriter):
class_name = 'RuntimeEnabledFeatures'
file_basename = 'runtime_enabled_features'
def __init__(self, json5_file_path, output_dir):
super(RuntimeFeatureWriter, self).__init__(json5_file_path, output_dir)
self._outputs = {
(self.file_basename + '.h'): self.generate_header,
(self.file_basename + '.cc'): self.generate_implementation,
}
# Write features to file for bindings generation
self._write_features_to_pickle_file(output_dir)
def _write_features_to_pickle_file(self, platform_output_dir):
# TODO(yashard): Get the file path from args instead of hardcoding it.
file_name = os.path.join(platform_output_dir, '..', 'build', 'scripts', 'runtime_enabled_features.pickle')
features_map = {}
for feature in self._features:
features_map[str(feature['name'])] = {
'in_origin_trial': feature['in_origin_trial']
}
if os.path.isfile(file_name):
with open(os.path.abspath(file_name)) as pickle_file:
# pylint: disable=broad-except
try:
if pickle.load(pickle_file) == features_map:
return
except Exception:
# If trouble unpickling, overwrite
pass
with open(os.path.abspath(file_name), 'w') as pickle_file:
pickle.dump(features_map, pickle_file)
def _template_inputs(self):
return {
'features': self._features,
......@@ -120,7 +161,7 @@ class RuntimeFeatureWriter(json5_generator.Writer):
return self._template_inputs()
class RuntimeFeatureTestHelpersWriter(RuntimeFeatureWriter):
class RuntimeFeatureTestHelpersWriter(BaseRuntimeFeatureWriter):
class_name = 'ScopedRuntimeEnabledFeatureForTest'
file_basename = 'runtime_enabled_features_test_helpers'
......@@ -139,6 +180,7 @@ class RuntimeFeatureTestHelpersWriter(RuntimeFeatureWriter):
def generate_header(self):
return self._template_inputs()
if __name__ == '__main__':
json5_generator.Maker(RuntimeFeatureWriter).main()
json5_generator.Maker(RuntimeFeatureTestHelpersWriter).main()
......@@ -10,7 +10,7 @@ import template_expander
# We want exactly the same parsing as RuntimeFeatureWriter but generate
# different files.
class OriginTrialsWriter(make_runtime_features.RuntimeFeatureWriter):
class OriginTrialsWriter(make_runtime_features.BaseRuntimeFeatureWriter):
file_basename = 'web_origin_trials'
def __init__(self, json5_file_path, output_dir):
......
......@@ -39,10 +39,12 @@ blink_python_runner("runtime_enabled_features") {
"../build/scripts/templates/runtime_enabled_features_test_helpers.h.tmpl",
]
build_scripts_output_dir = "$blink_platform_output_dir/../build/scripts"
outputs = [
"$blink_platform_output_dir/runtime_enabled_features.cc",
"$blink_platform_output_dir/runtime_enabled_features.h",
"$blink_platform_output_dir/testing/runtime_enabled_features_test_helpers.h",
"$build_scripts_output_dir/runtime_enabled_features.pickle",
]
args = [
......@@ -50,6 +52,11 @@ blink_python_runner("runtime_enabled_features") {
"--output_dir",
rebase_path(blink_platform_output_dir, root_build_dir),
]
visibility += [
"//third_party/blink/renderer/bindings/core:interfaces_info_individual_core",
"//third_party/blink/renderer/bindings/modules:interfaces_info_individual_modules",
]
}
blink_python_runner("color_data") {
......
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