1#!/usr/bin/env python 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 4# found in the LICENSE file. 5 6""" 7Helper for generating compile DBs for clang tooling. On non-Windows platforms, 8this is pretty straightforward. On Windows, the tool does a bit of extra work to 9integrate the content of response files, force clang tooling to run in clang-cl 10mode, etc. 11""" 12 13import argparse 14import json 15import os 16import sys 17 18script_dir = os.path.dirname(os.path.realpath(__file__)) 19tool_dir = os.path.abspath(os.path.join(script_dir, '../pylib')) 20sys.path.insert(0, tool_dir) 21 22from clang import compile_db 23 24 25def main(argv): 26 parser = argparse.ArgumentParser() 27 parser.add_argument( 28 '-p', 29 required=True, 30 help='Path to build directory') 31 parser.add_argument( 32 'targets', 33 nargs='*', 34 help='Additional targets to pass to ninja') 35 parser.add_argument( 36 '-o', 37 help='File to write the compilation database to. Defaults to stdout') 38 39 args = parser.parse_args() 40 41 compdb_text = json.dumps( 42 compile_db.ProcessCompileDatabaseIfNeeded( 43 compile_db.GenerateWithNinja(args.p, args.targets))) 44 if args.o is None: 45 print(compdb_text) 46 else: 47 with open(args.o, 'w') as f: 48 f.write(compdb_text) 49 50 51if __name__ == '__main__': 52 sys.exit(main(sys.argv[1:])) 53