Commit b102970c authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Roll inspector_protocol to 0d4255502019144a5dec5669d7992165ae8924e7.

https://chromium.googlesource.com/deps/inspector_protocol/+/0d4255502019144a5dec5669d7992165ae8924e7

Change-Id: I3711883a4cff11f71cca10054e4aac11293f5293
Reviewed-on: https://chromium-review.googlesource.com/1139095Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54503}
parent a8cb6a72
This diff is collapsed.
# Copyright 2017 The Chromium Authors. All rights reserved.
#!/usr/bin/env python
# Copyright 2018 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.
import collections
import json
import os.path
import re
import sys
import convert_protocol_to_json
file_name = None
description = ''
primitiveTypes = ['integer', 'number', 'boolean', 'string', 'object', 'any', 'array']
def assignType(item, type, isArray=False):
if isArray:
item['type'] = 'array'
item['items'] = collections.OrderedDict()
assignType(item['items'], type)
return
if type == 'enum':
type = 'string'
if type in primitiveTypes:
item['type'] = type
else:
item['$ref'] = type
def createItem(d, experimental, deprecated, name=None):
result = collections.OrderedDict(d)
if name:
result['name'] = name
global description
if description:
result['description'] = description.strip()
if experimental:
result['experimental'] = True
if deprecated:
result['deprecated'] = True
return result
def parse(data):
protocol = collections.OrderedDict()
protocol['version'] = collections.OrderedDict()
protocol['domains'] = []
domain = None
item = None
subitems = None
nukeDescription = False
global description
lines = data.split('\n')
for i in range(0, len(lines)):
if nukeDescription:
description = ''
nukeDescription = False
line = lines[i]
trimLine = line.strip()
if trimLine.startswith('#'):
if len(description):
description += '\n'
description += trimLine[2:]
continue
else:
nukeDescription = True
if len(trimLine) == 0:
continue
match = re.compile('^(experimental )?(deprecated )?domain (.*)').match(line)
if match:
domain = createItem({'domain' : match.group(3)}, match.group(1), match.group(2))
protocol['domains'].append(domain)
continue
match = re.compile('^ depends on ([^\s]+)').match(line)
if match:
if 'dependencies' not in domain:
domain['dependencies'] = []
domain['dependencies'].append(match.group(1))
continue
match = re.compile('^ (experimental )?(deprecated )?type (.*) extends (array of )?([^\s]+)').match(line)
if match:
if 'types' not in domain:
domain['types'] = []
item = createItem({'id': match.group(3)}, match.group(1), match.group(2))
assignType(item, match.group(5), match.group(4))
domain['types'].append(item)
continue
match = re.compile('^ (experimental )?(deprecated )?(command|event) (.*)').match(line)
if match:
list = []
if match.group(3) == 'command':
if 'commands' in domain:
list = domain['commands']
else:
list = domain['commands'] = []
else:
if 'events' in domain:
list = domain['events']
else:
list = domain['events'] = []
item = createItem({}, match.group(1), match.group(2), match.group(4))
list.append(item)
continue
match = re.compile('^ (experimental )?(deprecated )?(optional )?(array of )?([^\s]+) ([^\s]+)').match(line)
if match:
param = createItem({}, match.group(1), match.group(2), match.group(6))
if match.group(3):
param['optional'] = True
assignType(param, match.group(5), match.group(4))
if match.group(5) == 'enum':
enumliterals = param['enum'] = []
subitems.append(param)
continue
match = re.compile('^ (parameters|returns|properties)').match(line)
if match:
subitems = item[match.group(1)] = []
continue
match = re.compile('^ enum').match(line)
if match:
enumliterals = item['enum'] = []
continue
match = re.compile('^version').match(line)
if match:
continue
match = re.compile('^ major (\d+)').match(line)
if match:
protocol['version']['major'] = match.group(1)
continue
match = re.compile('^ minor (\d+)').match(line)
if match:
protocol['version']['minor'] = match.group(1)
continue
match = re.compile('^ redirect ([^\s]+)').match(line)
if match:
item['redirect'] = match.group(1)
continue
match = re.compile('^ ( )?[^\s]+$').match(line)
if match:
# enum literal
enumliterals.append(trimLine)
continue
print 'Error in %s:%s, illegal token: \t%s' % (file_name, i, line)
sys.exit(1)
return protocol
def main(argv):
if len(argv) < 2:
sys.stderr.write("Usage: %s <protocol.pdl> <protocol.json>\n" % sys.argv[0])
return 1
global file_name
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[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()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
def main():
convert_protocol_to_json.main()
# Chromium inspector (devtools) protocol
This package contains code generators and templates for the Chromium
inspector protocol.
In the Chromium tree, it's rolled into
https://cs.chromium.org/chromium/src/third_party/inspector_protocol/
In the V8 tree, it's rolled into
https://cs.chromium.org/chromium/src/v8/third_party/inspector_protocol/
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 752d4abd13119010cf30e454e8ef9b5fb7ef43a3
Revision: 0d4255502019144a5dec5669d7992165ae8924e7
License: BSD
License File: LICENSE
Security Critical: no
......
This diff is collapsed.
This diff is collapsed.
# This file is used by git-cl to get repository specific information.
CC_LIST: chromium-reviews@chromium.org
CODE_REVIEW_SERVER: codereview.chromium.org
GERRIT_HOST: True
PROJECT: inspector_protocol
VIEW_VC: https://chromium.googlesource.com/deps/inspector_protocol/+/
......@@ -11,6 +11,7 @@ try:
except ImportError:
import simplejson as json
import pdl
def main(argv):
if len(argv) < 1:
......@@ -25,8 +26,7 @@ def main(argv):
sys.stderr.write("Cannot find %s\n" % file_name)
return 1
input_file = open(file_name, "r")
json_string = input_file.read()
parsed_json = json.loads(json_string)
parsed_json = pdl.loads(input_file.read(), file_name)
domains += parsed_json["domains"]
version = parsed_json["version"]
......
#!/usr/bin/env python
# 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.
import collections
import json
import os.path
import re
import sys
import pdl
def main(argv):
if len(argv) < 2:
sys.stderr.write("Usage: %s <protocol.pdl> <protocol.json>\n" % sys.argv[0])
return 1
file_name = os.path.normpath(argv[0])
input_file = open(file_name, "r")
pdl_string = input_file.read()
protocol = pdl.loads(pdl_string, file_name)
input_file.close()
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()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
......@@ -27,13 +27,12 @@ template("inspector_protocol_generate") {
inspector_protocol_dir = invoker.inspector_protocol_dir
action(target_name) {
script = "$inspector_protocol_dir/CodeGenerator.py"
script = "$inspector_protocol_dir/code_generator.py"
inputs = [
invoker.config_file,
"$inspector_protocol_dir/lib/Allocator_h.template",
"$inspector_protocol_dir/lib/Array_h.template",
"$inspector_protocol_dir/lib/Collections_h.template",
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_h.template",
"$inspector_protocol_dir/lib/ErrorSupport_cpp.template",
......
......@@ -7,7 +7,6 @@
'inspector_protocol_files': [
'lib/Allocator_h.template',
'lib/Array_h.template',
'lib/Collections_h.template',
'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template',
'lib/ErrorSupport_cpp.template',
......@@ -27,7 +26,7 @@
'templates/Imported_h.template',
'templates/TypeBuilder_cpp.template',
'templates/TypeBuilder_h.template',
'CodeGenerator.py',
'code_generator.py',
]
}
}
// Copyright 2016 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 {{"_".join(config.protocol.namespace)}}_Collections_h
#define {{"_".join(config.protocol.namespace)}}_Collections_h
#include {{format_include(config.protocol.package, "Forward")}}
#include <cstddef>
#if defined(__APPLE__) && !defined(_LIBCPP_VERSION)
#include <map>
#include <set>
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
template <class Key, class T> using HashMap = std::map<Key, T>;
template <class Key> using HashSet = std::set<Key>;
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#else
#include <unordered_map>
#include <unordered_set>
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
template <class Key, class T> using HashMap = std::unordered_map<Key, T>;
template <class Key> using HashSet = std::unordered_set<Key>;
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // defined(__APPLE__) && !defined(_LIBCPP_VERSION)
#endif // !defined({{"_".join(config.protocol.namespace)}}_Collections_h)
......@@ -231,7 +231,7 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco
m_dispatchers[name] = std::move(dispatcher);
}
void UberDispatcher::setupRedirects(const HashMap<String, String>& redirects)
void UberDispatcher::setupRedirects(const std::unordered_map<String, String>& redirects)
{
for (const auto& pair : redirects)
m_redirects[pair.first] = pair.second;
......@@ -269,7 +269,7 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
return DispatchResponse::kError;
}
HashMap<String, String>::iterator redirectIt = m_redirects.find(method);
std::unordered_map<String, String>::iterator redirectIt = m_redirects.find(method);
if (redirectIt != m_redirects.end())
method = redirectIt->second;
......
......@@ -5,9 +5,8 @@
#ifndef {{"_".join(config.protocol.namespace)}}_DispatcherBase_h
#define {{"_".join(config.protocol.namespace)}}_DispatcherBase_h
//#include "Collections.h"
//#include "ErrorSupport.h"
//#include "Forward.h"
//#include "ErrorSupport.h"
//#include "Values.h"
{% for namespace in config.protocol.namespace %}
......@@ -101,7 +100,7 @@ public:
private:
FrontendChannel* m_frontendChannel;
protocol::HashSet<WeakPtr*> m_weakPtrs;
std::unordered_set<WeakPtr*> m_weakPtrs;
int m_lastCallbackId;
bool m_lastCallbackFallThrough;
};
......@@ -111,7 +110,7 @@ class {{config.lib.export_macro}} UberDispatcher {
public:
explicit UberDispatcher(FrontendChannel*);
void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
void setupRedirects(const HashMap<String, String>&);
void setupRedirects(const std::unordered_map<String, String>&);
DispatchResponse::Status dispatch(std::unique_ptr<Value> message, int* callId = nullptr, String* method = nullptr);
FrontendChannel* channel() { return m_frontendChannel; }
bool fallThroughForNotFound() { return m_fallThroughForNotFound; }
......@@ -122,8 +121,8 @@ public:
private:
FrontendChannel* m_frontendChannel;
bool m_fallThroughForNotFound;
HashMap<String, String> m_redirects;
protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
std::unordered_map<String, String> m_redirects;
std::unordered_map<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
};
class InternalResponse : public Serializable {
......
......@@ -5,7 +5,7 @@
#ifndef {{"_".join(config.protocol.namespace)}}_ErrorSupport_h
#define {{"_".join(config.protocol.namespace)}}_ErrorSupport_h
//#include "Forward.h"
#include {{format_include(config.protocol.package, "Forward")}}
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
......
......@@ -10,7 +10,10 @@
{% endif %}
#include {{format_include(config.lib.string_header)}}
#include <cstddef>
#include <vector>
#include <unordered_map>
#include <unordered_set>
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
......
......@@ -425,9 +425,8 @@ std::unique_ptr<Value> buildValue(const Char* start, const Char* end, const Char
double value = charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok);
if (!ok)
return nullptr;
int number = static_cast<int>(value);
if (number == value)
result = FundamentalValue::create(number);
if (value >= INT_MIN && value <= INT_MAX && static_cast<int>(value) == value)
result = FundamentalValue::create(static_cast<int>(value));
else
result = FundamentalValue::create(value);
break;
......
......@@ -7,6 +7,6 @@
#include {{format_include(config.protocol.package, "Protocol")}}
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
......@@ -6,7 +6,6 @@
#define {{"_".join(config.protocol.namespace)}}_Values_h
//#include "Allocator.h"
//#include "Collections.h"
//#include "Forward.h"
{% for namespace in config.protocol.namespace %}
......@@ -200,7 +199,7 @@ private:
m_order.push_back(key);
}
using Dictionary = protocol::HashMap<String, std::unique_ptr<Value>>;
using Dictionary = std::unordered_map<String, std::unique_ptr<Value>>;
Dictionary m_data;
std::vector<String> m_order;
};
......
# Copyright 2018 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.
import collections
import json
import os.path
import re
import sys
description = ''
primitiveTypes = ['integer', 'number', 'boolean', 'string', 'object', 'any', 'array']
def assignType(item, type, isArray=False):
if isArray:
item['type'] = 'array'
item['items'] = collections.OrderedDict()
assignType(item['items'], type)
return
if type == 'enum':
type = 'string'
if type in primitiveTypes:
item['type'] = type
else:
item['$ref'] = type
def createItem(d, experimental, deprecated, name=None):
result = collections.OrderedDict(d)
if name:
result['name'] = name
global description
if description:
result['description'] = description.strip()
if experimental:
result['experimental'] = True
if deprecated:
result['deprecated'] = True
return result
def parse(data, file_name):
protocol = collections.OrderedDict()
protocol['version'] = collections.OrderedDict()
protocol['domains'] = []
domain = None
item = None
subitems = None
nukeDescription = False
global description
lines = data.split('\n')
for i in range(0, len(lines)):
if nukeDescription:
description = ''
nukeDescription = False
line = lines[i]
trimLine = line.strip()
if trimLine.startswith('#'):
if len(description):
description += '\n'
description += trimLine[2:]
continue
else:
nukeDescription = True
if len(trimLine) == 0:
continue
match = re.compile('^(experimental )?(deprecated )?domain (.*)').match(line)
if match:
domain = createItem({'domain' : match.group(3)}, match.group(1), match.group(2))
protocol['domains'].append(domain)
continue
match = re.compile('^ depends on ([^\s]+)').match(line)
if match:
if 'dependencies' not in domain:
domain['dependencies'] = []
domain['dependencies'].append(match.group(1))
continue
match = re.compile('^ (experimental )?(deprecated )?type (.*) extends (array of )?([^\s]+)').match(line)
if match:
if 'types' not in domain:
domain['types'] = []
item = createItem({'id': match.group(3)}, match.group(1), match.group(2))
assignType(item, match.group(5), match.group(4))
domain['types'].append(item)
continue
match = re.compile('^ (experimental )?(deprecated )?(command|event) (.*)').match(line)
if match:
list = []
if match.group(3) == 'command':
if 'commands' in domain:
list = domain['commands']
else:
list = domain['commands'] = []
else:
if 'events' in domain:
list = domain['events']
else:
list = domain['events'] = []
item = createItem({}, match.group(1), match.group(2), match.group(4))
list.append(item)
continue
match = re.compile('^ (experimental )?(deprecated )?(optional )?(array of )?([^\s]+) ([^\s]+)').match(line)
if match:
param = createItem({}, match.group(1), match.group(2), match.group(6))
if match.group(3):
param['optional'] = True
assignType(param, match.group(5), match.group(4))
if match.group(5) == 'enum':
enumliterals = param['enum'] = []
subitems.append(param)
continue
match = re.compile('^ (parameters|returns|properties)').match(line)
if match:
subitems = item[match.group(1)] = []
continue
match = re.compile('^ enum').match(line)
if match:
enumliterals = item['enum'] = []
continue
match = re.compile('^version').match(line)
if match:
continue
match = re.compile('^ major (\d+)').match(line)
if match:
protocol['version']['major'] = match.group(1)
continue
match = re.compile('^ minor (\d+)').match(line)
if match:
protocol['version']['minor'] = match.group(1)
continue
match = re.compile('^ redirect ([^\s]+)').match(line)
if match:
item['redirect'] = match.group(1)
continue
match = re.compile('^ ( )?[^\s]+$').match(line)
if match:
# enum literal
enumliterals.append(trimLine)
continue
print 'Error in %s:%s, illegal token: \t%s' % (file_name, i, line)
sys.exit(1)
return protocol
def loads(data, file_name):
if file_name.endswith(".pdl"):
return parse(data, file_name)
return json.loads(data)
......@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include {{format_include(config.protocol.package, domain.domain)}}
#include {{format_domain_include(config.protocol.package, domain.domain)}}
#include {{format_include(config.protocol.package, "Protocol")}}
......@@ -24,7 +24,7 @@ const char Metainfo::version[] = "{{domain.version}}";
namespace {{type.id}}Enum {
{% for literal in type.enum %}
const char* {{ literal | dash_to_camelcase}} = "{{literal}}";
const char {{ literal | dash_to_camelcase}}[] = "{{literal}}";
{% endfor %}
} // namespace {{type.id}}Enum
{% if protocol.is_exported(domain.domain, type.id) %}
......@@ -211,13 +211,13 @@ public:
}
~DispatcherImpl() override { }
DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
HashMap<String, String>& redirects() { return m_redirects; }
std::unordered_map<String, String>& redirects() { return m_redirects; }
protected:
using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
using DispatchMap = protocol::HashMap<String, CallHandler>;
using DispatchMap = std::unordered_map<String, CallHandler>;
DispatchMap m_dispatchMap;
HashMap<String, String> m_redirects;
std::unordered_map<String, String> m_redirects;
{% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %}
......@@ -231,7 +231,7 @@ protected:
DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
{
protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
if (it == m_dispatchMap.end()) {
if (m_fallThroughForNotFound)
return DispatchResponse::kFallThrough;
......
......@@ -15,7 +15,7 @@
// and include Domain::API version from there.
{% for name in domain.dependencies %}
{% if protocol.is_imported_dependency(name) %}
#include {{format_include(config.protocol.package, name)}}
#include {{format_domain_include(config.protocol.package, name)}}
{% endif %}
{% endfor %}
{% if protocol.is_exported_domain(domain.domain) %}
......@@ -46,7 +46,7 @@ using {{type.id}} = {{protocol.resolve_type(type).type}};
namespace {{type.id}}Enum {
{% for literal in type.enum %}
{{config.protocol.export_macro}} extern const char* {{ literal | dash_to_camelcase}};
{{config.protocol.export_macro}} extern const char {{ literal | dash_to_camelcase}}[];
{% endfor %}
} // namespace {{type.id}}Enum
{% endif %}
......
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