9
9
#
10
10
#===------------------------------------------------------------------------===#
11
11
12
+ from __future__ import print_function
13
+
12
14
import argparse
13
15
import os
14
16
import re
15
17
import sys
16
18
17
-
18
19
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
19
20
# and 'False' if the entry already existed.
20
21
def adapt_cmake (module_path , check_name_camel ):
@@ -30,7 +31,7 @@ def adapt_cmake(module_path, check_name_camel):
30
31
return False
31
32
32
33
print ('Updating %s...' % filename )
33
- with open (filename , 'wb ' ) as f :
34
+ with open (filename , 'w ' ) as f :
34
35
cpp_found = False
35
36
file_added = False
36
37
for line in lines :
@@ -50,7 +51,7 @@ def write_header(module_path, module, check_name, check_name_camel):
50
51
check_name_dashes = module + '-' + check_name
51
52
filename = os .path .join (module_path , check_name_camel ) + '.h'
52
53
print ('Creating %s...' % filename )
53
- with open (filename , 'wb ' ) as f :
54
+ with open (filename , 'w ' ) as f :
54
55
header_guard = ('LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_' + module .upper () + '_'
55
56
+ check_name_camel .upper () + '_H' )
56
57
f .write ('//===--- ' )
@@ -103,7 +104,7 @@ class %(check_name)s : public ClangTidyCheck {
103
104
def write_implementation (module_path , module , check_name_camel ):
104
105
filename = os .path .join (module_path , check_name_camel ) + '.cpp'
105
106
print ('Creating %s...' % filename )
106
- with open (filename , 'wb ' ) as f :
107
+ with open (filename , 'w ' ) as f :
107
108
f .write ('//===--- ' )
108
109
f .write (os .path .basename (filename ))
109
110
f .write (' - clang-tidy' )
@@ -152,14 +153,15 @@ def write_implementation(module_path, module, check_name_camel):
152
153
153
154
# Modifies the module to include the new check.
154
155
def adapt_module (module_path , module , check_name , check_name_camel ):
155
- modulecpp = filter (lambda p : p .lower () == module .lower () + 'tidymodule.cpp' ,
156
- os .listdir (module_path ))[0 ]
156
+ modulecpp = list (filter (
157
+ lambda p : p .lower () == module .lower () + 'tidymodule.cpp' ,
158
+ os .listdir (module_path )))[0 ]
157
159
filename = os .path .join (module_path , modulecpp )
158
160
with open (filename , 'r' ) as f :
159
161
lines = f .readlines ()
160
162
161
163
print ('Updating %s...' % filename )
162
- with open (filename , 'wb ' ) as f :
164
+ with open (filename , 'w ' ) as f :
163
165
header_added = False
164
166
header_found = False
165
167
check_added = False
@@ -199,7 +201,7 @@ def add_release_notes(module_path, module, check_name):
199
201
lines = f .readlines ()
200
202
201
203
print ('Updating %s...' % filename )
202
- with open (filename , 'wb ' ) as f :
204
+ with open (filename , 'w ' ) as f :
203
205
note_added = False
204
206
header_found = False
205
207
@@ -227,7 +229,7 @@ def write_test(module_path, module, check_name, test_extension):
227
229
filename = os .path .normpath (os .path .join (module_path , '../../test/clang-tidy' ,
228
230
check_name_dashes + '.' + test_extension ))
229
231
print ('Creating %s...' % filename )
230
- with open (filename , 'wb ' ) as f :
232
+ with open (filename , 'w ' ) as f :
231
233
f .write ("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
232
234
233
235
// FIXME: Add something that triggers the check here.
@@ -251,8 +253,8 @@ def update_checks_list(clang_tidy_path):
251
253
filename = os .path .normpath (os .path .join (docs_dir , 'list.rst' ))
252
254
with open (filename , 'r' ) as f :
253
255
lines = f .readlines ()
254
- doc_files = filter (lambda s : s .endswith ('.rst' ) and s != 'list.rst' ,
255
- os .listdir (docs_dir ))
256
+ doc_files = list ( filter (lambda s : s .endswith ('.rst' ) and s != 'list.rst' ,
257
+ os .listdir (docs_dir )))
256
258
doc_files .sort ()
257
259
258
260
def format_link (doc_file ):
@@ -275,7 +277,7 @@ def format_link(doc_file):
275
277
checks = map (format_link , doc_files )
276
278
277
279
print ('Updating %s...' % filename )
278
- with open (filename , 'wb ' ) as f :
280
+ with open (filename , 'w ' ) as f :
279
281
for line in lines :
280
282
f .write (line )
281
283
if line .startswith ('.. toctree::' ):
@@ -289,7 +291,7 @@ def write_docs(module_path, module, check_name):
289
291
filename = os .path .normpath (os .path .join (
290
292
module_path , '../../docs/clang-tidy/checks/' , check_name_dashes + '.rst' ))
291
293
print ('Creating %s...' % filename )
292
- with open (filename , 'wb ' ) as f :
294
+ with open (filename , 'w ' ) as f :
293
295
f .write (""".. title:: clang-tidy - %(check_name_dashes)s
294
296
295
297
%(check_name_dashes)s
@@ -333,16 +335,16 @@ def main():
333
335
return
334
336
335
337
if not args .module or not args .check :
336
- print 'Module and check must be specified.'
338
+ print ( 'Module and check must be specified.' )
337
339
parser .print_usage ()
338
340
return
339
341
340
342
module = args .module
341
343
check_name = args .check
342
344
343
345
if check_name .startswith (module ):
344
- print 'Check name "%s" must not start with the module "%s". Exiting.' % (
345
- check_name , module )
346
+ print ( 'Check name "%s" must not start with the module "%s". Exiting.' % (
347
+ check_name , module ))
346
348
return
347
349
check_name_camel = '' .join (map (lambda elem : elem .capitalize (),
348
350
check_name .split ('-' ))) + 'Check'
0 commit comments