Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tools/boilerplate.py

Issue 2570093002: Remove test suffixes from included filename in boilerplate.py. (Closed)
Patch Set: Add for loop; add '_browsertest' suffix. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 suffixes = [ '_test', '_unittest', '_browsertest' ]
57 for suffix in suffixes:
58 l = len(suffix)
59 if base[-l:] == suffix:
60 return base[:-l]
61 return base
62
54 def _CppImplementation(filename): 63 def _CppImplementation(filename):
55 base, _ = os.path.splitext(filename) 64 include = '#include "' + _RemoveTestSuffix(filename) + '.h"'
56 include = '#include "' + base + '.h"'
57 return '\n'.join(['', include]) 65 return '\n'.join(['', include])
58 66
59 67
60 def _ObjCppImplementation(filename): 68 def _ObjCppImplementation(filename):
61 base, _ = os.path.splitext(filename) 69 include = '#import "' + _RemoveTestSuffix(filename) + '.h"'
62 include = '#import "' + base + '.h"'
63 return '\n'.join(['', include]) 70 return '\n'.join(['', include])
64 71
65 72
66 def _CreateFile(filename): 73 def _CreateFile(filename):
67 contents = _GetHeader(filename) + '\n' 74 contents = _GetHeader(filename) + '\n'
68 75
69 if filename.endswith('.h'): 76 if filename.endswith('.h'):
70 contents += _CppHeader(filename) 77 contents += _CppHeader(filename)
71 elif filename.endswith('.cc'): 78 elif filename.endswith('.cc'):
72 contents += _CppImplementation(filename) 79 contents += _CppImplementation(filename)
(...skipping 21 matching lines...) Expand all
94 if os.path.exists(f): 101 if os.path.exists(f):
95 print >> sys.stderr, 'A file at path %s already exists' % f 102 print >> sys.stderr, 'A file at path %s already exists' % f
96 return 2 103 return 2
97 104
98 for f in files: 105 for f in files:
99 _CreateFile(f) 106 _CreateFile(f)
100 107
101 108
102 if __name__ == '__main__': 109 if __name__ == '__main__':
103 sys.exit(Main()) 110 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698