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

Side by Side Diff: tools/json_schema_compiler/cpp_bundle_generator.py

Issue 2275063002: [Extensions] Don't generate a list for each generated schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: woot Created 4 years, 3 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 | « extensions/common/extension_api.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 import code 5 import code
6 import cpp_util 6 import cpp_util
7 from model import Platforms 7 from model import Platforms
8 from schema_util import CapitalizeFirstLetter 8 from schema_util import CapitalizeFirstLetter
9 from schema_util import JsFunctionNameToClassName 9 from schema_util import JsFunctionNameToClassName
10 10
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 c.Append(cpp_util.CHROMIUM_LICENSE) 319 c.Append(cpp_util.CHROMIUM_LICENSE)
320 c.Append() 320 c.Append()
321 c.Append('#include "%s"' % (os.path.join(self._bundle._source_file_dir, 321 c.Append('#include "%s"' % (os.path.join(self._bundle._source_file_dir,
322 'generated_schemas.h'))) 322 'generated_schemas.h')))
323 c.Append() 323 c.Append()
324 c.Append('#include "base/lazy_instance.h"') 324 c.Append('#include "base/lazy_instance.h"')
325 c.Append() 325 c.Append()
326 c.Append('namespace {') 326 c.Append('namespace {')
327 for api in self._bundle._api_defs: 327 for api in self._bundle._api_defs:
328 namespace = self._bundle._model.namespaces[api.get('namespace')] 328 namespace = self._bundle._model.namespaces[api.get('namespace')]
329 # JSON parsing code expects lists of schemas, so dump a singleton list. 329 json_content = json.dumps(_PrefixSchemaWithNamespace(
330 json_content = json.dumps([_PrefixSchemaWithNamespace( 330 _RemoveUnneededFields(api)),
331 _RemoveUnneededFields(api))],
332 separators=(',', ':')) 331 separators=(',', ':'))
333 # Escape all double-quotes and backslashes. For this to output a valid 332 # Escape all double-quotes and backslashes. For this to output a valid
334 # JSON C string, we need to escape \ and ". Note that some schemas are 333 # JSON C string, we need to escape \ and ". Note that some schemas are
335 # too large to compile on windows. Split the JSON up into several 334 # too large to compile on windows. Split the JSON up into several
336 # strings, since apparently that helps. 335 # strings, since apparently that helps.
337 max_length = 8192 336 max_length = 8192
338 segments = [json_content[i:i + max_length].replace('\\', '\\\\') 337 segments = [json_content[i:i + max_length].replace('\\', '\\\\')
339 .replace('"', '\\"') 338 .replace('"', '\\"')
340 for i in xrange(0, len(json_content), max_length)] 339 for i in xrange(0, len(json_content), max_length)]
341 c.Append('const char %s[] = "%s";' % 340 c.Append('const char %s[] = "%s";' %
(...skipping 25 matching lines...) Expand all
367 c.Append() 366 c.Append()
368 c.Append('// static') 367 c.Append('// static')
369 c.Sblock('bool %s::IsGenerated(std::string name) {' % 368 c.Sblock('bool %s::IsGenerated(std::string name) {' %
370 self._bundle._GenerateBundleClass('GeneratedSchemas')) 369 self._bundle._GenerateBundleClass('GeneratedSchemas'))
371 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') 370 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;')
372 c.Eblock('}') 371 c.Eblock('}')
373 c.Append() 372 c.Append()
374 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) 373 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace))
375 c.Append() 374 c.Append()
376 return c 375 return c
OLDNEW
« no previous file with comments | « extensions/common/extension_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698