Skip to content

Commit c4ca7d6

Browse files
deps: update inspector_protocol to 1b1bcbbe060e8c8cd8704f00f78978c50991
PR-URL: #60705 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 2856475 commit c4ca7d6

File tree

6 files changed

+187
-56
lines changed

6 files changed

+187
-56
lines changed

deps/inspector_protocol/README.node

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name: inspector protocol
22
Short Name: inspector_protocol
33
URL: https://chromium.googlesource.com/deps/inspector_protocol/
44
Version: 0
5-
Revision: af7f5a8173fdbc29f0835ec94395932e328b2ea2
5+
Revision: 1b1bcbbe060e8c8cd8704f00f78978c50991b307
66
License: BSD
77
License File: LICENSE
88
Security Critical: no

deps/inspector_protocol/code_generator.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ def init_defaults(config_tuple, path, defaults):
7575
"--inspector_protocol_dir", type=unicode, required=True,
7676
help=("directory with code_generator.py and C++ encoding / binding "
7777
"libraries, relative to the root of the source tree."))
78+
cmdline_parser.add_argument("--depfile", type=unicode, required=False)
79+
cmdline_parser.add_argument("--stamp", type=unicode, required=False)
7880
arg_options = cmdline_parser.parse_args()
7981
jinja_dir = arg_options.jinja_dir
8082
output_base = arg_options.output_base
8183
config_file = arg_options.config
8284
config_base = os.path.dirname(config_file)
8385
config_values = arg_options.config_value
86+
if bool(arg_options.depfile) != bool(arg_options.stamp):
87+
raise Exception("--depfile requires --stamp and vice versa")
88+
depfile = arg_options.depfile
89+
stamp = arg_options.stamp
8490
inspector_protocol_dir = arg_options.inspector_protocol_dir.lstrip('/')
8591
except Exception:
8692
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
@@ -122,7 +128,8 @@ def init_defaults(config_tuple, path, defaults):
122128
parts = key_value.split("=")
123129
if len(parts) == 2:
124130
defaults["." + parts[0]] = parts[1]
125-
return (jinja_dir, config_file, init_defaults(config_partial, "", defaults))
131+
return (jinja_dir, config_file, init_defaults(config_partial, "", defaults),
132+
depfile, stamp)
126133
except Exception:
127134
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
128135
exc = sys.exc_info()[1]
@@ -360,6 +367,7 @@ class Protocol(object):
360367
def __init__(self, config):
361368
self.config = config
362369
self.json_api = {"domains": []}
370+
self.source_set = set()
363371
self.imported_domains = []
364372
self.exported_domains = []
365373
self.generate_domains = self.read_protocol_file(config.protocol.path)
@@ -381,7 +389,8 @@ def __init__(self, config):
381389

382390
def read_protocol_file(self, file_name):
383391
input_file = open(file_name, "r")
384-
parsed_json = pdl.loads(input_file.read(), file_name)
392+
parsed_json = pdl.loads(input_file.read(), file_name, False,
393+
self.source_set)
385394
input_file.close()
386395
version = '%s.%s' % (parsed_json["version"]["major"],
387396
parsed_json["version"]["minor"])
@@ -600,9 +609,10 @@ def is_imported_dependency(self, domain):
600609

601610

602611
def main():
603-
jinja_dir, config_file, config = read_config()
612+
jinja_dir, config_file, config, deps_filename, stamp_filename = read_config()
604613

605614
protocol = Protocol(config)
615+
source_set = protocol.source_set
606616

