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

Side by Side Diff: tools/dom/scripts/chromegenerator.py

Issue 12209045: Initial commit of generated dart:chrome app_window and app_runtime (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added chromegenerator.py, which (if run from its local directory), generates app_window and app_run… Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file.
5
6 """This module generates Dart Chrome APIs from the Chrome IDL files."""
7
8 import sys
9 import os
10
11 # The path to the JSON Schema Compiler, which can be run to generate the files.
blois 2013/02/08 00:08:04 This library structure was set up when we thought
sashab 2013/02/08 00:49:28 Agreed :)
12 # Lives in the Chromium repository, so needs to be pulled in somehow.
13 COMPILER = "../../../third_party/chrome_api_tools/compiler.py"
14
15 # The path to the Chrome IDL files. They live in the Chromium repository, so
16 # need to be pulled in somehow.
17 API_DIR = "../../../third_party/chrome_api/"
18
19 # The path to the custom overrides directory, containing override files.
20 OVERRIDES_DIR = "../src/chrome/custom_dart/"
21
22 # The path to where the generated .dart files should be saved.
23 OUTPUT_DIR = "../src/chrome/"
24
25 # The path to where the output template file is. This file will be populated
26 # with TEMPLATE_CONTENT, followed by the list of generated .dart files.
27 OUTPUT_TEMPLATE = "../templates/html/dart2js/chrome_dart2js.darttemplate"
28
29 # The content to fill OUTPUT_TEMPLATE with. Will be followed by a list of the
30 # names of the generated .dart files.
31 TEMPLATE_CONTENT = """
32 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
33 // for details. All rights reserved. Use of this source code is governed by a
34 // BSD-style license that can be found in the LICENSE file.
35
36 // DO NOT EDIT
37 // Auto-generated dart:chrome library.
38
39 library chrome;
40
41 import 'dart:_foreign_helper' show JS;
42 /* TODO(sashab): Add "show convertDartClosureToJS" once 'show' works. */
43 import 'dart:_js_helper';
44 import 'dart:html_common';
45 import 'dart:html';
46
47 part "$AUXILIARY_DIR/chrome/utils.dart";
48 part "$AUXILIARY_DIR/chrome/chrome.dart";
49
50 // Generated files below this line.
51 """
52
53 # The format for adding files to TEMPLATE_CONTENT. Will be substituted with the
54 # filename (not including the extension) of the IDL/JSON file.
55 TEMPLATE_FILE_FORMAT = 'part "$AUXILIARY_DIR/chrome/%s.dart";'
56
57 # A list of schema files to generate.
58 # TODO(sashab): Later, use the ones from API_DIR/api.gyp.
59 API_FILES = [
60 "app_window.idl",
61 "app_runtime.idl"
62 ]
63
64 if __name__ == "__main__":
65 # Generate each file.
66 for filename in API_FILES:
67 result = os.system('python "%s" -g dart -D "%s" -d "%s" -r "%s" "%s"' % (
68 COMPILER, OVERRIDES_DIR, OUTPUT_DIR, API_DIR,
69 os.path.join(API_DIR, filename)))
70 if result != 0:
71 print "Error occurred during generation of %s." % (
72 os.path.join(API_DIR, filename))
73 sys.exit(1)
74 else:
75 print "Generated %s successfully to %s.dart." % (
76 os.path.join(API_DIR, filename),
77 os.path.join(OUTPUT_DIR, os.path.splitext(filename)[1]))
78
79 # Generate the template.
80 files_to_add = (TEMPLATE_FILE_FORMAT % os.path.splitext(f)[0]
81 for f in API_FILES)
82 with open(OUTPUT_TEMPLATE, 'w') as template_file:
83 template_file.write(TEMPLATE_CONTENT)
84 template_file.write('\n'.join(files_to_add))
85 print "Generated template succesfully."
86
87
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698