6"""Script to generate configuration files for analysis servers of C++ and Dart.
8It generates compile_commands.json for C++ clang and intellij and
9analysis_options.yaml for the Dart analyzer.
19import generate_buildfiles
30 """Generate compile_commands.json for the C++ analysis servers.
32 compile_commands.json is used by the c++ clang
and intellij language analysis
33 servers used
in IDEs such
as Visual Studio Code
and Emacs.
36 options: supported options include: verbose, force, dir
39 success (0)
or failure (non zero)
42 fname = os.path.join(options.dir, "compile_commands.json")
44 if os.path.isfile(fname)
and not options.force:
45 print(fname +
" already exists, use --force to override")
56 sanitizer=options.sanitizer)
58 if not os.path.isdir(out_folder):
61 command_set = json.loads(
62 subprocess.check_output([
63 "buildtools/ninja/ninja",
"-C", out_folder,
"-t",
"compdb",
"-x",
68 for obj
in command_set:
69 command = obj[
"command"]
72 if "-DDART_PRECOMPILED_RUNTIME" in command:
76 command = command.replace(
"-Werror",
"")
78 match = re.search(
r"(\.\.\/\.\.\/[^ ]+\/clang\/bin\/clang)", command)
80 command = match.group(1) + command[match.end():]
82 print(
"Path ending in clang/bin/clang not found in the command.")
87 command = re.sub(
r"([^\s]*)ninja -t msvc -e environment.x64 --",
"",
93 'C:\\src\\depot_tools\\win_toolchain\\vs_files\\27370823e7\\Windows Kits\\10\\Include\\10.0.22621.0\\um',
94 'C:\\src\\depot_tools\\win_toolchain\\vs_files\\27370823e7\\Windows Kits\\10\\Include\\10.0.22621.0\\shared',
95 'C:\\src\\depot_tools\\win_toolchain\\vs_files\\27370823e7\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt',
96 'C:\\src\\depot_tools\\win_toolchain\\vs_files\\27370823e7\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt',
97 'C:\\src\\depot_tools\\win_toolchain\\vs_files\\27370823e7\\VC\\Tools\\MSVC\\14.34.31933\\include',
98 'C:\\src\\depot_tools\\win_toolchain\\vs_files\\27370823e7\\VC\\Tools\\MSVC\\14.34.31933\\atlmfc\\include',
100 for windowsSysroot
in windowsSysroots:
101 command = command.replace(
102 "-DDART_TARGET_OS_WINDOWS",
103 "-DDART_TARGET_OS_WINDOWS \"-I%s\"" % windowsSysroot)
106 command = command.replace(
"-DDART_TARGET_OS_WINDOWS",
107 "-DDART_TARGET_OS_WINDOWS -ferror-limit=0")
109 obj[
"command"] = command
112 with open(fname,
"w")
as f:
113 json.dump(commands, f, indent=4)
119 parser = argparse.ArgumentParser(
120 description=
"Python script to generate compile_commands.json and "
121 "analysis_options.yaml which are used by the analysis servers for "
124 parser.add_argument(
"-v",
126 help=
"Verbose output.",
129 parser.add_argument(
"-f",
131 help=
"Override files.",
134 parser.add_argument(
"-d",
136 help=
"Target directory.",
137 default=utils.DART_DIR)
139 parser.add_argument(
"-a",
141 help=
"Target architecture for runtime sources.",
144 parser.add_argument(
"-s",
146 help=
"Target operating system for runtime sources.",
149 parser.add_argument(
'--sanitizer',
151 help=
'Build variants (comma-separated).',
152 metavar=
'[none,asan,lsan,msan,tsan,ubsan]',
155 options = parser.parse_args(argv[1:])
160if __name__ ==
"__main__":
161 sys.exit(
main(sys.argv))
def GenerateIdeFiles(options)
def GenerateCompileCommands(options)
def print(*args, **kwargs)
def GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)