607617
if not config.exported and len(protocol.exported_domains):
608618
sys.stderr.write(("Domains [%s] are exported, but config is missing export "
@@ -648,18 +658,26 @@ def main():
648658
}
649659

650660
if domain["domain"] in protocol.generate_domains:
651-
outputs[os.path.join(config.protocol.output, to_file_name(
652-
config, file_name + ".h"))] = h_template.render(template_context)
653-
outputs[os.path.join(config.protocol.output, to_file_name(
654-
config, file_name + ".cpp"))] = cpp_template.render(template_context)
661+
output_h = os.path.join(config.protocol.output, to_file_name(
662+
config, file_name + ".h"))
663+
outputs[output_h] = h_template.render(template_context)
664+
source_set.add(h_template.filename)
665+
output_cpp = os.path.join(config.protocol.output, to_file_name(
666+
config, file_name + ".cpp"))
667+
outputs[output_cpp] = cpp_template.render(template_context)
668+
source_set.add(cpp_template.filename)
655669
if domain["domain"] in protocol.exported_domains:
656-
outputs[os.path.join(config.exported.output, to_file_name(
657-
config, file_name + ".h"))] = exported_template.render(
670+
output_export_h = os.path.join(config.exported.output, to_file_name(
671+
config, file_name + ".h"))
672+
outputs[output_export_h] = exported_template.render(
658673
template_context)
674+
source_set.add(exported_template.filename)
659675
if domain["domain"] in protocol.imported_domains:
660-
outputs[os.path.join(config.protocol.output, to_file_name(
661-
config, file_name + ".h"))] = imported_template.render(
676+
output_import_h = os.path.join(config.protocol.output, to_file_name(
677+
config, file_name + ".h"))
678+
outputs[output_import_h] = imported_template.render(
662679
template_context)
680+
source_set.add(imported_template.filename)
663681

664682
if config.lib:
665683
template_context = {
@@ -702,6 +720,7 @@ def generate_lib_file(file_name, template_files):
702720
inputs.append(os.path.join(lib_templates_dir, template_file))
703721
template = jinja_env.get_template("lib/" + template_file)
704722
parts.append(template.render(template_context))
723+
source_set.add(template.filename)
705724
outputs[file_name] = "\n\n".join(parts)
706725

707726
generate_lib_file(os.path.join(config.lib.output, to_file_name(
@@ -713,17 +732,9 @@ def generate_lib_file(file_name, template_files):
713732
generate_lib_file(os.path.join(config.lib.output, to_file_name(
714733
config, "Protocol.cpp")), protocol_cpp_templates)
715734

716-
# Make gyp / make generatos happy, otherwise make rebuilds world.
717-
inputs_ts = max(map(os.path.getmtime, inputs))
718-
up_to_date = True
719-
for output_file in outputs.keys():
720-
if (not os.path.exists(output_file)
721-
or os.path.getmtime(output_file) < inputs_ts):
722-
up_to_date = False
723-
break
724-
if up_to_date:
725-
sys.exit()
726-
735+
if stamp_filename:
736+
with open(stamp_filename, "w"):
737+
pass
727738
for file_name, content in outputs.items():
728739
# Remove output file first to account for potential case changes.
729740
try:
@@ -734,6 +745,12 @@ def generate_lib_file(file_name, template_files):
734745
out_file.write(content)
735746
out_file.close()
736747

748+
if deps_filename:
749+
assert stamp_filename
750+
with open(deps_filename, "w") as deps_file:
751+
deps_file.write("%s: %s\n" % (
752+
stamp_filename, " ".join(sorted(source_set))))
753+
737754

738755
if __name__ == "__main__":
739756
main()

deps/inspector_protocol/concatenate_protocols.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os.path
77
import sys
8+
import argparse
89

910
try:
1011
import json
@@ -14,29 +15,52 @@
1415
import pdl
1516

1617
def main(argv):
17-
if len(argv) < 1:
18+
cmdline_parser = argparse.ArgumentParser()
19+
cmdline_parser.add_argument('filename', nargs='*')
20+
cmdline_parser.add_argument("--depfile", required=False)
21+
cmdline_parser.add_argument("--stamp", required=False)
22+
arg_options = cmdline_parser.parse_args()
23+
24+
if bool(arg_options.depfile) != bool(arg_options.stamp):
25+
raise Exception("--depfile requires --stamp and vice versa")
26+
27+
if len(arg_options.filename) < 1:
1828
sys.stderr.write(
1929
"Usage: %s <protocol-1> [<protocol-2> [, <protocol-3>...]] "
2030
"<output-file>\n" % sys.argv[0])
2131
return 1
2232

33+
filenames = arg_options.filename
34+
deps_filename = arg_options.depfile
35+
stamp_filename = arg_options.stamp
2336
domains = []
37+
source_set = set()
2438
version = None
25-
for protocol in argv[:-1]:
39+
for protocol in filenames[:-1]:
2640
file_name = os.path.normpath(protocol)
2741
if not os.path.isfile(file_name):
2842
sys.stderr.write("Cannot find %s\n" % file_name)
2943
return 1
3044
input_file = open(file_name, "r")
31-
parsed_json = pdl.loads(input_file.read(), file_name)
45+
parsed_json = pdl.loads(input_file.read(), file_name, False, source_set)
3246
domains += parsed_json["domains"]
3347
version = parsed_json["version"]
3448

49+
if stamp_filename:
50+
with open(stamp_filename, "w"):
51+
pass
52+
3553
output_file = open(argv[-1], "w")
3654
json.dump({"version": version, "domains": domains}, output_file,
3755
indent=4, sort_keys=False, separators=(',', ': '))
3856
output_file.close()
3957

58+
if deps_filename:
59+
assert stamp_filename
60+
with open(deps_filename, "w") as deps_file:
61+
deps_file.write("%s: %s\n" % (
62+
stamp_filename, " ".join(sorted(source_set))))
63+
4064

4165
if __name__ == '__main__':
4266
sys.exit(main(sys.argv[1:]))

deps/inspector_protocol/inspector_protocol.gni

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ template("inspector_protocol_generate") {
4747
"$inspector_protocol_dir/templates/TypeBuilder_cpp.template",
4848
"$inspector_protocol_dir/templates/TypeBuilder_h.template",
4949
]
50+
5051
if (defined(invoker.inputs)) {
5152
inputs += invoker.inputs
5253
}
@@ -61,6 +62,12 @@ template("inspector_protocol_generate") {
6162
]
6263
}
6364

65+
outputs = get_path_info(rebase_path(invoker.outputs, ".", invoker.out_dir),
66+
"abspath")
67+
68+
_stampfile = outputs[0]
69+
depfile = "${invoker.out_dir}/${target_name}.d"
70+
6471
args = [
6572
"--jinja_dir",
6673
rebase_path(jinja_dir, root_build_dir),
@@ -70,6 +77,10 @@ template("inspector_protocol_generate") {
7077
rebase_path(invoker.config_file, root_build_dir),
7178
"--inspector_protocol_dir",
7279
"$inspector_protocol_dir",
80+
"--depfile",
81+
rebase_path(depfile, root_build_dir),
82+
"--stamp",
83+
rebase_path(_stampfile, root_build_dir),
7384
]
7485
if (use_embedder_types) {
7586
args += [
@@ -86,8 +97,55 @@ template("inspector_protocol_generate") {
8697
}
8798
}
8899

89-
outputs = get_path_info(rebase_path(invoker.outputs, ".", invoker.out_dir),
90-
"abspath")
100+
forward_variables_from(invoker,
101+
[
102+
"visibility",
103+
"deps",
104+
"public_deps",
105+
])
106+
}
107+
}
108+
109+
# This template concatenates multiple protocol files
110+
# into a single (JSON) file.
111+
#
112+
# Inputs
113+
#
114+
# inputs (required)
115+
# Paths to .pdl or .json files with protocol definitions.
116+
#
117+
# output_file (required)
118+
# Path to put the concatenated file in. It must be inside output or
119+
# generated file directory.
120+
#
121+
# inspector_protocol_dir (required)
122+
# Path to the inspector_protocol directory.
123+
#
124+
template("inspector_protocol_concatenate") {
125+
assert(defined(invoker.inputs))
126+
assert(defined(invoker.output_file))
127+
assert(defined(invoker.inspector_protocol_dir))
128+
_inspector_protocol_dir = invoker.inspector_protocol_dir
129+
130+
action(target_name) {
131+
script = "$_inspector_protocol_dir/concatenate_protocols.py"
132+
133+
inputs = invoker.inputs
134+
outputs = []
135+
depfile = "${invoker.output_file}_${target_name}.d"
136+
137+
args = [
138+
"--depfile",
139+
rebase_path(depfile, root_build_dir),
140+
"--stamp",
141+
rebase_path(invoker.output_file, root_build_dir),
142+
]
143+
144+
inputs += invoker.inputs
145+
args += rebase_path(invoker.inputs, root_build_dir)
146+
147+
outputs += [invoker.output_file]
148+
args += [rebase_path(invoker.output_file, root_build_dir)]
91149

92150
forward_variables_from(invoker,
93151
[

deps/inspector_protocol/pdl.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ def createItem(d, experimental, deprecated, name=None):
5050
return result
5151

5252

53-
def parse(data, file_name, map_binary_to_string=False):
53+
def parse(data, file_name, map_binary_to_string, source_set):
54+
assert source_set is None or isinstance(source_set, set)
5455
protocol = collections.OrderedDict()
5556
protocol['version'] = collections.OrderedDict()
5657
protocol['domains'] = []
5758
domain = None
5859
item = None
5960
subitems = None
6061
nukeDescription = False
62+
if source_set is not None:
63+
source_set.add(file_name)
6164
global description
6265
lines = data.split('\n')
6366
for i in range(0, len(lines)):
@@ -90,11 +93,11 @@ def parse(data, file_name, map_binary_to_string=False):
9093
r'^include (.*)').match(line)
9194
if match:
9295
included_filename = match.group(1)
93-
if path.isabs(included_filename):
94-
raise Exception("Only relative paths are supported in include's")
95-
resolved_path = path.normpath(path.join(path.dirname(file_name), included_filename))
96+
if os.path.isabs(included_filename):
97+
raise Exception("Only relative paths are supported in includes")
98+
resolved_path = os.path.normpath(os.path.join(os.path.dirname(file_name), included_filename))
9699
with open(resolved_path, 'r') as file:
97-
included_data = parse(file.read(), resolved_path, map_binary_to_string)
100+
included_data = parse(file.read(), resolved_path, map_binary_to_string, source_set)
98101
protocol['domains'].extend(included_data['domains'])
99102
continue
100103

@@ -187,7 +190,7 @@ def parse(data, file_name, map_binary_to_string=False):
187190
return protocol
188191

189192

190-
def loads(data, file_name, map_binary_to_string=False):
193+
def loads(data, file_name, map_binary_to_string=False, source_set=None):
191194
if file_name.endswith(".pdl"):
192-
return parse(data, file_name, map_binary_to_string)
195+
return parse(data, file_name, map_binary_to_string, source_set)
193196
return json.loads(data)

0 commit comments

Comments
 (0)