Commit 596ae5a1 authored by Haojian Wu's avatar Haojian Wu Committed by Commit Bot

[clang] Drop generated files in compilation database.

Generated files (e.g. bind_unittest_nc.cc) are less interesting than regular
human-written files, e.g. it doesn't make sense to apply clang-tidy FixIts to
them; clangd indexer are not interested in indexing them.

And these files are usually not generated when running clang-based tools.

size of compilation databse: 204M => 176M
number of entries : 44450 => 38198

Change-Id: I32c639562187f814a9286f945b9dfcfbc4ab21d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1526264
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Haojian Wu <hokein.wu@gmail.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644005}
parent 1ba1794f
......@@ -102,6 +102,17 @@ def GetNinjaPath():
'..', '..', '..', '..', 'third_party', 'depot_tools', ninja_executable)
def IsGeneratedFile(entry):
"""Check whether an entry in a compilation database is for generated file.
"""
build_dir = entry['directory']
# According to https://www.chromium.org/developers/generated-files, Chromium's
# generated files are output in <build_dir>/gen directory.
gen_dir = os.path.join(build_dir, 'gen', '') # with trailing path separator
absolute_file_path = os.path.normpath(os.path.join(build_dir, entry['file']))
return absolute_file_path.startswith(gen_dir)
# FIXME: This really should be a build target, rather than generated at runtime.
def GenerateWithNinja(path, targets=[]):
"""Generates a compile database using ninja.
......@@ -116,10 +127,13 @@ def GenerateWithNinja(path, targets=[]):
# TODO(dcheng): Ensure that clang is enabled somehow.
# First, generate the compile database.
json_compile_db = subprocess.check_output(
json_compile_db = json.loads(subprocess.check_output(
[GetNinjaPath(), '-C', path] + targets +
['-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx'])
return json.loads(json_compile_db)
['-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx']))
# Drop generated files.
# The directory of the compliation database entry is expected to be the
# absolute path of the given 'path'.
return [entry for entry in json_compile_db if not IsGeneratedFile(entry) ]
def Read(path):
......
......@@ -73,6 +73,26 @@ class CompileDbTest(unittest.TestCase):
for actual, expected in zip(processed_compile_db, _EXPECTED_COMPILE_DB):
self.assertDictEqual(actual, expected)
def testIsGeneratedFiles(self):
if sys.platform != 'win32':
return
test_cases = [
({
'directory': 'chromium/src/out/Release',
'command': 'clang foo.cpp',
'file': '../../chrome/foo.cpp'
}, False),
({
'directory': 'chromium/src/out/Release',
'command': 'clang gen.cpp',
'file': 'gen/gen.cpp'
}, True),
]
for entry, expected in test_cases:
self.assertEqual(compile_db.IsGeneratedFile(entry), expected)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment