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

Side by Side Diff: chrome/browser/devtools/devtools_protocol_constants_generator.py

Issue 2035653005: DevTools: split protocol.json into files per domain. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import sys 6 import sys
7 import string 7 import string
8 import json 8 import json
9 9
10 package = sys.argv[1] 10 package = sys.argv[1]
11 output_cc_path = sys.argv[2] 11 output_cc_path = sys.argv[2]
12 output_h_path = sys.argv[3] 12 output_h_path = sys.argv[3]
13 blink_protocol_path = sys.argv[4] 13 blink_protocol_path = sys.argv[4]
14 browser_protocol_path = sys.argv[5] if len(sys.argv) > 5 else None 14 browser_protocol_path = sys.argv[5] if len(sys.argv) > 5 else None
15 15
16 template_h = string.Template("""\ 16 template_h = string.Template("""\
17 // Copyright 2013 The Chromium Authors. All rights reserved. 17 // Copyright 2013 The Chromium Authors. All rights reserved.
18 // Use of this source code is governed by a BSD-style license that can be 18 // Use of this source code is governed by a BSD-style license that can be
19 // found in the LICENSE file. 19 // found in the LICENSE file.
20 20
21 #ifndef ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ 21 #ifndef ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
22 #define ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ 22 #define ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
23 23
24 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. 24 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
25 // Generated by 25 // Generated by
26 // chrome/browser/devtools/devtools_protocol_constants_generator.py from 26 // chrome/browser/devtools/devtools_protocol_constants_generator.py from
27 // third_party/WebKit/Source/devtools/protocol.json and 27 // gen/blink/core/inspector/protocol/inspector.json and
28 // content/browser/devtools/browser_protocol.json 28 // content/browser/devtools/browser_protocol.json
29 29
30 #include <string> 30 #include <string>
31 31
32 namespace $package { 32 namespace $package {
33 namespace devtools { 33 namespace devtools {
34 34
35 extern const char kProtocolVersion[]; 35 extern const char kProtocolVersion[];
36 36
37 bool IsSupportedProtocolVersion(const std::string& version); 37 bool IsSupportedProtocolVersion(const std::string& version);
38 38
39 extern const char kResult[]; 39 extern const char kResult[];
40 $contents 40 $contents
41 41
42 } // devtools 42 } // devtools
43 } // $package 43 } // $package
44 44
45 #endif // ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ 45 #endif // ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
46 """) 46 """)
47 47
48 template_cc = string.Template("""\ 48 template_cc = string.Template("""\
49 // Copyright 2013 The Chromium Authors. All rights reserved. 49 // Copyright 2013 The Chromium Authors. All rights reserved.
50 // Use of this source code is governed by a BSD-style license that can be 50 // Use of this source code is governed by a BSD-style license that can be
51 // found in the LICENSE file. 51 // found in the LICENSE file.
52 52
53 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. 53 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
54 // Generated by 54 // Generated by
55 // chrome/browser/devtools/devtools_protocol_constants_generator.py from 55 // chrome/browser/devtools/devtools_protocol_constants_generator.py from
56 // third_party/WebKit/Source/devtools/protocol.json and 56 // gen/blink/core/inspector/protocol/inspector.json and
57 // content/browser/devtools/browser_protocol.json 57 // content/browser/devtools/browser_protocol.json
58 58
59 #include "base/strings/string_number_conversions.h" 59 #include "base/strings/string_number_conversions.h"
60 #include "base/strings/string_split.h" 60 #include "base/strings/string_split.h"
61 #include "base/strings/string_util.h" 61 #include "base/strings/string_util.h"
62 #include "$package/browser/devtools/devtools_protocol_constants.h" 62 #include "$package/browser/devtools/devtools_protocol_constants.h"
63 63
64 namespace $package { 64 namespace $package {
65 namespace devtools { 65 namespace devtools {
66 66
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return body 136 return body
137 137
138 def CreateHeader(tree, output_file): 138 def CreateHeader(tree, output_file):
139 contents = FormatContents(tree, "", "extern const char {0}[];\n") 139 contents = FormatContents(tree, "", "extern const char {0}[];\n")
140 output_file.write(template_h.substitute({ 140 output_file.write(template_h.substitute({
141 "contents": contents, 141 "contents": contents,
142 "package": package, 142 "package": package,
143 "PACKAGE": package.upper() 143 "PACKAGE": package.upper()
144 })) 144 }))
145 145
146 def CreateBody(tree, version, output_file): 146 def CreateBody(tree, output_file):
147 contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n") 147 contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n")
148 output_file.write(template_cc.substitute({ 148 output_file.write(template_cc.substitute({
149 "major": version["major"], 149 "major": "1",
150 "minor": version["minor"], 150 "minor": "1",
151 "contents": contents, 151 "contents": contents,
152 "package": package 152 "package": package
153 })) 153 }))
154 154
155 blink_protocol_data = open(blink_protocol_path).read() 155 blink_protocol_data = open(blink_protocol_path).read()
156 blink_protocol = json.loads(blink_protocol_data) 156 blink_protocol = json.loads(blink_protocol_data)
157 blink_version = blink_protocol["version"]
158 157
159 domains = blink_protocol["domains"] 158 domains = blink_protocol["domains"]
160 159
161 if browser_protocol_path: 160 if browser_protocol_path:
162 browser_protocol_data = open(browser_protocol_path).read() 161 browser_protocol_data = open(browser_protocol_path).read()
163 browser_protocol = json.loads(browser_protocol_data) 162 browser_protocol = json.loads(browser_protocol_data)
164 domains = domains + browser_protocol["domains"] 163 domains = domains + browser_protocol["domains"]
165 164
166 namespace_tree = {} 165 namespace_tree = {}
167 166
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 parent_namespace[ref_type["id"]] = CreateNamespace(path[0], 198 parent_namespace[ref_type["id"]] = CreateNamespace(path[0],
200 ref_type, ["properties"], ["kParam"]) 199 ref_type, ["properties"], ["kParam"])
201 except IndexError: 200 except IndexError:
202 sys.stderr.write("Failed to resolve type [{0}].\n".format(reference)) 201 sys.stderr.write("Failed to resolve type [{0}].\n".format(reference))
203 sys.exit(1) 202 sys.exit(1)
204 203
205 for (namespace_name, namespace) in namespace_tree.items(): 204 for (namespace_name, namespace) in namespace_tree.items():
206 namespace["kName"] = namespace_name 205 namespace["kName"] = namespace_name
207 206
208 with open(output_cc_path, "w") as f: 207 with open(output_cc_path, "w") as f:
209 CreateBody(namespace_tree, blink_version, f) 208 CreateBody(namespace_tree, f)
210 209
211 with open(output_h_path, "w") as f: 210 with open(output_h_path, "w") as f:
212 CreateHeader(namespace_tree, f) 211 CreateHeader(namespace_tree, f)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698