Index: third_party/WebKit/Source/platform/inspector_protocol/CodeGenerator.py |
diff --git a/third_party/WebKit/Source/platform/inspector_protocol/CodeGenerator.py b/third_party/WebKit/Source/platform/inspector_protocol/CodeGenerator.py |
index e00e0d3e4465d6204b96feab00b82a784b4797ae..33d75c310abd658fb55c33242a9ffc5ccbd5dd1f 100644 |
--- a/third_party/WebKit/Source/platform/inspector_protocol/CodeGenerator.py |
+++ b/third_party/WebKit/Source/platform/inspector_protocol/CodeGenerator.py |
@@ -33,18 +33,19 @@ sys.path.insert(1, third_party_dir) |
import jinja2 |
cmdline_parser = optparse.OptionParser() |
-cmdline_parser.add_option("--domains") |
-cmdline_parser.add_option("--output_dir") |
-cmdline_parser.add_option("--output_package") |
+cmdline_parser.add_option("--protocol_dir") |
+cmdline_parser.add_option("--include_dir") |
cmdline_parser.add_option("--string_type") |
cmdline_parser.add_option("--export_macro") |
- |
-generate_domains = set() |
+cmdline_parser.add_option("--output_dir") |
+cmdline_parser.add_option("--output_package") |
try: |
arg_options, arg_values = cmdline_parser.parse_args() |
- if (len(arg_values) == 0): |
- raise Exception("At least one plain argument expected (found %s)" % len(arg_values)) |
+ protocol_dir = arg_options.protocol_dir |
+ if not protocol_dir: |
+ raise Exception("Protocol directory must be specified") |
+ include_dir = arg_options.include_dir |
output_dirname = arg_options.output_dir |
if not output_dirname: |
raise Exception("Output directory must be specified") |
@@ -57,27 +58,37 @@ try: |
export_macro = arg_options.export_macro |
if not export_macro: |
raise Exception("Export macro must be specified") |
- output_domains = arg_options.domains |
- if output_domains and len(output_domains): |
- for domain in output_domains.split(","): |
- generate_domains.add(domain) |
except Exception: |
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
exc = sys.exc_info()[1] |
sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
- sys.stderr.write("Usage: <script> --output_dir <output_dir> protocol.json ...\n") |
exit(1) |
-json_api = {"domains": []} |
-json_timestamp = 0 |
+# Make gyp / make generatos happy, otherwise make rebuilds world. |
+def up_to_date(): |
+ template_ts = max( |
+ os.path.getmtime(__file__), |
+ os.path.getmtime(os.path.join(templates_dir, "TypeBuilder_h.template")), |
+ os.path.getmtime(os.path.join(templates_dir, "TypeBuilder_cpp.template"))) |
+ |
+ for name in os.listdir(protocol_dir): |
+ filename = os.path.join(protocol_dir, name) |
+ if name.endswith(".json") and os.path.isfile(filename): |
+ h_path = os.path.join(output_dirname, name.replace(".json", ".h")) |
+ cpp_path = os.path.join(output_dirname, name.replace(".json", ".cpp")) |
+ if not os.path.exists(h_path) or not os.path.exists(cpp_path): |
+ return False |
+ protocol_ts = os.path.getmtime(filename) |
+ generated_ts = max(os.path.getmtime(h_path), os.path.getmtime(cpp_path)) |
+ if generated_ts < template_ts or generated_ts < protocol_ts: |
+ return False |
+ return True |
+ |
+ |
+if up_to_date(): |
+ sys.exit() |
-for filename in arg_values: |
- json_timestamp = max(os.path.getmtime(filename), json_timestamp) |
- input_file = open(filename, "r") |
- json_string = input_file.read() |
- parsed_json = json.loads(json_string) |
- json_api["domains"] += parsed_json["domains"] |
def to_title_case(name): |
return name[:1].upper() + name[1:] |
@@ -212,6 +223,7 @@ type_definitions["boolean"] = create_primitive_type_definition("boolean") |
type_definitions["object"] = create_object_type_definition() |
type_definitions["any"] = create_any_type_definition() |
+ |
def wrap_array_definition(type): |
return { |
"return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], |
@@ -244,9 +256,6 @@ def create_type_definitions(): |
else: |
type_definitions[domain["domain"] + "." + type["id"]] = create_primitive_type_definition(type["type"]) |
-patch_full_qualified_refs() |
-create_type_definitions() |
- |
def type_definition(name): |
return type_definitions[name] |
@@ -275,18 +284,30 @@ def has_disable(commands): |
return False |
-if os.path.exists(__file__): |
- current_script_timestamp = os.path.getmtime(__file__) |
-else: |
- current_script_timestamp = 0 |
+generate_domains = [] |
+filenames = [] |
+for f in os.listdir(protocol_dir): |
+ name = os.path.join(protocol_dir, f) |
+ if name.endswith(".json") and os.path.isfile(name): |
+ filenames.append(name) |
+ generate_domains.append(f.replace(".json", "")) |
+ |
+if include_dir: |
+ for f in os.listdir(include_dir): |
+ name = os.path.join(include_dir, f) |
+ if name.endswith(".json") and os.path.isfile(name): |
+ filenames.append(name) |
+ |
+json_api = {"domains": []} |
+for filename in filenames: |
+ input_file = open(filename, "r") |
+ json_string = input_file.read() |
+ parsed_json = json.loads(json_string) |
+ json_api["domains"].append(parsed_json) |
-def is_up_to_date(file, template): |
- if not os.path.exists(file): |
- return False |
- timestamp = os.path.getmtime(file) |
- return timestamp > max(os.path.getmtime(module_path + template), |
- current_script_timestamp, json_timestamp) |
+patch_full_qualified_refs() |
+create_type_definitions() |
if not os.path.exists(output_dirname): |
os.mkdir(output_dirname) |
@@ -303,10 +324,6 @@ def generate(domain): |
h_file_name = output_dirname + "/" + class_name + ".h" |
cpp_file_name = output_dirname + "/" + class_name + ".cpp" |
- if (is_up_to_date(cpp_file_name, cpp_template_name) and |
- is_up_to_date(h_file_name, h_template_name)): |
- return |
- |
template_context = { |
"domain": domain, |
"join_arrays": join_arrays, |