| 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 # pylint: disable=import-error,print-statement,relative-import | 5 # pylint: disable=import-error,print-statement,relative-import |
| 6 | 6 |
| 7 """Plumbing for a Jinja-based code generator, including CodeGeneratorBase, a bas
e class for all generators.""" | 7 """Plumbing for a Jinja-based code generator, including CodeGeneratorBase, a bas
e class for all generators.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import posixpath | 10 import posixpath |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 # Insert at 1 so at front to override system libraries, and | 38 # Insert at 1 so at front to override system libraries, and |
| 39 # after path[0] == invoking script dir | 39 # after path[0] == invoking script dir |
| 40 sys.path.insert(1, THIRD_PARTY_DIR) | 40 sys.path.insert(1, THIRD_PARTY_DIR) |
| 41 import jinja2 | 41 import jinja2 |
| 42 | 42 |
| 43 | 43 |
| 44 def generate_indented_conditional(code, conditional): | 44 def generate_indented_conditional(code, conditional): |
| 45 # Indent if statement to level of original code | 45 # Indent if statement to level of original code |
| 46 indent = re.match(' *', code).group(0) | 46 indent = re.match(' *', code).group(0) |
| 47 return ('%sif (%s) {\n' % (indent, conditional) + | 47 return ('%sif (%s) {\n' % (indent, conditional) + |
| 48 ' %s\n' % '\n '.join(code.splitlines()) + | 48 ' %s\n' % '\n '.join(code.splitlines()) + |
| 49 '%s}\n' % indent) | 49 '%s}\n' % indent) |
| 50 | 50 |
| 51 | 51 |
| 52 # [Exposed] | 52 # [Exposed] |
| 53 def exposed_if(code, exposed_test): | 53 def exposed_if(code, exposed_test): |
| 54 if not exposed_test: | 54 if not exposed_test: |
| 55 return code | 55 return code |
| 56 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) | 56 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) |
| 57 | 57 |
| 58 | 58 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 # Create a dummy file as output for the build system, | 182 # Create a dummy file as output for the build system, |
| 183 # since filenames of individual cache files are unpredictable and opaque | 183 # since filenames of individual cache files are unpredictable and opaque |
| 184 # (they are hashes of the template path, which varies based on environment) | 184 # (they are hashes of the template path, which varies based on environment) |
| 185 with open(dummy_filename, 'w') as dummy_file: | 185 with open(dummy_filename, 'w') as dummy_file: |
| 186 pass # |open| creates or touches the file | 186 pass # |open| creates or touches the file |
| 187 | 187 |
| 188 | 188 |
| 189 if __name__ == '__main__': | 189 if __name__ == '__main__': |
| 190 sys.exit(main(sys.argv)) | 190 sys.exit(main(sys.argv)) |
| OLD | NEW |