| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 os.path | 5 import os.path |
| 6 import sys | 6 import sys |
| 7 import optparse | 7 import optparse |
| 8 try: | 8 try: |
| 9 import json | 9 import json |
| 10 except ImportError: | 10 except ImportError: |
| 11 import simplejson as json | 11 import simplejson as json |
| 12 | 12 |
| 13 # Path handling for libraries and templates | 13 # Path handling for libraries and templates |
| 14 # Paths have to be normalized because Jinja uses the exact template path to | 14 # Paths have to be normalized because Jinja uses the exact template path to |
| 15 # determine the hash used in the cache filename, and we need a pre-caching step | 15 # determine the hash used in the cache filename, and we need a pre-caching step |
| 16 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 16 # to be concurrency-safe. Use absolute path because __file__ is absolute if |
| 17 # module is imported, and relative if executed directly. | 17 # module is imported, and relative if executed directly. |
| 18 # If paths differ between pre-caching and individual file compilation, the cache | 18 # If paths differ between pre-caching and individual file compilation, the cache |
| 19 # is regenerated, which causes a race condition and breaks concurrent build, | 19 # is regenerated, which causes a race condition and breaks concurrent build, |
| 20 # since some compile processes will try to read the partially written cache. | 20 # since some compile processes will try to read the partially written cache. |
| 21 module_path, module_filename = os.path.split(os.path.realpath(__file__)) | 21 module_path, module_filename = os.path.split(os.path.realpath(__file__)) |
| 22 templates_dir = module_path | 22 templates_dir = module_path |
| 23 | 23 |
| 24 # In Blink, jinja2 is in chromium's third_party directory. | 24 # In Blink, jinja2 is in chromium's third_party directory. |
| 25 # Insert at 1 so at front to override system libraries, and | 25 # Insert at 1 so at front to override system libraries, and |
| 26 # after path[0] == invoking script dir | 26 # after path[0] == invoking script dir |
| 27 third_party_dir = os.path.normpath(os.path.join( | 27 third_party_dir = os.path.normpath(os.path.join( |
| 28 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) | 28 module_path, os.pardir, os.pardir, os.pardir, os.pardir, os.pardir, |
| 29 "third_party")) |
| 29 if os.path.isdir(third_party_dir): | 30 if os.path.isdir(third_party_dir): |
| 30 sys.path.insert(1, third_party_dir) | 31 sys.path.insert(1, third_party_dir) |
| 31 | 32 |
| 32 # In Node, it is in deps folder | 33 # In Node, it is in deps folder |
| 33 deps_dir = os.path.normpath(os.path.join( | 34 deps_dir = os.path.normpath(os.path.join( |
| 34 module_path, os.pardir, os.pardir, "deps")) | 35 module_path, os.pardir, os.pardir, os.pardir, os.pardir, "third_party")) |
| 36 |
| 35 if os.path.isdir(deps_dir): | 37 if os.path.isdir(deps_dir): |
| 36 sys.path.insert(1, os.path.join(deps_dir, "jinja2")) | 38 sys.path.insert(1, os.path.join(deps_dir, "jinja2")) |
| 37 sys.path.insert(1, os.path.join(deps_dir, "markupsafe")) | 39 sys.path.insert(1, os.path.join(deps_dir, "markupsafe")) |
| 38 | 40 |
| 39 import jinja2 | 41 import jinja2 |
| 40 | 42 |
| 41 cmdline_parser = optparse.OptionParser() | 43 cmdline_parser = optparse.OptionParser() |
| 42 cmdline_parser.add_option("--protocol") | 44 cmdline_parser.add_option("--protocol") |
| 43 cmdline_parser.add_option("--include") | 45 cmdline_parser.add_option("--include") |
| 44 cmdline_parser.add_option("--string_type") | 46 cmdline_parser.add_option("--string_type") |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 cpp_file = output_file(cpp_file_name) | 348 cpp_file = output_file(cpp_file_name) |
| 347 h_file.write(h_template.render(template_context)) | 349 h_file.write(h_template.render(template_context)) |
| 348 cpp_file.write(cpp_template.render(template_context)) | 350 cpp_file.write(cpp_template.render(template_context)) |
| 349 h_file.close() | 351 h_file.close() |
| 350 cpp_file.close() | 352 cpp_file.close() |
| 351 | 353 |
| 352 | 354 |
| 353 for domain in json_api["domains"]: | 355 for domain in json_api["domains"]: |
| 354 if domain["domain"] in generate_domains: | 356 if domain["domain"] in generate_domains: |
| 355 generate(domain) | 357 generate(domain) |
| OLD | NEW |