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

Side by Side Diff: tools/clang/scripts/generate_win_compdb.py

Issue 2542563002: Clang scripts updates. (Closed)
Patch Set: nits 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 | tools/clang/scripts/run_tool.py » ('j') | 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 """ 6 """
7 Clang tools on Windows are still a bit busted. The tooling can't handle 7 Clang tools on Windows are still a bit busted. The tooling can't handle
8 backslashes in paths, doesn't understand how to read .rsp files, etc. In 8 backslashes in paths, doesn't understand how to read .rsp files, etc. In
9 addition, ninja generates compile commands prefixed with the ninja msvc helper, 9 addition, ninja generates compile commands prefixed with the ninja msvc helper,
10 which also confuses clang. This script generates a compile DB that should mostly 10 which also confuses clang. This script generates a compile DB that should mostly
11 work until clang tooling can be improved upstream. 11 work until clang tooling can be improved upstream.
12 """ 12 """
13 13
14 import argparse
14 import os 15 import os
15 import re 16 import re
16 import json 17 import json
17 import shlex 18 import shlex
18 import subprocess 19 import subprocess
19 import sys 20 import sys
20 21
21 22
22 _NINJA_MSVC_WRAPPER = re.compile('ninja -t msvc -e .+? -- ') 23 _NINJA_MSVC_WRAPPER = re.compile('ninja -t msvc -e .+? -- ')
23 _RSP_RE = re.compile(r' (@(.+?\.rsp)) ') 24 _RSP_RE = re.compile(r' (@(.+?\.rsp)) ')
(...skipping 29 matching lines...) Expand all
53 # tooling. This should really only matter for command, but we do it for all 54 # tooling. This should really only matter for command, but we do it for all
54 # keys for consistency. 55 # keys for consistency.
55 e['directory'] = e['directory'].replace('\\', '/') 56 e['directory'] = e['directory'].replace('\\', '/')
56 e['command'] = e['command'].replace('\\', '/') 57 e['command'] = e['command'].replace('\\', '/')
57 e['file'] = e['file'].replace('\\', '/') 58 e['file'] = e['file'].replace('\\', '/')
58 59
59 return e 60 return e
60 61
61 62
62 def main(argv): 63 def main(argv):
64 # Parse argument
65 parser = argparse.ArgumentParser()
66 parser.add_argument(
67 'build_path',
68 nargs='?',
69 help='Path to build directory',
70 default='out/Debug')
71 args = parser.parse_args()
63 # First, generate the compile database. 72 # First, generate the compile database.
64 print 'Generating compile DB with ninja...' 73 print 'Generating compile DB with ninja...'
65 compile_db_as_json = subprocess.check_output(shlex.split( 74 compile_db_as_json = subprocess.check_output(shlex.split(
66 'ninja -C out/Debug -t compdb cc cxx objc objcxx')) 75 'ninja -C %s -t compdb cc cxx objc objcxx' % args.build_path))
67 76
68 compile_db = json.loads(compile_db_as_json) 77 compile_db = json.loads(compile_db_as_json)
69 print 'Read in %d entries from the compile db' % len(compile_db) 78 print 'Read in %d entries from the compile db' % len(compile_db)
70 compile_db = [_ProcessEntry(e) for e in compile_db] 79 compile_db = [_ProcessEntry(e) for e in compile_db]
71 original_length = len(compile_db) 80 original_length = len(compile_db)
72 81
73 # Filter out NaCl stuff. The clang tooling chokes on them. 82 # Filter out NaCl stuff. The clang tooling chokes on them.
74 compile_db = [e for e in compile_db if '_nacl.cc.pdb' not in e['command'] 83 compile_db = [e for e in compile_db if '_nacl.cc.pdb' not in e['command']
75 and '_nacl_win64.cc.pdb' not in e['command']] 84 and '_nacl_win64.cc.pdb' not in e['command']]
76 print 'Filtered out %d entries...' % (original_length - len(compile_db)) 85 print 'Filtered out %d entries...' % (original_length - len(compile_db))
77 f = file('out/Debug/compile_commands.json', 'w') 86 f = file('%s/compile_commands.json' % args.build_path, 'w')
78 f.write(json.dumps(compile_db, indent=2)) 87 f.write(json.dumps(compile_db, indent=2))
79 print 'Done!' 88 print 'Done!'
80 89
81 90
82 if __name__ == '__main__': 91 if __name__ == '__main__':
83 sys.exit(main(sys.argv[1:])) 92 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | tools/clang/scripts/run_tool.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698