| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Create files with copyright boilerplate and header include guards. | 6 """Create files with copyright boilerplate and header include guards. |
| 7 | 7 |
| 8 Usage: tools/boilerplate.py path/to/file.{h,cc} | 8 Usage: tools/boilerplate.py path/to/file.{h,cc} |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 def _RemoveTestSuffix(filename): | 54 def _RemoveTestSuffix(filename): |
| 55 base, _ = os.path.splitext(filename) | 55 base, _ = os.path.splitext(filename) |
| 56 suffixes = [ '_test', '_unittest', '_browsertest' ] | 56 suffixes = [ '_test', '_unittest', '_browsertest' ] |
| 57 for suffix in suffixes: | 57 for suffix in suffixes: |
| 58 l = len(suffix) | 58 l = len(suffix) |
| 59 if base[-l:] == suffix: | 59 if base[-l:] == suffix: |
| 60 return base[:-l] | 60 return base[:-l] |
| 61 return base | 61 return base |
| 62 | 62 |
| 63 def _CppImplementation(filename): | 63 def _CppImplementation(filename): |
| 64 include = '#include "' + _RemoveTestSuffix(filename) + '.h"' | 64 return '\n#include "' + _RemoveTestSuffix(filename) + '.h"\n' |
| 65 return '\n'.join(['', include]) | |
| 66 | 65 |
| 67 | 66 |
| 68 def _ObjCppImplementation(filename): | 67 def _ObjCppImplementation(filename): |
| 69 include = '#import "' + _RemoveTestSuffix(filename) + '.h"' | 68 return '\n#import "' + _RemoveTestSuffix(filename) + '.h"\n' |
| 70 return '\n'.join(['', include]) | |
| 71 | 69 |
| 72 | 70 |
| 73 def _CreateFile(filename): | 71 def _CreateFile(filename): |
| 74 contents = _GetHeader(filename) + '\n' | 72 contents = _GetHeader(filename) + '\n' |
| 75 | 73 |
| 76 if filename.endswith('.h'): | 74 if filename.endswith('.h'): |
| 77 contents += _CppHeader(filename) | 75 contents += _CppHeader(filename) |
| 78 elif filename.endswith('.cc'): | 76 elif filename.endswith('.cc'): |
| 79 contents += _CppImplementation(filename) | 77 contents += _CppImplementation(filename) |
| 80 elif filename.endswith('.mm'): | 78 elif filename.endswith('.mm'): |
| (...skipping 20 matching lines...) Expand all Loading... |
| 101 if os.path.exists(f): | 99 if os.path.exists(f): |
| 102 print >> sys.stderr, 'A file at path %s already exists' % f | 100 print >> sys.stderr, 'A file at path %s already exists' % f |
| 103 return 2 | 101 return 2 |
| 104 | 102 |
| 105 for f in files: | 103 for f in files: |
| 106 _CreateFile(f) | 104 _CreateFile(f) |
| 107 | 105 |
| 108 | 106 |
| 109 if __name__ == '__main__': | 107 if __name__ == '__main__': |
| 110 sys.exit(Main()) | 108 sys.exit(Main()) |
| OLD | NEW |