mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 18:49:37 +00:00
tools/generate_compile_commands.py conform to style guide
Change-Id: I7d0b917968cf232fde4d0650e25d82fa6b4caefe Reviewed-on: https://dart-review.googlesource.com/c/86881 Reviewed-by: Zach Anderson <zra@google.com>
This commit is contained in:
parent
ddf3c5ee8c
commit
1f5c77c298
|
@ -4,45 +4,75 @@
|
|||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import subprocess
|
||||
import argparse
|
||||
import generate_buildfiles
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import utils
|
||||
import os
|
||||
|
||||
### Python script to generate compile_commands.json and make it more useful.
|
||||
# Python script to generate compile_commands.json which is used by the clang
|
||||
# and intellij language analysis servers used in IDEs such as Visual Studio
|
||||
# Code and Emacs.
|
||||
|
||||
HOST_OS = utils.GuessOS()
|
||||
|
||||
if not HOST_OS in ['linux', 'macos']:
|
||||
print ("Generate compile_commands has not been ported to %s yet." % (HOST_OS))
|
||||
exit
|
||||
|
||||
if HOST_OS == 'linux':
|
||||
ninja = 'ninja-linux64'
|
||||
out_folder = ' out'
|
||||
if HOST_OS == 'macos':
|
||||
ninja = 'ninja-mac'
|
||||
out_folder = ' xcodebuild'
|
||||
def GenerateCompileCommands(options):
|
||||
gn_result = generate_buildfiles.RunGn(options)
|
||||
if (gn_result != 0):
|
||||
return gn_result
|
||||
|
||||
subprocess.call("python tools/generate_buildfiles.py", shell=True)
|
||||
out_folder = utils.GetBuildRoot(HOST_OS, mode="debug", arch="x64")
|
||||
|
||||
command_set = json.loads(
|
||||
subprocess.check_output(
|
||||
ninja + " -C " + out_folder + "/DebugX64 -t compdb cxx cc h", shell=True
|
||||
if (not os.path.isdir(out_folder)):
|
||||
return 1
|
||||
|
||||
command_set = json.loads(
|
||||
subprocess.check_output(
|
||||
["ninja", "-C", out_folder, "-t", "compdb", "cxx", "cc", "h"]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
commands = []
|
||||
for obj in command_set:
|
||||
C = obj["command"]
|
||||
commands = []
|
||||
for obj in command_set:
|
||||
command = obj["command"]
|
||||
|
||||
# Skip precompiled mode, a lot of code is commented out in precompiled mode
|
||||
if ("-DDART_PRECOMPILED_RUNTIME" in C):
|
||||
continue
|
||||
# Skip precompiled mode, a lot of code is commented out in precompiled mode
|
||||
if ("-DDART_PRECOMPILED_RUNTIME" in command):
|
||||
continue
|
||||
|
||||
# Remove warnings
|
||||
C = C.replace("-Werror", "")
|
||||
# Remove warnings
|
||||
command = command.replace("-Werror", "")
|
||||
|
||||
obj["command"] = C
|
||||
commands += [obj]
|
||||
obj["command"] = command
|
||||
commands += [obj]
|
||||
|
||||
json.dump(commands, open("compile_commands.json", "w"), indent=4)
|
||||
json.dump(commands, open("compile_commands.json", "w"), indent=4)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def ParseArgs(args):
|
||||
args = args[1:]
|
||||
parser = argparse.ArgumentParser(
|
||||
description="A script to generate compile_commands.json which is used by"
|
||||
+ "the clang and intellij language analysis servers used in IDEs such as"
|
||||
+ "Visual Studio Code and Emacs")
|
||||
|
||||
parser.add_argument("-v", "--verbose",
|
||||
help='Verbose output.',
|
||||
default=False,
|
||||
action="store_true")
|
||||
|
||||
return parser.parse_args(args)
|
||||
|
||||
|
||||
def main(argv):
|
||||
options = ParseArgs(argv)
|
||||
return GenerateCompileCommands(options)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
|
|
Loading…
Reference in a new issue