Commit 57b5087f authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Revert "[clang] Drop generated files in compilation database."

This reverts commit 596ae5a1.

Reason for revert: breaks code search, which indexes generated files

Original change's description:
> [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: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#644005}

TBR=dcheng@chromium.org,hokein.wu@gmail.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Id57f162675df0bb274690868f9436edf80c4a0a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1540148Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644659}
parent cb8aabf8
...@@ -102,17 +102,6 @@ def GetNinjaPath(): ...@@ -102,17 +102,6 @@ def GetNinjaPath():
'..', '..', '..', '..', 'third_party', 'depot_tools', ninja_executable) '..', '..', '..', '..', '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. # FIXME: This really should be a build target, rather than generated at runtime.
def GenerateWithNinja(path, targets=[]): def GenerateWithNinja(path, targets=[]):
"""Generates a compile database using ninja. """Generates a compile database using ninja.
...@@ -127,13 +116,10 @@ def GenerateWithNinja(path, targets=[]): ...@@ -127,13 +116,10 @@ def GenerateWithNinja(path, targets=[]):
# TODO(dcheng): Ensure that clang is enabled somehow. # TODO(dcheng): Ensure that clang is enabled somehow.
# First, generate the compile database. # First, generate the compile database.
json_compile_db = json.loads(subprocess.check_output( json_compile_db = subprocess.check_output(
[GetNinjaPath(), '-C', path] + targets + [GetNinjaPath(), '-C', path] + targets +
['-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx'])) ['-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx'])
# Drop generated files. return json.loads(json_compile_db)
# 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): def Read(path):
......
...@@ -73,26 +73,6 @@ class CompileDbTest(unittest.TestCase): ...@@ -73,26 +73,6 @@ class CompileDbTest(unittest.TestCase):
for actual, expected in zip(processed_compile_db, _EXPECTED_COMPILE_DB): for actual, expected in zip(processed_compile_db, _EXPECTED_COMPILE_DB):
self.assertDictEqual(actual, expected) 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__': if __name__ == '__main__':
unittest.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