Commit 94d6253b authored by eustas@chromium.org's avatar eustas@chromium.org

Add devtools protocol constants generator to chrome/

BUG=373325

Review URL: https://codereview.chromium.org/297803003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272570 0039d316-1c4b-4281-b951-d872f2087c98
parent a78f5aae
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'devtools_protocol_constants',
'type': 'none',
'actions': [
{
'action_name': 'devtools_protocol_constants',
'variables': {
'blink_protocol': '../../../third_party/WebKit/Source/devtools/protocol.json',
'generator': '../../../content/public/browser/devtools_protocol_constants_generator.py',
'package': 'chrome'
},
'inputs': [
'<(blink_protocol)',
'<(generator)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.cc',
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.h'
],
'action':[
'python',
'<(generator)',
'<(package)',
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.cc',
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.h',
'<(blink_protocol)',
],
'message': 'Generating DevTools protocol constants from <(blink_protocol)'
}
],
},
],
}
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
'../third_party/icu/icu.gyp:icuuc', '../third_party/icu/icu.gyp:icuuc',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'../third_party/libusb/libusb.gyp:libusb', '../third_party/libusb/libusb.gyp:libusb',
'browser/devtools/devtools_protocol_constants.gyp:devtools_protocol_constants',
'chrome_resources.gyp:chrome_extra_resources', 'chrome_resources.gyp:chrome_extra_resources',
'chrome_resources.gyp:chrome_resources', 'chrome_resources.gyp:chrome_resources',
'chrome_resources.gyp:chrome_strings', 'chrome_resources.gyp:chrome_strings',
...@@ -77,6 +78,9 @@ ...@@ -77,6 +78,9 @@
'browser/devtools/devtools_window.h', 'browser/devtools/devtools_window.h',
'browser/devtools/remote_debugging_server.cc', 'browser/devtools/remote_debugging_server.cc',
'browser/devtools/remote_debugging_server.h', 'browser/devtools/remote_debugging_server.h',
# These files are generated by devtools_protocol_constants_generator.py.
'<(SHARED_INTERMEDIATE_DIR)/chrome/browser/devtools/devtools_protocol_constants.cc',
'<(SHARED_INTERMEDIATE_DIR)/chrome/browser/devtools/devtools_protocol_constants.h',
], ],
'conditions': [ 'conditions': [
['OS=="android"', { ['OS=="android"', {
......
...@@ -47,24 +47,27 @@ ...@@ -47,24 +47,27 @@
'action_name': 'devtools_protocol_constants', 'action_name': 'devtools_protocol_constants',
'variables': { 'variables': {
'blink_protocol': '../../../third_party/WebKit/Source/devtools/protocol.json', 'blink_protocol': '../../../third_party/WebKit/Source/devtools/protocol.json',
'browser_protocol': 'browser_protocol.json' 'browser_protocol': 'browser_protocol.json',
'generator': '../../public/browser/devtools_protocol_constants_generator.py',
'package': 'content'
}, },
'inputs': [ 'inputs': [
'<(blink_protocol)', '<(blink_protocol)',
'<(browser_protocol)', '<(browser_protocol)',
'devtools_protocol_constants_generator.py', '<(generator)',
], ],
'outputs': [ 'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/content/browser/devtools/devtools_protocol_constants.cc', '<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.cc',
'<(SHARED_INTERMEDIATE_DIR)/content/browser/devtools/devtools_protocol_constants.h' '<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.h'
], ],
'action':[ 'action':[
'python', 'python',
'devtools_protocol_constants_generator.py', '<(generator)',
'<(package)',
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.cc',
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.h',
'<(blink_protocol)', '<(blink_protocol)',
'<(browser_protocol)', '<(browser_protocol)',
'<(SHARED_INTERMEDIATE_DIR)/content/browser/devtools/devtools_protocol_constants.cc',
'<(SHARED_INTERMEDIATE_DIR)/content/browser/devtools/devtools_protocol_constants.h',
], ],
'message': 'Generating DevTools protocol constants from <(blink_protocol)' 'message': 'Generating DevTools protocol constants from <(blink_protocol)'
} }
......
#!/usr/bin/python #!/usr/bin/python
# Copyright 2013 The Chromium Authors. All rights reserved. # Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -7,23 +7,29 @@ import sys ...@@ -7,23 +7,29 @@ import sys
import string import string
import json import json
package = sys.argv[1]
output_cc_path = sys.argv[2]
output_h_path = sys.argv[3]
blink_protocol_path = sys.argv[4]
browser_protocol_path = sys.argv[5] if len(sys.argv) > 5 else None
template_h = string.Template("""\ template_h = string.Template("""\
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ #ifndef ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ #define ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
// THIS FILE IS AUTOGENERATED. DO NOT EDIT. // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// Generated by // Generated by
// content/browser/devtools/devtools_protocol_constants_generator.py from // content/public/browser/devtools_protocol_constants_generator.py from
// third_party/WebKit/Source/devtools/protocol.json and // third_party/WebKit/Source/devtools/protocol.json and
// content/browser/devtools/browser_protocol.json). // content/browser/devtools/browser_protocol.json
#include <string> #include <string>
namespace content { namespace $package {
namespace devtools { namespace devtools {
extern const char kProtocolVersion[]; extern const char kProtocolVersion[];
...@@ -34,9 +40,9 @@ extern const char kResult[]; ...@@ -34,9 +40,9 @@ extern const char kResult[];
$contents $contents
} // devtools } // devtools
} // content } // $package
#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_ #endif // ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
""") """)
template_cc = string.Template("""\ template_cc = string.Template("""\
...@@ -46,15 +52,15 @@ template_cc = string.Template("""\ ...@@ -46,15 +52,15 @@ template_cc = string.Template("""\
// THIS FILE IS AUTOGENERATED. DO NOT EDIT. // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// Generated by // Generated by
// content/browser/devtools/devtools_protocol_constants_generator.py from // content/public/browser/devtools_protocol_constants_generator.py from
// third_party/WebKit/Source/devtools/protocol.json and // third_party/WebKit/Source/devtools/protocol.json and
// content/browser/devtools/browser_protocol.json). // content/browser/devtools/browser_protocol.json
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/browser/devtools/devtools_protocol_constants.h" #include "$package/browser/devtools/devtools_protocol_constants.h"
namespace content { namespace $package {
namespace devtools { namespace devtools {
const char kProtocolVersion[] = "$major.$minor"; const char kProtocolVersion[] = "$major.$minor";
...@@ -72,7 +78,7 @@ const char kResult[] = "result"; ...@@ -72,7 +78,7 @@ const char kResult[] = "result";
$contents $contents
} // devtools } // devtools
} // content } // $package
""") """)
def Capitalize(s): def Capitalize(s):
...@@ -130,25 +136,31 @@ def FormatNamespace(title, tree, indent, format_string): ...@@ -130,25 +136,31 @@ def FormatNamespace(title, tree, indent, format_string):
def CreateHeader(tree, output_file): def CreateHeader(tree, output_file):
contents = FormatContents(tree, "", "extern const char {0}[];\n") contents = FormatContents(tree, "", "extern const char {0}[];\n")
output_file.write(template_h.substitute({"contents": contents})) output_file.write(template_h.substitute({
"contents": contents,
"package": package,
"PACKAGE": package.upper()
}))
def CreateBody(tree, version, output_file): def CreateBody(tree, version, output_file):
contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n") contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n")
output_file.write(template_cc.substitute({ output_file.write(template_cc.substitute({
"major": version["major"], "major": version["major"],
"minor": version["minor"], "minor": version["minor"],
"contents": contents "contents": contents,
"package": package
})) }))
blink_protocol_data = open(sys.argv[1]).read() blink_protocol_data = open(blink_protocol_path).read()
browser_protocol_data = open(sys.argv[2]).read()
blink_protocol = json.loads(blink_protocol_data) blink_protocol = json.loads(blink_protocol_data)
browser_protocol = json.loads(browser_protocol_data)
blink_version = blink_protocol["version"] blink_version = blink_protocol["version"]
domains = blink_protocol["domains"] + browser_protocol["domains"] domains = blink_protocol["domains"]
if browser_protocol_path:
browser_protocol_data = open(browser_protocol_path).read()
browser_protocol = json.loads(browser_protocol_data)
domains = domains + browser_protocol["domains"]
namespace_tree = {} namespace_tree = {}
...@@ -192,8 +204,8 @@ while (references): ...@@ -192,8 +204,8 @@ while (references):
for (namespace_name, namespace) in namespace_tree.items(): for (namespace_name, namespace) in namespace_tree.items():
namespace["kName"] = namespace_name namespace["kName"] = namespace_name
with open(sys.argv[3], "w") as f: with open(output_cc_path, "w") as f:
CreateBody(namespace_tree, blink_version, f) CreateBody(namespace_tree, blink_version, f)
with open(sys.argv[4], "w") as f: with open(output_h_path, "w") as f:
CreateHeader(namespace_tree, f) CreateHeader(namespace_tree, f)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment