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

Side by Side Diff: content/public/browser/devtools_protocol_constants_generator.py

Issue 297803003: Add devtools protocol constants generator to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 | « content/browser/devtools/devtools_resources.gyp ('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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 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]
11 output_cc_path = sys.argv[2]
12 output_h_path = sys.argv[3]
13 blink_protocol_path = sys.argv[4]
14 browser_protocol_path = sys.argv[5] if len(sys.argv) > 5 else None
15
10 template_h = string.Template("""\ 16 template_h = string.Template("""\
11 // Copyright 2013 The Chromium Authors. All rights reserved. 17 // Copyright 2013 The Chromium Authors. All rights reserved.
12 // 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
13 // found in the LICENSE file. 19 // found in the LICENSE file.
14 20
15 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ 21 #ifndef ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
16 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ 22 #define ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
17 23
18 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. 24 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
19 // Generated by 25 // Generated by
20 // content/browser/devtools/devtools_protocol_constants_generator.py from 26 // content/public/browser/devtools_protocol_constants_generator.py from
21 // third_party/WebKit/Source/devtools/protocol.json and 27 // third_party/WebKit/Source/devtools/protocol.json and
22 // content/browser/devtools/browser_protocol.json). 28 // content/browser/devtools/browser_protocol.json
23 29
24 #include <string> 30 #include <string>
25 31
26 namespace content { 32 namespace $package {
27 namespace devtools { 33 namespace devtools {
28 34
29 extern const char kProtocolVersion[]; 35 extern const char kProtocolVersion[];
30 36
31 bool IsSupportedProtocolVersion(const std::string& version); 37 bool IsSupportedProtocolVersion(const std::string& version);
32 38
33 extern const char kResult[]; 39 extern const char kResult[];
34 $contents 40 $contents
35 41
36 } // devtools 42 } // devtools
37 } // content 43 } // $package
38 44
39 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ 45 #endif // ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
40 """) 46 """)
41 47
42 template_cc = string.Template("""\ 48 template_cc = string.Template("""\
43 // Copyright 2013 The Chromium Authors. All rights reserved. 49 // Copyright 2013 The Chromium Authors. All rights reserved.
44 // 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
45 // found in the LICENSE file. 51 // found in the LICENSE file.
46 52
47 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. 53 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
48 // Generated by 54 // Generated by
49 // content/browser/devtools/devtools_protocol_constants_generator.py from 55 // content/public/browser/devtools_protocol_constants_generator.py from
50 // third_party/WebKit/Source/devtools/protocol.json and 56 // third_party/WebKit/Source/devtools/protocol.json and
51 // content/browser/devtools/browser_protocol.json). 57 // content/browser/devtools/browser_protocol.json
52 58
53 #include "base/strings/string_number_conversions.h" 59 #include "base/strings/string_number_conversions.h"
54 #include "base/strings/string_util.h" 60 #include "base/strings/string_util.h"
55 #include "content/browser/devtools/devtools_protocol_constants.h" 61 #include "$package/browser/devtools/devtools_protocol_constants.h"
56 62
57 namespace content { 63 namespace $package {
58 namespace devtools { 64 namespace devtools {
59 65
60 const char kProtocolVersion[] = "$major.$minor"; 66 const char kProtocolVersion[] = "$major.$minor";
61 67
62 bool IsSupportedProtocolVersion(const std::string& version) { 68 bool IsSupportedProtocolVersion(const std::string& version) {
63 std::vector<std::string> tokens; 69 std::vector<std::string> tokens;
64 Tokenize(version, ".", &tokens); 70 Tokenize(version, ".", &tokens);
65 int major, minor; 71 int major, minor;
66 return tokens.size() == 2 && 72 return tokens.size() == 2 &&
67 base::StringToInt(tokens[0], &major) && major == $major && 73 base::StringToInt(tokens[0], &major) && major == $major &&
68 base::StringToInt(tokens[1], &minor) && minor <= $minor; 74 base::StringToInt(tokens[1], &minor) && minor <= $minor;
69 } 75 }
70 76
71 const char kResult[] = "result"; 77 const char kResult[] = "result";
72 $contents 78 $contents
73 79
74 } // devtools 80 } // devtools
75 } // content 81 } // $package
76 """) 82 """)
77 83
78 def Capitalize(s): 84 def Capitalize(s):
79 return s[:1].capitalize() + s[1:] 85 return s[:1].capitalize() + s[1:]
80 86
81 references = [] 87 references = []
82 88
83 def CreateNamespace(domain_name, data, keys, prefixes, name = None): 89 def CreateNamespace(domain_name, data, keys, prefixes, name = None):
84 result = {} 90 result = {}
85 if name: 91 if name:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 def FormatNamespace(title, tree, indent, format_string): 129 def FormatNamespace(title, tree, indent, format_string):
124 if (not tree): 130 if (not tree):
125 return "" 131 return ""
126 body = '\n' + indent + "namespace " + title + " {\n" 132 body = '\n' + indent + "namespace " + title + " {\n"
127 body += FormatContents(tree, indent + " ", format_string) 133 body += FormatContents(tree, indent + " ", format_string)
128 body += indent + "} // " + title + "\n" 134 body += indent + "} // " + title + "\n"
129 return body 135 return body
130 136
131 def CreateHeader(tree, output_file): 137 def CreateHeader(tree, output_file):
132 contents = FormatContents(tree, "", "extern const char {0}[];\n") 138 contents = FormatContents(tree, "", "extern const char {0}[];\n")
133 output_file.write(template_h.substitute({"contents": contents})) 139 output_file.write(template_h.substitute({
140 "contents": contents,
141 "package": package,
142 "PACKAGE": package.upper()
143 }))
134 144
135 def CreateBody(tree, version, output_file): 145 def CreateBody(tree, version, output_file):
136 contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n") 146 contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n")
137 output_file.write(template_cc.substitute({ 147 output_file.write(template_cc.substitute({
138 "major": version["major"], 148 "major": version["major"],
139 "minor": version["minor"], 149 "minor": version["minor"],
140 "contents": contents 150 "contents": contents,
151 "package": package
141 })) 152 }))
142 153
143 blink_protocol_data = open(sys.argv[1]).read() 154 blink_protocol_data = open(blink_protocol_path).read()
144 browser_protocol_data = open(sys.argv[2]).read()
145
146 blink_protocol = json.loads(blink_protocol_data) 155 blink_protocol = json.loads(blink_protocol_data)
147 browser_protocol = json.loads(browser_protocol_data)
148
149 blink_version = blink_protocol["version"] 156 blink_version = blink_protocol["version"]
150 157
151 domains = blink_protocol["domains"] + browser_protocol["domains"] 158 domains = blink_protocol["domains"]
159
160 if browser_protocol_path:
161 browser_protocol_data = open(browser_protocol_path).read()
162 browser_protocol = json.loads(browser_protocol_data)
163 domains = domains + browser_protocol["domains"]
152 164
153 namespace_tree = {} 165 namespace_tree = {}
154 166
155 for domain in domains: 167 for domain in domains:
156 domain_value = {} 168 domain_value = {}
157 domain_namespace_name = Capitalize(domain["domain"]) 169 domain_namespace_name = Capitalize(domain["domain"])
158 if "commands" in domain: 170 if "commands" in domain:
159 for command in domain["commands"]: 171 for command in domain["commands"]:
160 if (IsHandledInBrowser(command)): 172 if (IsHandledInBrowser(command)):
161 domain_value[command["name"]] = CreateNamespace(domain["domain"], 173 domain_value[command["name"]] = CreateNamespace(domain["domain"],
(...skipping 23 matching lines...) Expand all
185 ref_type = [t for t in domain["types"] if t["id"] == path[1]][0] 197 ref_type = [t for t in domain["types"] if t["id"] == path[1]][0]
186 parent_namespace[ref_type["id"]] = CreateNamespace(path[0], 198 parent_namespace[ref_type["id"]] = CreateNamespace(path[0],
187 ref_type, ["properties"], ["kParam"]) 199 ref_type, ["properties"], ["kParam"])
188 except IndexError: 200 except IndexError:
189 sys.stderr.write("Failed to resolve type [{0}].\n".format(reference)) 201 sys.stderr.write("Failed to resolve type [{0}].\n".format(reference))
190 sys.exit(1) 202 sys.exit(1)
191 203
192 for (namespace_name, namespace) in namespace_tree.items(): 204 for (namespace_name, namespace) in namespace_tree.items():
193 namespace["kName"] = namespace_name 205 namespace["kName"] = namespace_name
194 206
195 with open(sys.argv[3], "w") as f: 207 with open(output_cc_path, "w") as f:
196 CreateBody(namespace_tree, blink_version, f) 208 CreateBody(namespace_tree, blink_version, f)
197 209
198 with open(sys.argv[4], "w") as f: 210 with open(output_h_path, "w") as f:
199 CreateHeader(namespace_tree, f) 211 CreateHeader(namespace_tree, f)
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_resources.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698