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

Side by Side Diff: third_party/WebKit/Source/build/scripts/json5_generator.py

Issue 2815773003: Make json5_generator.Writer always take a list of files. (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/make_css_property_apis.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic generator for configuration files in JSON5 format. 5 """Generic generator for configuration files in JSON5 format.
6 6
7 The configuration file is expected to contain either a data array or a data map, 7 The configuration file is expected to contain either a data array or a data map,
8 an optional parameters validation map, and an optional metdata map. Examples: 8 an optional parameters validation map, and an optional metdata map. Examples:
9 { 9 {
10 data: [ 10 data: [
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 class Json5File(object): 92 class Json5File(object):
93 def __init__(self, file_paths, doc, default_metadata=None, default_parameter s=None): 93 def __init__(self, file_paths, doc, default_metadata=None, default_parameter s=None):
94 self.file_paths = file_paths 94 self.file_paths = file_paths
95 self.name_dictionaries = [] 95 self.name_dictionaries = []
96 self.metadata = copy.deepcopy(default_metadata if default_metadata else {}) 96 self.metadata = copy.deepcopy(default_metadata if default_metadata else {})
97 self.parameters = copy.deepcopy(default_parameters if default_parameters else {}) 97 self.parameters = copy.deepcopy(default_parameters if default_parameters else {})
98 self._defaults = {} 98 self._defaults = {}
99 self._process(doc) 99 self._process(doc)
100 100
101 @classmethod 101 @classmethod
102 def load_from_files(cls, file_paths, default_metadata, default_parameters=No ne): 102 def load_from_files(cls, file_paths, default_metadata=None, default_paramete rs=None):
103 if isinstance(file_paths, basestring):
104 file_paths = [file_paths]
105
103 merged_doc = dict() 106 merged_doc = dict()
104 for path in file_paths: 107 for path in file_paths:
105 assert path.endswith(".json5") 108 assert path.endswith(".json5")
106 with open(os.path.abspath(path)) as json5_file: 109 with open(os.path.abspath(path)) as json5_file:
107 doc = _json5_load(json5_file.read()) 110 doc = _json5_load(json5_file.read())
108 if not merged_doc: 111 if not merged_doc:
109 merged_doc = doc 112 merged_doc = doc
110 else: 113 else:
111 _merge_doc(merged_doc, doc) 114 _merge_doc(merged_doc, doc)
112 return Json5File(file_paths, merged_doc, default_metadata, default_param eters) 115 return Json5File(file_paths, merged_doc, default_metadata, default_param eters)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 192
190 class Writer(object): 193 class Writer(object):
191 # Subclasses should override. 194 # Subclasses should override.
192 class_name = None 195 class_name = None
193 default_metadata = None 196 default_metadata = None
194 default_parameters = None 197 default_parameters = None
195 198
196 def __init__(self, json5_files): 199 def __init__(self, json5_files):
197 self._outputs = {} # file_name -> generator 200 self._outputs = {} # file_name -> generator
198 self.gperf_path = None 201 self.gperf_path = None
199 if isinstance(json5_files, basestring):
200 json5_files = [json5_files]
alancutter (OOO until 2018) 2017/04/13 03:23:52 This code (that existed) smells bad. Are we certai
shend 2017/04/13 03:57:43 Done.
201 if json5_files: 202 if json5_files:
202 self.json5_file = Json5File.load_from_files(json5_files, 203 self.json5_file = Json5File.load_from_files(json5_files,
203 self.default_metadata, 204 self.default_metadata,
204 self.default_parameters) 205 self.default_parameters)
205 206
206 def _write_file_if_changed(self, output_dir, contents, file_name): 207 def _write_file_if_changed(self, output_dir, contents, file_name):
207 path = os.path.join(output_dir, file_name) 208 path = os.path.join(output_dir, file_name)
208 209
209 # The build system should ensure our output directory exists, but just 210 # The build system should ensure our output directory exists, but just
210 # in case. 211 # in case.
(...skipping 30 matching lines...) Expand all
241 parser.add_argument("--developer_dir", help="Path to Xcode.") 242 parser.add_argument("--developer_dir", help="Path to Xcode.")
242 parser.add_argument("--output_dir", default=os.getcwd()) 243 parser.add_argument("--output_dir", default=os.getcwd())
243 args = parser.parse_args() 244 args = parser.parse_args()
244 245
245 if args.developer_dir: 246 if args.developer_dir:
246 os.environ["DEVELOPER_DIR"] = args.developer_dir 247 os.environ["DEVELOPER_DIR"] = args.developer_dir
247 248
248 writer = self._writer_class(args.files) 249 writer = self._writer_class(args.files)
249 writer.set_gperf_path(args.gperf) 250 writer.set_gperf_path(args.gperf)
250 writer.write_files(args.output_dir) 251 writer.write_files(args.output_dir)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/make_css_property_apis.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698