| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb4740d commit 15a74c0
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ Name: inspector protocol | |||
| 2 | 2 | Short Name: inspector_protocol | |
| 3 | 3 | URL: https://chromium.googlesource.com/deps/inspector_protocol/ | |
| 4 | 4 | Version: 0 | |
| 5 | - Revision: af7f5a8173fdbc29f0835ec94395932e328b2ea2 | ||
| 5 | + Revision: 1b1bcbbe060e8c8cd8704f00f78978c50991b307 | ||
| 6 | 6 | License: BSD | |
| 7 | 7 | License File: LICENSE | |
| 8 | 8 | Security Critical: no | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,12 +75,18 @@ def init_defaults(config_tuple, path, defaults): | |||
| 75 | 75 | "--inspector_protocol_dir", type=unicode, required=True, | |
| 76 | 76 | help=("directory with code_generator.py and C++ encoding / binding " | |
| 77 | 77 | "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) | ||
| 78 | 80 | arg_options = cmdline_parser.parse_args() | |
| 79 | 81 | jinja_dir = arg_options.jinja_dir | |
| 80 | 82 | output_base = arg_options.output_base | |
| 81 | 83 | config_file = arg_options.config | |
| 82 | 84 | config_base = os.path.dirname(config_file) | |
| 83 | 85 | 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 | ||
| 84 | 90 | inspector_protocol_dir = arg_options.inspector_protocol_dir.lstrip('/') | |
| 85 | 91 | except Exception: | |
| 86 | 92 | # 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): | |||
| 122 | 128 | parts = key_value.split("=") | |
| 123 | 129 | if len(parts) == 2: | |
| 124 | 130 | 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) | ||
| 126 | 133 | except Exception: | |
| 127 | 134 | # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | |
| 128 | 135 | exc = sys.exc_info()[1] | |
@@ -360,6 +367,7 @@ class Protocol(object): | |||
| 360 | 367 | def __init__(self, config): | |
| 361 | 368 | self.config = config | |
| 362 | 369 | self.json_api = {"domains": []} | |
| 370 | + self.source_set = set() | ||
| 363 | 371 | self.imported_domains = [] | |
| 364 | 372 | self.exported_domains = [] | |
| 365 | 373 | self.generate_domains = self.read_protocol_file(config.protocol.path) | |
@@ -381,7 +389,8 @@ def __init__(self, config): | |||
| 381 | 389 | ||
| 382 | 390 | def read_protocol_file(self, file_name): | |
| 383 | 391 | 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) | ||
| 385 | 394 | input_file.close() | |
| 386 | 395 | version = '%s.%s' % (parsed_json["version"]["major"], | |
| 387 | 396 | parsed_json["version"]["minor"]) | |
@@ -600,9 +609,10 @@ def is_imported_dependency(self, domain): | |||
| 600 | 609 | ||
| 601 | 610 | ||
| 602 | 611 | def main(): | |
| 603 | - jinja_dir, config_file, config = read_config() | ||
| 612 | + jinja_dir, config_file, config, deps_filename, stamp_filename = read_config() | ||
| 604 | 613 | ||
| 605 | 614 | protocol = Protocol(config) | |
| 615 | + source_set = protocol.source_set | ||
| 606 | 616 | ||
| 607 | 617 | if not config.exported and len(protocol.exported_domains): | |
| 608 | 618 | sys.stderr.write(("Domains [%s] are exported, but config is missing export " | |
@@ -648,18 +658,26 @@ def main(): | |||
| 648 | 658 | } | |
| 649 | 659 | ||
| 650 | 660 | 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) | ||
| 655 | 669 | 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( | ||
| 658 | 673 | template_context) | |
| 674 | + source_set.add(exported_template.filename) | ||
| 659 | 675 | 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( | ||
| 662 | 679 | template_context) | |
| 680 | + source_set.add(imported_template.filename) | ||
| 663 | 681 | ||
| 664 | 682 | if config.lib: | |
| 665 | 683 | template_context = { | |
@@ -702,6 +720,7 @@ def generate_lib_file(file_name, template_files): | |||
| 702 | 720 | inputs.append(os.path.join(lib_templates_dir, template_file)) | |
| 703 | 721 | template = jinja_env.get_template("lib/" + template_file) | |
| 704 | 722 | parts.append(template.render(template_context)) | |
| 723 | + source_set.add(template.filename) | ||
| 705 | 724 | outputs[file_name] = "\n\n".join(parts) | |
| 706 | 725 | ||
| 707 | 726 | generate_lib_file(os.path.join(config.lib.output, to_file_name( | |
@@ -713,17 +732,9 @@ def generate_lib_file(file_name, template_files): | |||
| 713 | 732 | generate_lib_file(os.path.join(config.lib.output, to_file_name( | |
| 714 | 733 | config, "Protocol.cpp")), protocol_cpp_templates) | |
| 715 | 734 | ||
| 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 | ||
| 727 | 738 | for file_name, content in outputs.items(): | |
| 728 | 739 | # Remove output file first to account for potential case changes. | |
| 729 | 740 | try: | |
@@ -734,6 +745,12 @@ def generate_lib_file(file_name, template_files): | |||
| 734 | 745 | out_file.write(content) | |
| 735 | 746 | out_file.close() | |
| 736 | 747 | ||
| 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 | + | ||
| 737 | 754 | ||
| 738 | 755 | if __name__ == "__main__": | |
| 739 | 756 | main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | import os.path | |
| 7 | 7 | import sys | |
| 8 | + import argparse | ||
| 8 | 9 | ||
| 9 | 10 | try: | |
| 10 | 11 | import json | |
@@ -14,29 +15,52 @@ | |||
| 14 | 15 | import pdl | |
| 15 | 16 | ||
| 16 | 17 | 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: | ||
| 18 | 28 | sys.stderr.write( | |
| 19 | 29 | "Usage: %s <protocol-1> [<protocol-2> [, <protocol-3>...]] " | |
| 20 | 30 | "<output-file>\n" % sys.argv[0]) | |
| 21 | 31 | return 1 | |
| 22 | 32 | ||
| 33 | + filenames = arg_options.filename | ||
| 34 | + deps_filename = arg_options.depfile | ||
| 35 | + stamp_filename = arg_options.stamp | ||
| 23 | 36 | domains = [] | |
| 37 | + source_set = set() | ||
| 24 | 38 | version = None | |
| 25 | - for protocol in argv[:-1]: | ||
| 39 | + for protocol in filenames[:-1]: | ||
| 26 | 40 | file_name = os.path.normpath(protocol) | |
| 27 | 41 | if not os.path.isfile(file_name): | |
| 28 | 42 | sys.stderr.write("Cannot find %s\n" % file_name) | |
| 29 | 43 | return 1 | |
| 30 | 44 | 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) | ||
| 32 | 46 | domains += parsed_json["domains"] | |
| 33 | 47 | version = parsed_json["version"] | |
| 34 | 48 | ||
| 49 | + if stamp_filename: | ||
| 50 | + with open(stamp_filename, "w"): | ||
| 51 | + pass | ||
| 52 | + | ||
| 35 | 53 | output_file = open(argv[-1], "w") | |
| 36 | 54 | json.dump({"version": version, "domains": domains}, output_file, | |
| 37 | 55 | indent=4, sort_keys=False, separators=(',', ': ')) | |
| 38 | 56 | output_file.close() | |
| 39 | 57 | ||
| 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 | + | ||
| 40 | 64 | ||
| 41 | 65 | if __name__ == '__main__': | |
| 42 | 66 | sys.exit(main(sys.argv[1:])) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,7 @@ template("inspector_protocol_generate") { | |||
| 47 | 47 | "$inspector_protocol_dir/templates/TypeBuilder_cpp.template", | |
| 48 | 48 | "$inspector_protocol_dir/templates/TypeBuilder_h.template", | |
| 49 | 49 | ] | |
| 50 | + | ||
| 50 | 51 | if (defined(invoker.inputs)) { | |
| 51 | 52 | inputs += invoker.inputs | |
| 52 | 53 | } | |
@@ -61,6 +62,12 @@ template("inspector_protocol_generate") { | |||
| 61 | 62 | ] | |
| 62 | 63 | } | |
| 63 | 64 | ||
| 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 | + | ||
| 64 | 71 | args = [ | |
| 65 | 72 | "--jinja_dir", | |
| 66 | 73 | rebase_path(jinja_dir, root_build_dir), | |
@@ -70,6 +77,10 @@ template("inspector_protocol_generate") { | |||
| 70 | 77 | rebase_path(invoker.config_file, root_build_dir), | |
| 71 | 78 | "--inspector_protocol_dir", | |
| 72 | 79 | "$inspector_protocol_dir", | |
| 80 | + "--depfile", | ||
| 81 | + rebase_path(depfile, root_build_dir), | ||
| 82 | + "--stamp", | ||
| 83 | + rebase_path(_stampfile, root_build_dir), | ||
| 73 | 84 | ] | |
| 74 | 85 | if (use_embedder_types) { | |
| 75 | 86 | args += [ | |
@@ -86,8 +97,55 @@ template("inspector_protocol_generate") { | |||
| 86 | 97 | } | |
| 87 | 98 | } | |
| 88 | 99 | ||
| 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)] | ||
| 91 | 149 | ||
| 92 | 150 | forward_variables_from(invoker, | |
| 93 | 151 | [ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,14 +50,17 @@ def createItem(d, experimental, deprecated, name=None): | |||
| 50 | 50 | return result | |
| 51 | 51 | ||
| 52 | 52 | ||
| 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) | ||
| 54 | 55 | protocol = collections.OrderedDict() | |
| 55 | 56 | protocol['version'] = collections.OrderedDict() | |
| 56 | 57 | protocol['domains'] = [] | |
| 57 | 58 | domain = None | |
| 58 | 59 | item = None | |
| 59 | 60 | subitems = None | |
| 60 | 61 | nukeDescription = False | |
| 62 | + if source_set is not None: | ||
| 63 | + source_set.add(file_name) | ||
| 61 | 64 | global description | |
| 62 | 65 | lines = data.split('\n') | |
| 63 | 66 | for i in range(0, len(lines)): | |
@@ -90,11 +93,11 @@ def parse(data, file_name, map_binary_to_string=False): | |||
| 90 | 93 | r'^include (.*)').match(line) | |
| 91 | 94 | if match: | |
| 92 | 95 | 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)) | ||
| 96 | 99 | 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) | ||
| 98 | 101 | protocol['domains'].extend(included_data['domains']) | |
| 99 | 102 | continue | |
| 100 | 103 | ||
@@ -187,7 +190,7 @@ def parse(data, file_name, map_binary_to_string=False): | |||
| 187 | 190 | return protocol | |
| 188 | 191 | ||
| 189 | 192 | ||
| 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): | ||
| 191 | 194 | 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) | ||
| 193 | 196 | return json.loads(data) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments