| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Writes C++ header/cc source files for embedding resources into C++.""" | 5 """Writes C++ header/cc source files for embedding resources into C++.""" |
| 6 | 6 |
| 7 import datetime | 7 import datetime |
| 8 import os | 8 import os |
| 9 import sys |
| 9 | 10 |
| 10 | 11 |
| 11 def WriteSource(base_name, | 12 def WriteSource(base_name, |
| 12 dir_from_src, | 13 dir_from_src, |
| 13 output_dir, | 14 output_dir, |
| 14 global_string_map): | 15 global_string_map): |
| 15 """Writes C++ header/cc source files for the given map of string variables. | 16 """Writes C++ header/cc source files for the given map of string variables. |
| 16 | 17 |
| 17 Args: | 18 Args: |
| 18 base_name: The basename of the file, without the extension. | 19 base_name: The basename of the file, without the extension. |
| 19 dir_from_src: Path from src to the directory that will contain the file, | 20 dir_from_src: Path from src to the directory that will contain the file, |
| 20 using forward slashes. | 21 using forward slashes. |
| 21 output_dir: Directory to output the sources to. | 22 output_dir: Directory to output the sources to. |
| 22 global_string_map: Map of variable names to their string values. These | 23 global_string_map: Map of variable names to their string values. These |
| 23 variables will be available as globals. | 24 variables will be available as globals. |
| 24 """ | 25 """ |
| 25 copyright = '\n'.join([ | 26 copyright = '\n'.join([ |
| 26 '// Copyright %s The Chromium Authors. All rights reserved.', | 27 '// Copyright %s The Chromium Authors. All rights reserved.', |
| 27 '// Use of this source code is governed by a BSD-style license that ' | 28 '// Use of this source code is governed by a BSD-style license that ' |
| 28 'can be', | 29 'can be', |
| 29 '// found in the LICENSE file.']) % datetime.date.today().year | 30 '// found in the LICENSE file.', |
| 31 '', |
| 32 '// This file was generated at (%s) by running:', |
| 33 '// %s']) % ( |
| 34 datetime.date.today().year, |
| 35 datetime.datetime.now().isoformat(' '), |
| 36 ' '.join(sys.argv)) |
| 30 | 37 |
| 31 # Write header file. | 38 # Write header file. |
| 32 externs = [] | 39 externs = [] |
| 33 for name in global_string_map.iterkeys(): | 40 for name in global_string_map.iterkeys(): |
| 34 externs += ['extern const char %s[];' % name] | 41 externs += ['extern const char %s[];' % name] |
| 35 | 42 |
| 36 temp = '_'.join(dir_from_src.split('/') + [base_name]) | 43 temp = '_'.join(dir_from_src.split('/') + [base_name]) |
| 37 define = temp.upper() + '_H_' | 44 define = temp.upper() + '_H_' |
| 38 header = '\n'.join([ | 45 header = '\n'.join([ |
| 39 copyright, | 46 copyright, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 66 cc = '\n'.join([ | 73 cc = '\n'.join([ |
| 67 copyright, | 74 copyright, |
| 68 '', | 75 '', |
| 69 '#include "%s"' % (dir_from_src + '/' + base_name + '.h'), | 76 '#include "%s"' % (dir_from_src + '/' + base_name + '.h'), |
| 70 '', | 77 '', |
| 71 '\n'.join(definitions)]) | 78 '\n'.join(definitions)]) |
| 72 cc += '\n' | 79 cc += '\n' |
| 73 | 80 |
| 74 with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f: | 81 with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f: |
| 75 f.write(cc) | 82 f.write(cc) |
| OLD | NEW |