| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 Google Inc. All rights reserved. | 2 # Copyright (c) 2013 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (agent->${name}(${params_agent})) | 108 if (agent->${name}(${params_agent})) |
| 109 timelineAgentId = agent->id(); | 109 timelineAgentId = agent->id(); |
| 110 }""") | 110 }""") |
| 111 | 111 |
| 112 | 112 |
| 113 template_instrumenting_agents_h = string.Template("""// Code generated from Insp
ectorInstrumentation.idl | 113 template_instrumenting_agents_h = string.Template("""// Code generated from Insp
ectorInstrumentation.idl |
| 114 | 114 |
| 115 #ifndef InstrumentingAgentsInl_h | 115 #ifndef InstrumentingAgentsInl_h |
| 116 #define InstrumentingAgentsInl_h | 116 #define InstrumentingAgentsInl_h |
| 117 | 117 |
| 118 #include <wtf/FastAllocBase.h> | 118 #include "wtf/FastAllocBase.h" |
| 119 #include <wtf/Noncopyable.h> | 119 #include "wtf/Noncopyable.h" |
| 120 #include <wtf/PassRefPtr.h> | 120 #include "wtf/PassRefPtr.h" |
| 121 #include <wtf/RefCounted.h> | 121 #include "wtf/RefCounted.h" |
| 122 | 122 |
| 123 namespace WebCore { | 123 namespace WebCore { |
| 124 | 124 |
| 125 ${forward_list} | 125 ${forward_list} |
| 126 | 126 |
| 127 class InstrumentingAgents : public RefCounted<InstrumentingAgents> { | 127 class InstrumentingAgents : public RefCounted<InstrumentingAgents> { |
| 128 WTF_MAKE_NONCOPYABLE(InstrumentingAgents); | 128 WTF_MAKE_NONCOPYABLE(InstrumentingAgents); |
| 129 WTF_MAKE_FAST_ALLOCATED; | 129 WTF_MAKE_FAST_ALLOCATED; |
| 130 public: | 130 public: |
| 131 static PassRefPtr<InstrumentingAgents> create() | 131 static PassRefPtr<InstrumentingAgents> create() |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 member_list="\n".join(member_list)) | 462 member_list="\n".join(member_list)) |
| 463 | 463 |
| 464 cpp_lines = template_instrumenting_agents_cpp.substitute( | 464 cpp_lines = template_instrumenting_agents_cpp.substitute( |
| 465 None, | 465 None, |
| 466 init_list="\n , ".join(init_list), | 466 init_list="\n , ".join(init_list), |
| 467 reset_list="\n ".join(reset_list)) | 467 reset_list="\n ".join(reset_list)) |
| 468 | 468 |
| 469 return header_lines, cpp_lines | 469 return header_lines, cpp_lines |
| 470 | 470 |
| 471 | 471 |
| 472 def generate(input_path, output_h_dir, output_cpp_dir): | 472 def generate(input_path, output_dir): |
| 473 fin = open(input_path, "r") | 473 fin = open(input_path, "r") |
| 474 files = load_model_from_idl(fin.read()) | 474 files = load_model_from_idl(fin.read()) |
| 475 fin.close() | 475 fin.close() |
| 476 | 476 |
| 477 cpp_includes = [] | 477 cpp_includes = [] |
| 478 cpp_lines = [] | 478 cpp_lines = [] |
| 479 used_agents = set() | 479 used_agents = set() |
| 480 for f in files: | 480 for f in files: |
| 481 cpp_includes.append(include_header(f.header_name)) | 481 cpp_includes.append(include_header(f.header_name)) |
| 482 | 482 |
| 483 fout = open(output_h_dir + "/" + f.header_name + ".h", "w") | 483 fout = open(output_dir + "/" + f.header_name + ".h", "w") |
| 484 fout.write(f.generate(cpp_lines, used_agents)) | 484 fout.write(f.generate(cpp_lines, used_agents)) |
| 485 fout.close() | 485 fout.close() |
| 486 | 486 |
| 487 for agent in used_agents: | 487 for agent in used_agents: |
| 488 cpp_includes.append(include_inspector_header(agent_class_name(agent))) | 488 cpp_includes.append(include_inspector_header(agent_class_name(agent))) |
| 489 cpp_includes.append(include_header("InstrumentingAgentsInl")) | 489 cpp_includes.append(include_header("InstrumentingAgentsInl")) |
| 490 cpp_includes.sort() | 490 cpp_includes.sort() |
| 491 | 491 |
| 492 instrumenting_agents_header, instrumenting_agents_cpp = generate_instrumenti
ng_agents(used_agents) | 492 instrumenting_agents_header, instrumenting_agents_cpp = generate_instrumenti
ng_agents(used_agents) |
| 493 | 493 |
| 494 fout = open(output_h_dir + "/" + "InstrumentingAgentsInl.h", "w") | 494 fout = open(output_dir + "/" + "InstrumentingAgentsInl.h", "w") |
| 495 fout.write(instrumenting_agents_header) | 495 fout.write(instrumenting_agents_header) |
| 496 fout.close() | 496 fout.close() |
| 497 | 497 |
| 498 fout = open(output_cpp_dir + "/InspectorInstrumentationImpl.cpp", "w") | 498 fout = open(output_dir + "/InspectorInstrumentationImpl.cpp", "w") |
| 499 fout.write(template_cpp.substitute(None, | 499 fout.write(template_cpp.substitute(None, |
| 500 includes="\n".join(cpp_includes), | 500 includes="\n".join(cpp_includes), |
| 501 extra_definitions=instrumenting_agents_cp
p, | 501 extra_definitions=instrumenting_agents_cp
p, |
| 502 methods="\n".join(cpp_lines))) | 502 methods="\n".join(cpp_lines))) |
| 503 fout.close() | 503 fout.close() |
| 504 | 504 |
| 505 | 505 |
| 506 cmdline_parser = optparse.OptionParser() | 506 cmdline_parser = optparse.OptionParser() |
| 507 cmdline_parser.add_option("--output_h_dir") | 507 cmdline_parser.add_option("--output_dir") |
| 508 cmdline_parser.add_option("--output_cpp_dir") | |
| 509 | 508 |
| 510 try: | 509 try: |
| 511 arg_options, arg_values = cmdline_parser.parse_args() | 510 arg_options, arg_values = cmdline_parser.parse_args() |
| 512 if (len(arg_values) != 1): | 511 if (len(arg_values) != 1): |
| 513 raise Exception("Exactly one plain argument expected (found %s)" % len(a
rg_values)) | 512 raise Exception("Exactly one plain argument expected (found %s)" % len(a
rg_values)) |
| 514 input_path = arg_values[0] | 513 input_path = arg_values[0] |
| 515 output_header_dirpath = arg_options.output_h_dir | 514 output_dirpath = arg_options.output_dir |
| 516 output_cpp_dirpath = arg_options.output_cpp_dir | 515 if not output_dirpath: |
| 517 if not output_header_dirpath: | 516 raise Exception("Output directory must be specified") |
| 518 raise Exception("Output .h directory must be specified") | |
| 519 if not output_cpp_dirpath: | |
| 520 raise Exception("Output .cpp directory must be specified") | |
| 521 except Exception: | 517 except Exception: |
| 522 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | 518 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
| 523 exc = sys.exc_info()[1] | 519 exc = sys.exc_info()[1] |
| 524 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) | 520 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
| 525 sys.stderr.write("Usage: <script> InspectorInstrumentation.idl --output_h_di
r <output_header_dir> --output_cpp_dir <output_cpp_dir>\n") | 521 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") |
| 526 exit(1) | 522 exit(1) |
| 527 | 523 |
| 528 generate(input_path, output_header_dirpath, output_cpp_dirpath) | 524 generate(input_path, output_dirpath) |
| OLD | NEW |