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

[DevTools] Roll inspector_protocol to 02ca2bc2bb337cb2d4143157383b554f9b75dc99.

This brings in the CBOR_h / CBOR_cc template.

Change-Id: I3d3971a5ba4c98a8b36982449e4d9a2606010f22
Reviewed-on: https://chromium-review.googlesource.com/c/1459738Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59479}
parent 455200e0
#!/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 sys
import check_protocol_compatibility
sys.exit(check_protocol_compatibility.main())
......@@ -33,14 +33,14 @@ def read_config():
def json_object_hook(object_dict):
items = [(k, os.path.join(config_base, v) if k == "path" else v) for (k, v) in object_dict.items()]
items = [(k, os.path.join(output_base, v) if k == "output" else v) for (k, v) in items]
keys, values = zip(*items)
keys, values = list(zip(*items))
return collections.namedtuple('X', keys)(*values)
return json.loads(data, object_hook=json_object_hook)
def init_defaults(config_tuple, path, defaults):
keys = list(config_tuple._fields) # pylint: disable=E1101
values = [getattr(config_tuple, k) for k in keys]
for i in xrange(len(keys)):
for i in range(len(keys)):
if hasattr(values[i], "_fields"):
values[i] = init_defaults(values[i], path + "." + keys[i], defaults)
for optional in defaults:
......@@ -134,7 +134,7 @@ def dash_to_camelcase(word):
def to_snake_case(name):
return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name, sys.maxint).lower()
return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name, sys.maxsize).lower()
def to_method_case(config, name):
......@@ -623,7 +623,7 @@ def main():
lib_templates_dir = os.path.join(module_path, "lib")
# Note these should be sorted in the right order.
# TODO(dgozman): sort them programmatically based on commented includes.
lib_h_templates = [
protocol_h_templates = [
"ErrorSupport_h.template",
"Values_h.template",
"Object_h.template",
......@@ -632,15 +632,17 @@ def main():
"Array_h.template",
"DispatcherBase_h.template",
"Parser_h.template",
"CBOR_h.template",
]
lib_cpp_templates = [
protocol_cpp_templates = [
"Protocol_cpp.template",
"ErrorSupport_cpp.template",
"Values_cpp.template",
"Object_cpp.template",
"DispatcherBase_cpp.template",
"Parser_cpp.template",
"CBOR_cpp.template",
]
forward_h_templates = [
......@@ -649,6 +651,14 @@ def main():
"FrontendChannel_h.template",
]
base_string_adapter_h_templates = [
"base_string_adapter_h.template",
]
base_string_adapter_cc_templates = [
"base_string_adapter_cc.template",
]
def generate_lib_file(file_name, template_files):
parts = []
for template_file in template_files:
......@@ -658,20 +668,22 @@ def main():
outputs[file_name] = "\n\n".join(parts)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "Forward.h")), forward_h_templates)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "Protocol.h")), lib_h_templates)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "Protocol.cpp")), lib_cpp_templates)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "Protocol.h")), protocol_h_templates)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "Protocol.cpp")), protocol_cpp_templates)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "base_string_adapter.h")), base_string_adapter_h_templates)
generate_lib_file(os.path.join(config.lib.output, to_file_name(config, "base_string_adapter.cc")), base_string_adapter_cc_templates)
# Make gyp / make generatos happy, otherwise make rebuilds world.
inputs_ts = max(map(os.path.getmtime, inputs))
up_to_date = True
for output_file in outputs.iterkeys():
for output_file in outputs.keys():
if not os.path.exists(output_file) or os.path.getmtime(output_file) < inputs_ts:
up_to_date = False
break
if up_to_date:
sys.exit()
for file_name, content in outputs.iteritems():
for file_name, content in outputs.items():
out_file = open(file_name, "w")
out_file.write(content)
out_file.close()
......
......@@ -31,8 +31,12 @@ template("inspector_protocol_generate") {
inputs = [
invoker.config_file,
"$inspector_protocol_dir/lib/base_string_adapter_cc.template",
"$inspector_protocol_dir/lib/base_string_adapter_h.template",
"$inspector_protocol_dir/lib/Allocator_h.template",
"$inspector_protocol_dir/lib/Array_h.template",
"$inspector_protocol_dir/lib/CBOR_h.template",
"$inspector_protocol_dir/lib/CBOR_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_h.template",
"$inspector_protocol_dir/lib/ErrorSupport_cpp.template",
......
......@@ -7,6 +7,8 @@
'inspector_protocol_files': [
'lib/Allocator_h.template',
'lib/Array_h.template',
'lib/CBOR_h.template',
'lib/CBOR_cpp.template',
'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template',
'lib/ErrorSupport_cpp.template',
......
// This file is generated by Allocator_h.template.
// 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.
......
// This file is generated by Array_h.template.
// 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.
......
This diff is collapsed.
This diff is collapsed.
// This file is generated by DispatcherBase_cpp.template.
// 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.
......
// This file is generated by DispatcherBase_h.template.
// 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.
......
// This file is generated by ErrorSupport_cpp.template.
// 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.
......
// This file is generated by ErrorSupport_h.template.
// 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.
......
// This file is generated by Forward_h.template.
// 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.
......
// This file is generated by FrontendChannel_h.template.
// 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.
......
// This file is generated by Maybe_h.template.
// 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.
......
// This file is generated by Object_cpp.template.
// 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.
......
// This file is generated by Object_h.template.
// 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.
......
// This file is generated by Parser_cpp.template.
// 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.
......
// This file is generated by Parser_h.template.
// 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.
......
// This file is generated.
// This file is generated by Protocol_cpp.template.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
......
// This file is generated by ValueConversions_h.template.
// 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.
......
// This file is generated by Values_cpp.template.
// 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.
......
// This file is generated by Values_h.template.
// 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.
......
// This file is generated by DispatcherBase_cpp.template.
// Copyright 2019 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.
#include {{format_include(config.protocol.package, "base_string_adapter")}}
#include {{format_include(config.protocol.package, "Protocol")}}
#include <utility>
#include "base/base64.h"
#include "base/json/json_reader.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
std::unique_ptr<protocol::Value> toProtocolValue(
const base::Value* value, int depth) {
if (!value || !depth)
return nullptr;
if (value->is_none())
return protocol::Value::null();
if (value->is_bool()) {
bool inner;
value->GetAsBoolean(&inner);
return protocol::FundamentalValue::create(inner);
}
if (value->is_int()) {
int inner;
value->GetAsInteger(&inner);
return protocol::FundamentalValue::create(inner);
}
if (value->is_double()) {
double inner;
value->GetAsDouble(&inner);
return protocol::FundamentalValue::create(inner);
}
if (value->is_string()) {
std::string inner;
value->GetAsString(&inner);
return protocol::StringValue::create(inner);
}
if (value->is_list()) {
const base::ListValue* list = nullptr;
value->GetAsList(&list);
std::unique_ptr<protocol::ListValue> result = protocol::ListValue::create();
for (size_t i = 0; i < list->GetSize(); i++) {
const base::Value* item = nullptr;
list->Get(i, &item);
std::unique_ptr<protocol::Value> converted =
toProtocolValue(item, depth - 1);
if (converted)
result->pushValue(std::move(converted));
}
return std::move(result);
}
if (value->is_dict()) {
const base::DictionaryValue* dictionary = nullptr;
value->GetAsDictionary(&dictionary);
std::unique_ptr<protocol::DictionaryValue> result =
protocol::DictionaryValue::create();
for (base::DictionaryValue::Iterator it(*dictionary);
!it.IsAtEnd(); it.Advance()) {
std::unique_ptr<protocol::Value> converted =
toProtocolValue(&it.value(), depth - 1);
if (converted)
result->setValue(it.key(), std::move(converted));
}
return std::move(result);
}
return nullptr;
}
std::unique_ptr<base::Value> toBaseValue(Value* value, int depth) {
if (!value || !depth)
return nullptr;
if (value->type() == Value::TypeNull)
return std::make_unique<base::Value>();
if (value->type() == Value::TypeBoolean) {
bool inner;
value->asBoolean(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == Value::TypeInteger) {
int inner;
value->asInteger(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == Value::TypeDouble) {
double inner;
value->asDouble(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == Value::TypeString) {
std::string inner;
value->asString(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == Value::TypeArray) {
ListValue* list = ListValue::cast(value);
std::unique_ptr<base::ListValue> result(new base::ListValue());
for (size_t i = 0; i < list->size(); i++) {
std::unique_ptr<base::Value> converted =
toBaseValue(list->at(i), depth - 1);
if (converted)
result->Append(std::move(converted));
}
return std::move(result);
}
if (value->type() == Value::TypeObject) {
DictionaryValue* dict = DictionaryValue::cast(value);
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
for (size_t i = 0; i < dict->size(); i++) {
DictionaryValue::Entry entry = dict->at(i);
std::unique_ptr<base::Value> converted =
toBaseValue(entry.second, depth - 1);
if (converted)
result->SetWithoutPathExpansion(entry.first, std::move(converted));
}
return std::move(result);
}
return nullptr;
}
// static
std::unique_ptr<Value> StringUtil::parseJSON(
const std::string& json) {
std::unique_ptr<base::Value> value = base::JSONReader::Read(json);
return toProtocolValue(value.get(), 1000);
}
StringBuilder::StringBuilder() {}
StringBuilder::~StringBuilder() {}
void StringBuilder::append(const std::string& s) {
string_ += s;
}
void StringBuilder::append(char c) {
string_ += c;
}
void StringBuilder::append(const char* characters, size_t length) {
string_.append(characters, length);
}
// static
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
const String& str) {
builder.append('"');
base::string16 str16 = base::UTF8ToUTF16(str);
escapeWideStringForJSON(reinterpret_cast<const uint16_t*>(&str16[0]),
str16.length(), &builder);
builder.append('"');
}
std::string StringBuilder::toString() {
return string_;
}
void StringBuilder::reserveCapacity(size_t capacity) {
string_.reserve(capacity);
}
Binary::Binary() : bytes_(new base::RefCountedBytes) {}
Binary::Binary(const Binary& binary) : bytes_(binary.bytes_) {}
Binary::Binary(scoped_refptr<base::RefCountedMemory> bytes) : bytes_(bytes) {}
Binary::~Binary() {}
String Binary::toBase64() const {
std::string encoded;
base::Base64Encode(
base::StringPiece(reinterpret_cast<const char*>(bytes_->front()),
bytes_->size()),
&encoded);
return encoded;
}
// static
Binary Binary::fromBase64(const String& base64, bool* success) {
std::string decoded;
*success = base::Base64Decode(base::StringPiece(base64), &decoded);
if (*success) {
return Binary::fromString(std::move(decoded));
}
return Binary();
}
// static
Binary Binary::fromRefCounted(scoped_refptr<base::RefCountedMemory> memory) {
return Binary(memory);
}
// static
Binary Binary::fromVector(std::vector<uint8_t> data) {
return Binary(base::RefCountedBytes::TakeVector(&data));
}
// static
Binary Binary::fromString(std::string data) {
return Binary(base::RefCountedString::TakeString(&data));
}
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
// This file is generated by Parser_h.template.
// Copyright 2019 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)}}_BASE_STRING_ADAPTER_H
#define {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
#include <memory>
#include <string>
#include <vector>
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_number_conversions.h"
{% if config.lib.export_header %}
#include "{{config.lib.export_header}}"
{% endif %}
namespace base {
class Value;
}
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
class Value;
using String = std::string;
class {{config.lib.export_macro}} StringBuilder {
public:
StringBuilder();
~StringBuilder();
void append(const String&);
void append(char);
void append(const char*, size_t);
String toString();
void reserveCapacity(size_t);
private:
std::string string_;
};
class {{config.lib.export_macro}} StringUtil {
public:
static String substring(const String& s, unsigned pos, unsigned len) {
return s.substr(pos, len);
}
static String fromInteger(int number) { return base::NumberToString(number); }
static String fromDouble(double number) {
String s = base::NumberToString(number);
if (!s.empty() && s[0] == '.')
s = "0" + s;
return s;
}
static double toDouble(const char* s, size_t len, bool* ok) {
double v = 0.0;
*ok = base::StringToDouble(std::string(s, len), &v);
return *ok ? v : 0.0;
}
static size_t find(const String& s, const char* needle) {
return s.find(needle);
}
static size_t find(const String& s, const String& needle) {
return s.find(needle);
}
static const size_t kNotFound = static_cast<size_t>(-1);
static void builderAppend(StringBuilder& builder, const String& s) {
builder.append(s);
}
static void builderAppend(StringBuilder& builder, char c) {
builder.append(c);
}
static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
builder.append(s, len);
}
static void builderAppendQuotedString(StringBuilder& builder,
const String& str);
static void builderReserve(StringBuilder& builder, unsigned capacity) {
builder.reserveCapacity(capacity);
}
static String builderToString(StringBuilder& builder) {
return builder.toString();
}
static std::vector<uint8_t> utf8data(const String& str) {
return std::vector<uint8_t>(str.begin(), str.end());
}
static std::unique_ptr<Value> parseJSON(const String&);
};
// A read-only sequence of uninterpreted bytes with reference-counted storage.
class {{config.lib.export_macro}} Binary {
public:
Binary(const Binary&);
Binary();
~Binary();
const uint8_t* data() const { return bytes_->front(); }
size_t size() const { return bytes_->size(); }
scoped_refptr<base::RefCountedMemory> bytes() const { return bytes_; }
String toBase64() const;
static Binary fromBase64(const String& base64, bool* success);
static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
static Binary fromVector(std::vector<uint8_t> data);
static Binary fromString(std::string data);
private:
explicit Binary(scoped_refptr<base::RefCountedMemory> bytes);
scoped_refptr<base::RefCountedMemory> bytes_;
};
std::unique_ptr<Value> toProtocolValue(const base::Value* value, int depth);
std::unique_ptr<base::Value> toBaseValue(Value* value, int depth);
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H)
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import print_function
import collections
import json
import os.path
......@@ -159,7 +160,7 @@ def parse(data, file_name, map_binary_to_string=False):
enumliterals.append(trimLine)
continue
print 'Error in %s:%s, illegal token: \t%s' % (file_name, i, line)
print('Error in %s:%s, illegal token: \t%s' % (file_name, i, line))
sys.exit(1)
return protocol
......
// This file is generated
// This file is generated by Exported_h.template.
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
......
// This file is generated
// This file is generated by Imported_h.template.
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
......
// This file is generated
// This file is generated by TypeBuilder_cpp.template.
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
......
// This file is generated
// This file is generated by TypeBuilder_h.template.
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
......
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