| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import optparse | 5 import optparse |
| 6 import os.path | 6 import os.path |
| 7 import re | 7 import re |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 # Path handling for libraries and templates | 10 # Path handling for libraries and templates |
| 11 # Paths have to be normalized because Jinja uses the exact template path to | 11 # Paths have to be normalized because Jinja uses the exact template path to |
| 12 # determine the hash used in the cache filename, and we need a pre-caching step | 12 # determine the hash used in the cache filename, and we need a pre-caching step |
| 13 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 13 # to be concurrency-safe. Use absolute path because __file__ is absolute if |
| 14 # module is imported, and relative if executed directly. | 14 # module is imported, and relative if executed directly. |
| 15 # If paths differ between pre-caching and individual file compilation, the cache | 15 # If paths differ between pre-caching and individual file compilation, the cache |
| 16 # is regenerated, which causes a race condition and breaks concurrent build, | 16 # is regenerated, which causes a race condition and breaks concurrent build, |
| 17 # since some compile processes will try to read the partially written cache. | 17 # since some compile processes will try to read the partially written cache. |
| 18 module_path, module_filename = os.path.split(os.path.realpath(__file__)) | 18 module_path, module_filename = os.path.split(os.path.realpath(__file__)) |
| 19 templates_dir = module_path | 19 templates_dir = os.path.join(module_path, "templates") |
| 20 third_party_dir = os.path.normpath(os.path.join( | 20 third_party_dir = os.path.normpath(os.path.join( |
| 21 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) | 21 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) |
| 22 # jinja2 is in chromium's third_party directory. | 22 # jinja2 is in chromium's third_party directory. |
| 23 # Insert at 1 so at front to override system libraries, and | 23 # Insert at 1 so at front to override system libraries, and |
| 24 # after path[0] == invoking script dir | 24 # after path[0] == invoking script dir |
| 25 sys.path.insert(1, third_party_dir) | 25 sys.path.insert(1, third_party_dir) |
| 26 import jinja2 | 26 import jinja2 |
| 27 | 27 |
| 28 | 28 |
| 29 def to_lower_case(name): | 29 def to_lower_case(name): |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 def include_header(name): | 106 def include_header(name): |
| 107 return "#include \"%s.h\"" % name | 107 return "#include \"%s.h\"" % name |
| 108 | 108 |
| 109 | 109 |
| 110 def include_inspector_header(name): | 110 def include_inspector_header(name): |
| 111 if name == "PerformanceMonitor": | 111 if name == "PerformanceMonitor": |
| 112 return include_header("core/frame/" + name) | 112 return include_header("core/frame/" + name) |
| 113 if name == "PlatformInstrumentation": | 113 if name == "PlatformInstrumentation": |
| 114 return include_header("platform/instrumentation/" + name) | 114 return include_header("platform/instrumentation/" + name) |
| 115 if name == "CoreProbes": |
| 116 return include_header("core/instrumentation/" + name) |
| 115 return include_header("core/inspector/" + name) | 117 return include_header("core/inspector/" + name) |
| 116 | 118 |
| 117 | 119 |
| 118 class Method(object): | 120 class Method(object): |
| 119 def __init__(self, source): | 121 def __init__(self, source): |
| 120 match = re.match(r"(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", so
urce) | 122 match = re.match(r"(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", so
urce) |
| 121 if not match: | 123 if not match: |
| 122 sys.stderr.write("Cannot parse %s\n" % source) | 124 sys.stderr.write("Cannot parse %s\n" % source) |
| 123 sys.exit(1) | 125 sys.exit(1) |
| 124 | 126 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 all_agents.add(agent) | 223 all_agents.add(agent) |
| 222 all_defines += f.defines | 224 all_defines += f.defines |
| 223 | 225 |
| 224 template_context = { | 226 template_context = { |
| 225 "files": files, | 227 "files": files, |
| 226 "agents": all_agents, | 228 "agents": all_agents, |
| 227 "defines": all_defines, | 229 "defines": all_defines, |
| 228 "name": base_name, | 230 "name": base_name, |
| 229 "input_file": os.path.basename(input_path) | 231 "input_file": os.path.basename(input_path) |
| 230 } | 232 } |
| 231 cpp_template = jinja_env.get_template("/InstrumentingProbesImpl_cpp.template") | 233 cpp_template = jinja_env.get_template("/InstrumentingProbesImpl.cpp.tmpl") |
| 232 cpp_file = open(output_dirpath + "/" + base_name + "Impl.cpp", "w") | 234 cpp_file = open(output_dirpath + "/" + base_name + "Impl.cpp", "w") |
| 233 cpp_file.write(cpp_template.render(template_context)) | 235 cpp_file.write(cpp_template.render(template_context)) |
| 234 cpp_file.close() | 236 cpp_file.close() |
| 235 | 237 |
| 236 agents_h_template = jinja_env.get_template("/InstrumentingAgents_h.template") | 238 sink_h_template = jinja_env.get_template("/ProbesSink.h.tmpl") |
| 237 agents_h_file = open(output_dirpath + "/" + base_name + "Agents.h", "w") | 239 sink_h_file = open(output_dirpath + "/" + base_name + "Sink.h", "w") |
| 238 agents_h_file.write(agents_h_template.render(template_context)) | 240 sink_h_file.write(sink_h_template.render(template_context)) |
| 239 agents_h_file.close() | 241 sink_h_file.close() |
| 240 | 242 |
| 241 for f in files: | 243 for f in files: |
| 242 template_context["file"] = f | 244 template_context["file"] = f |
| 243 h_template = jinja_env.get_template("/InstrumentingProbesImpl_h.template") | 245 h_template = jinja_env.get_template("/InstrumentingProbesInl.h.tmpl") |
| 244 h_file = open(output_dirpath + "/" + f.header_name + ".h", "w") | 246 h_file = open(output_dirpath + "/" + f.header_name + ".h", "w") |
| 245 h_file.write(h_template.render(template_context)) | 247 h_file.write(h_template.render(template_context)) |
| 246 h_file.close() | 248 h_file.close() |
| OLD | NEW |