Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 return '\n'.join([ | 44 return '\n'.join([ |
| 45 '', | 45 '', |
| 46 '#ifndef ' + guard, | 46 '#ifndef ' + guard, |
| 47 '#define ' + guard, | 47 '#define ' + guard, |
| 48 '', | 48 '', |
| 49 '#endif // ' + guard, | 49 '#endif // ' + guard, |
| 50 '' | 50 '' |
| 51 ]) | 51 ]) |
| 52 | 52 |
| 53 | 53 |
| 54 def _RemoveTestSuffix(filename): | |
| 55 base, _ = os.path.splitext(filename) | |
| 56 if base[-5:] == '_test': | |
|
Robert Sesek
2016/12/13 17:23:20
It may be easier to maintain something like this:
Bence
2016/12/14 12:02:19
Done.
| |
| 57 return base[:-5] | |
| 58 if base[-9:] == '_unittest': | |
| 59 return base[:-9] | |
| 60 return base | |
| 61 | |
| 54 def _CppImplementation(filename): | 62 def _CppImplementation(filename): |
| 55 base, _ = os.path.splitext(filename) | 63 include = '#include "' + _RemoveTestSuffix(filename) + '.h"' |
| 56 include = '#include "' + base + '.h"' | |
| 57 return '\n'.join(['', include]) | 64 return '\n'.join(['', include]) |
| 58 | 65 |
| 59 | 66 |
| 60 def _ObjCppImplementation(filename): | 67 def _ObjCppImplementation(filename): |
| 61 base, _ = os.path.splitext(filename) | 68 include = '#import "' + _RemoveTestSuffix(filename) + '.h"' |
| 62 include = '#import "' + base + '.h"' | |
| 63 return '\n'.join(['', include]) | 69 return '\n'.join(['', include]) |
| 64 | 70 |
| 65 | 71 |
| 66 def _CreateFile(filename): | 72 def _CreateFile(filename): |
| 67 contents = _GetHeader(filename) + '\n' | 73 contents = _GetHeader(filename) + '\n' |
| 68 | 74 |
| 69 if filename.endswith('.h'): | 75 if filename.endswith('.h'): |
| 70 contents += _CppHeader(filename) | 76 contents += _CppHeader(filename) |
| 71 elif filename.endswith('.cc'): | 77 elif filename.endswith('.cc'): |
| 72 contents += _CppImplementation(filename) | 78 contents += _CppImplementation(filename) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 94 if os.path.exists(f): | 100 if os.path.exists(f): |
| 95 print >> sys.stderr, 'A file at path %s already exists' % f | 101 print >> sys.stderr, 'A file at path %s already exists' % f |
| 96 return 2 | 102 return 2 |
| 97 | 103 |
| 98 for f in files: | 104 for f in files: |
| 99 _CreateFile(f) | 105 _CreateFile(f) |
| 100 | 106 |
| 101 | 107 |
| 102 if __name__ == '__main__': | 108 if __name__ == '__main__': |
| 103 sys.exit(Main()) | 109 sys.exit(Main()) |
| OLD | NEW |