• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2016 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
6import json
7import os
8import subprocess
9
10
11def GenerateWithNinja(path):
12  """Generates a compile database using ninja.
13
14  Args:
15    path: The build directory to generate a compile database for.
16  """
17  # TODO(dcheng): Incorporate Windows-specific compile DB munging from
18  # https://codereview.chromium.org/718873004
19  print 'Generating compile database in %s...' % path
20  args = ['ninja', '-C', path, '-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx']
21  output = subprocess.check_output(args)
22  with file(os.path.join(path, 'compile_commands.json'), 'w') as f:
23    f.write(output)
24
25
26def Read(path):
27  """Reads a compile database into memory.
28
29  Args:
30    path: Directory that contains the compile database.
31  """
32  with open(os.path.join(path, 'compile_commands.json'), 'rb') as db:
33    return json.load(db)
34