Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: tools/json_to_struct/json_to_struct.py

Issue 1209743002: Generate a static struct from fieldtrial_testing_config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@codegen_nested_structs
Patch Set: add +x file permission Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/variations/fieldtrial_testing_config_mac.json ('k') | tools/perf/core/perf_benchmark.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_to_struct/json_to_struct.py
diff --git a/tools/json_to_struct/json_to_struct.py b/tools/json_to_struct/json_to_struct.py
index 726cec93d1cd11d307ef3756bc8270120fc80379..46cfd4a93975f4baa5cebe7b3002b479710dea3e 100755
--- a/tools/json_to_struct/json_to_struct.py
+++ b/tools/json_to_struct/json_to_struct.py
@@ -183,6 +183,29 @@ def _Load(filename):
result = json.loads(json_comment_eater.Nom(handle.read()))
return result
+def GenerateStruct(basepath, output_root, namespace, schema, description,
+ description_filename, schema_filename, year=None):
+ """Generates a C++ struct from a JSON description.
+
+ Args:
+ basepath: The base directory in which files are generated.
+ output_root: The filename and path, relative to basepath, of the file to
+ create, without an extension.
+ namespace: A string corresponding to the C++ namespace to use.
+ schema: A dict containing the schema. See comment at the top of this file.
+ description: A dict containing the description. See comment at the top of
+ this file.
+ description_filename: The description filename. This is added to the
+ header of the outputted files.
+ schema_filename: The schema filename. This is added to the header of the
+ outputted files.
+ year: Year to display next to the copy-right in the header.
+ """
+ year = int(year) if year else datetime.now().year
+ head = HEAD % (year, schema_filename, description_filename)
+ _GenerateH(basepath, output_root, head, namespace, schema, description)
+ _GenerateCC(basepath, output_root, head, namespace, schema, description)
+
if __name__ == '__main__':
parser = optparse.OptionParser(
description='Generates an C++ array of struct from a JSON description.',
@@ -195,6 +218,7 @@ if __name__ == '__main__':
help='C++ namespace for generated files. e.g search_providers.')
parser.add_option('-s', '--schema', help='path to the schema file, '
'mandatory.')
+ parser.add_option('-o', '--output', help='output filename, ')
(opts, args) = parser.parse_args()
if not opts.schema:
@@ -202,7 +226,7 @@ if __name__ == '__main__':
description_filename = os.path.normpath(args[0])
root, ext = os.path.splitext(description_filename)
- shortroot = os.path.split(root)[1]
+ shortroot = opts.output if opts.output else os.path.split(root)[1]
if opts.destdir:
output_root = os.path.join(os.path.normpath(opts.destdir), shortroot)
else:
@@ -215,7 +239,5 @@ if __name__ == '__main__':
schema = _Load(opts.schema)
description = _Load(description_filename)
-
- head = HEAD % (datetime.now().year, opts.schema, description_filename)
- _GenerateH(basepath, output_root, head, opts.namespace, schema, description)
- _GenerateCC(basepath, output_root, head, opts.namespace, schema, description)
+ GenerateStruct(basepath, output_root, opts.namespace, schema, description,
+ description_filename, opts.schema)
« no previous file with comments | « testing/variations/fieldtrial_testing_config_mac.json ('k') | tools/perf/core/perf_benchmark.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698