Commit 1d5d6a04 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector_protocol] roll to 752d4abd13119010cf30e454e8ef9b5fb7ef43a3

Includes:
- Better windows support in json generator.
- Add PDL2JSON, don't paste descriptions as comments into generated code.
- [inspector_protocol] generated only used types

R=pfeldman@chromium.org

Bug: none
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I3c634359b3ac4b00293ac7c5ee224dab53aae7ca
Reviewed-on: https://chromium-review.googlesource.com/810204
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49949}
parent f2e19a63
......@@ -12,5 +12,8 @@ yangguo@chromium.org
per-file js_protocol.json=set noparent
per-file js_protocol.json=dgozman@chromium.org
per-file js_protocol.json=pfeldman@chromium.org
per-file js_protocol.pdl=set noparent
per-file js_protocol.pdl=dgozman@chromium.org
per-file js_protocol.pdl=pfeldman@chromium.org
# COMPONENT: Platform>DevTools>JavaScript
This diff is collapsed.
......@@ -325,6 +325,7 @@ class Protocol(object):
self.patch_full_qualified_refs()
self.create_notification_types()
self.create_type_definitions()
self.generate_used_types()
def read_protocol_file(self, file_name):
......@@ -362,6 +363,56 @@ class Protocol(object):
patch_full_qualified_refs_in_domain(domain, domain["domain"])
def all_references(self, json):
refs = set()
if isinstance(json, list):
for item in json:
refs |= self.all_references(item)
if not isinstance(json, dict):
return refs
for key in json:
if key != "$ref":
refs |= self.all_references(json[key])
else:
refs.add(json["$ref"])
return refs
def generate_used_types(self):
all_refs = set()
for domain in self.json_api["domains"]:
domain_name = domain["domain"]
if "commands" in domain:
for command in domain["commands"]:
if self.generate_command(domain_name, command["name"]):
all_refs |= self.all_references(command)
if "events" in domain:
for event in domain["events"]:
if self.generate_event(domain_name, event["name"]):
all_refs |= self.all_references(event)
all_refs.add(domain_name + "." + to_title_case(event["name"]) + "Notification")
dependencies = self.generate_type_dependencies()
queue = set(all_refs)
while len(queue):
ref = queue.pop()
if ref in dependencies:
queue |= dependencies[ref] - all_refs
all_refs |= dependencies[ref]
self.used_types = all_refs
def generate_type_dependencies(self):
dependencies = dict()
domains_with_types = (x for x in self.json_api["domains"] if "types" in x)
for domain in domains_with_types:
domain_name = domain["domain"]
for type in domain["types"]:
related_types = self.all_references(type)
if len(related_types):
dependencies[domain_name + "." + type["id"]] = related_types
return dependencies
def create_notification_types(self):
for domain in self.json_api["domains"]:
if "events" in domain:
......@@ -444,9 +495,7 @@ class Protocol(object):
def generate_type(self, domain, typename):
if not self.config.protocol.options:
return domain in self.generate_domains
return self.check_options(self.config.protocol.options, domain, typename, "include_types", "exclude_types", True)
return domain + "." + typename in self.used_types
def is_async_command(self, domain, command):
......
# Copyright 2017 the V8 project authors. All rights reserved.
# Copyright 2017 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.
......@@ -61,7 +61,9 @@ def parse(data):
trimLine = line.strip()
if trimLine.startswith('#'):
description += trimLine[1:]
if len(description):
description += '\n'
description += trimLine[2:]
continue
else:
nukeDescription = True
......@@ -161,18 +163,20 @@ def parse(data):
def main(argv):
if len(argv) < 2:
sys.stderr.write("Usage: %s stamp <protocol.pdl>\n" % sys.argv[0])
sys.stderr.write("Usage: %s <protocol.pdl> <protocol.json>\n" % sys.argv[0])
return 1
global file_name
file_name = os.path.normpath(argv[1])
file_name = os.path.normpath(argv[0])
input_file = open(file_name, "r")
pdl_string = input_file.read()
protocol = parse(pdl_string)
output_file = open(argv[1].replace('.pdl', '.json'), "w")
output_file = open(argv[0].replace('.pdl', '.json'), 'wb')
json.dump(protocol, output_file, indent=4, separators=(',', ': '))
output_file.close()
output_file = open(os.path.normpath(argv[1]), 'wb')
json.dump(protocol, output_file, indent=4, separators=(',', ': '))
output_file.close()
with open(os.path.normpath(argv[0]), 'a') as _:
pass
if __name__ == '__main__':
......
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 65caa48c1d301e35f60b94ae770b0c68c34960d4
Revision: 752d4abd13119010cf30e454e8ef9b5fb7ef43a3
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -118,23 +118,6 @@ void DispatcherBase::markFallThrough(int callbackId)
m_lastCallbackFallThrough = true;
}
// static
bool DispatcherBase::getCommandName(const String& message, String* result)
{
std::unique_ptr<protocol::Value> value = StringUtil::parseJSON(message);
if (!value)
return false;
protocol::DictionaryValue* object = DictionaryValue::cast(value.get());
if (!object)
return false;
if (!object->getString("method", result))
return false;
return true;
}
void DispatcherBase::sendResponse(int callId, const DispatchResponse& response, std::unique_ptr<protocol::DictionaryValue> result)
{
if (!m_frontendChannel)
......@@ -272,7 +255,7 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
if (outCallId)
*outCallId = callId;
if (!success) {
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty");
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' property");
return DispatchResponse::kError;
}
......@@ -282,7 +265,7 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
if (outMethod)
*outMethod = method;
if (!success) {
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr);
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' property", nullptr);
return DispatchResponse::kError;
}
......@@ -308,6 +291,29 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
return it->second->dispatch(callId, method, std::move(messageObject));
}
bool UberDispatcher::getCommandName(const String& message, String* method, std::unique_ptr<protocol::DictionaryValue>* parsedMessage)
{
std::unique_ptr<protocol::Value> value = StringUtil::parseJSON(message);
if (!value) {
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
return false;
}
protocol::DictionaryValue* object = DictionaryValue::cast(value.get());
if (!object) {
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must be an object");
return false;
}
if (!object->getString("method", method)) {
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have string 'method' property");
return false;
}
parsedMessage->reset(DictionaryValue::cast(value.release()));
return true;
}
UberDispatcher::~UberDispatcher() = default;
// static
......
......@@ -85,8 +85,6 @@ public:
explicit DispatcherBase(FrontendChannel*);
virtual ~DispatcherBase();
static bool getCommandName(const String& message, String* result);
virtual DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) = 0;
void sendResponse(int callId, const DispatchResponse&, std::unique_ptr<protocol::DictionaryValue> result);
......@@ -118,6 +116,7 @@ public:
FrontendChannel* channel() { return m_frontendChannel; }
bool fallThroughForNotFound() { return m_fallThroughForNotFound; }
void setFallThroughForNotFound(bool);
bool getCommandName(const String& message, String* method, std::unique_ptr<protocol::DictionaryValue>* parsedMessage);
virtual ~UberDispatcher();
private:
......
......@@ -32,14 +32,11 @@ namespace {{domain.domain}} {
{% if not protocol.generate_type(domain.domain, type.id) %}{% continue %}{% endif %}
{% if type.type == "object" %}
{% if "properties" in type %}
// {{type.description}}
class {{type.id}};
{% else %}
// {{type.description}}
using {{type.id}} = Object;
{% endif %}
{% elif type.type != "array" %}
// {{type.description}}
using {{type.id}} = {{protocol.resolve_type(type).type}};
{% endif %}
{% endfor %}
......@@ -74,7 +71,6 @@ namespace {{param.name | to_title_case}}Enum {
{% if not protocol.generate_type(domain.domain, type.id) %}{% continue %}{% endif %}
{% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
// {{type.description}}
class {{config.protocol.export_macro}} {{type.id}} : public Serializable{% if protocol.is_exported(domain.domain, type.id) %}, public API::{{type.id}}{% endif %}{
PROTOCOL_DISALLOW_COPY({{type.id}});
public:
......
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