| 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 """ |   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 | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
|  41     match = _RSP_RE.search(e['command']) |  41     match = _RSP_RE.search(e['command']) | 
|  42     rsp_path = os.path.join(e['directory'], match.group(2)) |  42     rsp_path = os.path.join(e['directory'], match.group(2)) | 
|  43     rsp_contents = file(rsp_path).read() |  43     rsp_contents = file(rsp_path).read() | 
|  44     e['command'] = ''.join([ |  44     e['command'] = ''.join([ | 
|  45         e['command'][:match.start(1)], |  45         e['command'][:match.start(1)], | 
|  46         rsp_contents, |  46         rsp_contents, | 
|  47         e['command'][match.end(1):]]) |  47         e['command'][match.end(1):]]) | 
|  48   except IOError: |  48   except IOError: | 
|  49     pass |  49     pass | 
|  50  |  50  | 
|  51   # TODO(dcheng): This should be implemented in Clang tooling. |  | 
|  52   # http://llvm.org/bugs/show_bug.cgi?id=19687 |  | 
|  53   # Finally, use slashes instead of backslashes to avoid bad escaping by the |  | 
|  54   # tooling. This should really only matter for command, but we do it for all |  | 
|  55   # keys for consistency. |  | 
|  56   e['directory'] = e['directory'].replace('\\', '/') |  | 
|  57   e['command'] = e['command'].replace('\\', '/') |  | 
|  58   e['file'] = e['file'].replace('\\', '/') |  | 
|  59  |  | 
|  60   return e |  51   return e | 
|  61  |  52  | 
|  62  |  53  | 
|  63 def main(argv): |  54 def main(argv): | 
|  64   # Parse argument |  55   # Parse argument | 
|  65   parser = argparse.ArgumentParser() |  56   parser = argparse.ArgumentParser() | 
|  66   parser.add_argument( |  57   parser.add_argument( | 
|  67       'build_path', |  58       'build_path', | 
|  68       nargs='?', |  59       nargs='?', | 
|  69       help='Path to build directory', |  60       help='Path to build directory', | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  83   compile_db = [e for e in compile_db if '_nacl.cc.pdb' not in e['command'] |  74   compile_db = [e for e in compile_db if '_nacl.cc.pdb' not in e['command'] | 
|  84       and '_nacl_win64.cc.pdb' not in e['command']] |  75       and '_nacl_win64.cc.pdb' not in e['command']] | 
|  85   print 'Filtered out %d entries...' % (original_length - len(compile_db)) |  76   print 'Filtered out %d entries...' % (original_length - len(compile_db)) | 
|  86   f = file('%s/compile_commands.json' % args.build_path, 'w') |  77   f = file('%s/compile_commands.json' % args.build_path, 'w') | 
|  87   f.write(json.dumps(compile_db, indent=2)) |  78   f.write(json.dumps(compile_db, indent=2)) | 
|  88   print 'Done!' |  79   print 'Done!' | 
|  89  |  80  | 
|  90  |  81  | 
|  91 if __name__ == '__main__': |  82 if __name__ == '__main__': | 
|  92   sys.exit(main(sys.argv[1:])) |  83   sys.exit(main(sys.argv[1:])) | 
| OLD | NEW |