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 @@
'../third_party/icu/icu.gyp:icuuc',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'../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_resources',
'chrome_resources.gyp:chrome_strings',
......@@ -77,6 +78,9 @@
'browser/devtools/devtools_window.h',
'browser/devtools/remote_debugging_server.cc',
'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': [
['OS=="android"', {
......
......@@ -47,24 +47,27 @@
'action_name': 'devtools_protocol_constants',
'variables': {
'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': [
'<(blink_protocol)',
'<(browser_protocol)',
'devtools_protocol_constants_generator.py',
'<(generator)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/content/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.cc',
'<(SHARED_INTERMEDIATE_DIR)/<(package)/browser/devtools/devtools_protocol_constants.h'
],
'action':[
'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)',
'<(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)'
}
......
#!/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
# found in the LICENSE file.
......@@ -7,23 +7,29 @@ import sys
import string
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("""\
// Copyright 2013 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.
#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
#ifndef ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
#define ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// 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
// content/browser/devtools/browser_protocol.json).
// content/browser/devtools/browser_protocol.json
#include <string>
namespace content {
namespace $package {
namespace devtools {
extern const char kProtocolVersion[];
......@@ -34,9 +40,9 @@ extern const char kResult[];
$contents
} // devtools
} // content
} // $package
#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
#endif // ${PACKAGE}_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_CONSTANTS_H_
""")
template_cc = string.Template("""\
......@@ -46,15 +52,15 @@ template_cc = string.Template("""\
// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// 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
// content/browser/devtools/browser_protocol.json).
// content/browser/devtools/browser_protocol.json
#include "base/strings/string_number_conversions.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 {
const char kProtocolVersion[] = "$major.$minor";
......@@ -72,7 +78,7 @@ const char kResult[] = "result";
$contents
} // devtools
} // content
} // $package
""")
def Capitalize(s):
......@@ -130,25 +136,31 @@ def FormatNamespace(title, tree, indent, format_string):
def CreateHeader(tree, output_file):
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):
contents = FormatContents(tree, "", "const char {0}[] = \"{1}\";\n")
output_file.write(template_cc.substitute({
"major": version["major"],
"minor": version["minor"],
"contents": contents
"contents": contents,
"package": package
}))
blink_protocol_data = open(sys.argv[1]).read()
browser_protocol_data = open(sys.argv[2]).read()
blink_protocol_data = open(blink_protocol_path).read()
blink_protocol = json.loads(blink_protocol_data)
browser_protocol = json.loads(browser_protocol_data)
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 = {}
......@@ -192,8 +204,8 @@ while (references):
for (namespace_name, namespace) in namespace_tree.items():
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)
with open(sys.argv[4], "w") as f:
with open(output_h_path, "w") as 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