| 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 os | 7 import os |
| 8 | 8 |
| 9 | 9 |
| 10 def WriteSource(base_name, | 10 def WriteSource(base_name, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 define = temp.upper() + '_H_' | 36 define = temp.upper() + '_H_' |
| 37 header = '\n'.join([ | 37 header = '\n'.join([ |
| 38 copyright, | 38 copyright, |
| 39 '', | 39 '', |
| 40 '#ifndef ' + define, | 40 '#ifndef ' + define, |
| 41 '#define ' + define, | 41 '#define ' + define, |
| 42 '', | 42 '', |
| 43 '\n'.join(externs), | 43 '\n'.join(externs), |
| 44 '', | 44 '', |
| 45 '#endif // ' + define]) | 45 '#endif // ' + define]) |
| 46 header += '\n' |
| 46 | 47 |
| 47 with open(os.path.join(output_dir, base_name + '.h'), 'w') as f: | 48 with open(os.path.join(output_dir, base_name + '.h'), 'w') as f: |
| 48 f.write(header) | 49 f.write(header) |
| 49 | 50 |
| 50 # Write cc file. | 51 # Write cc file. |
| 51 def EscapeLine(line): | 52 def EscapeLine(line): |
| 52 return line.replace('\\', '\\\\').replace('"', '\\"') | 53 return line.replace('\\', '\\\\').replace('"', '\\"') |
| 53 | 54 |
| 54 definitions = [] | 55 definitions = [] |
| 55 for name, contents in global_string_map.iteritems(): | 56 for name, contents in global_string_map.iteritems(): |
| 56 lines = [] | 57 lines = [] |
| 57 if '\n' not in contents: | 58 if '\n' not in contents: |
| 58 lines = [' "%s"' % EscapeLine(contents)] | 59 lines = [' "%s"' % EscapeLine(contents)] |
| 59 else: | 60 else: |
| 60 for line in contents.split('\n'): | 61 for line in contents.split('\n'): |
| 61 lines += [' "%s\\n"' % EscapeLine(line)] | 62 lines += [' "%s\\n"' % EscapeLine(line)] |
| 62 definitions += ['const char %s[] =\n%s;' % (name, '\n'.join(lines))] | 63 definitions += ['const char %s[] =\n%s;' % (name, '\n'.join(lines))] |
| 63 | 64 |
| 64 cc = '\n'.join([ | 65 cc = '\n'.join([ |
| 65 copyright, | 66 copyright, |
| 66 '', | 67 '', |
| 67 '#include "%s"' % (dir_from_src + '/' + base_name + '.h'), | 68 '#include "%s"' % (dir_from_src + '/' + base_name + '.h'), |
| 68 '', | 69 '', |
| 69 '\n'.join(definitions)]) | 70 '\n'.join(definitions)]) |
| 71 cc += '\n' |
| 70 | 72 |
| 71 with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f: | 73 with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f: |
| 72 f.write(cc) | 74 f.write(cc) |
| OLD | NEW |