Flutter Engine
The Flutter Engine
Functions | Variables
generate_idefiles Namespace Reference

Functions

def GenerateIdeFiles (options)
 
def GenerateCompileCommands (options)
 
def main (argv)
 

Variables

 HOST_OS = utils.GuessOS()
 

Function Documentation

◆ GenerateCompileCommands()

def generate_idefiles.GenerateCompileCommands (   options)
Generate compile_commands.json for the C++ analysis servers.

compile_commands.json is used by the c++ clang and intellij language analysis
servers used in IDEs such as Visual Studio Code and Emacs.

Args:
options: supported options include: verbose, force, dir

Returns:
success (0) or failure (non zero)

Definition at line 29 of file generate_idefiles.py.

29def GenerateCompileCommands(options):
30 """Generate compile_commands.json for the C++ analysis servers.
31
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.
34
35 Args:
36 options: supported options include: verbose, force, dir
37
38 Returns:
39 success (0) or failure (non zero)
40 """
41
42 fname = os.path.join(options.dir, "compile_commands.json")
43
44 if os.path.isfile(fname) and not options.force:
45 print(fname + " already exists, use --force to override")
46 return
47
48 gn_result = generate_buildfiles.RunGn(options)
49 if gn_result != 0:
50 return gn_result
51
52 out_folder = utils.GetBuildRoot(HOST_OS,
53 mode="debug",
54 arch=options.arch,
55 target_os=options.os,
56 sanitizer=options.sanitizer)
57
58 if not os.path.isdir(out_folder):
59 return 1
60
61 command_set = json.loads(
62 subprocess.check_output([
63 "buildtools/ninja/ninja", "-C", out_folder, "-t", "compdb", "-x",
64 "cxx", "cc", "h"
65 ]))
66
67 commands = []
68 for obj in command_set:
69 command = obj["command"]
70
71 # Skip precompiled mode, a lot of code is commented out in precompiled mode
72 if "-DDART_PRECOMPILED_RUNTIME" in command:
73 continue
74
75 # Remove warnings
76 command = command.replace("-Werror", "")
77
78 match = re.search(r"(\.\.\/\.\.\/[^ ]+\/clang\/bin\/clang)", command)
79 if match:
80 command = match.group(1) + command[match.end():]
81 else:
82 print("Path ending in clang/bin/clang not found in the command.")
83
84 # Remove ninja prepend on Windows.
85 # This is not fully correct, as now it fails to find a sysroot for
86 # Windows. However, clangd completely fails with the `-t` flag.
87 command = re.sub(r"([^\s]*)ninja -t msvc -e environment.x64 --", "",
88 command)
89
90 # Add sysroot from out\DebugX64\environment.x64 on Windows.
91 # TODO(dacoharkes): Fetch the paths from that file.
92 windowsSysroots = [
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',
99 ]
100 for windowsSysroot in windowsSysroots:
101 command = command.replace(
102 "-DDART_TARGET_OS_WINDOWS",
103 "-DDART_TARGET_OS_WINDOWS \"-I%s\"" % windowsSysroot)
104
105 # Prevent packing errors from causing fatal_too_many_errors on Windows.
106 command = command.replace("-DDART_TARGET_OS_WINDOWS",
107 "-DDART_TARGET_OS_WINDOWS -ferror-limit=0")
108
109 obj["command"] = command
110 commands += [obj]
111
112 with open(fname, "w") as f:
113 json.dump(commands, f, indent=4)
114
115 return 0
116
117
def GenerateCompileCommands(options)
def print(*args, **kwargs)
Definition: run_tests.py:49
def GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)
Definition: utils.py:143

◆ GenerateIdeFiles()

def generate_idefiles.GenerateIdeFiles (   options)

Definition at line 25 of file generate_idefiles.py.

25def GenerateIdeFiles(options):
27
28
def GenerateIdeFiles(options)

◆ main()

def generate_idefiles.main (   argv)

Definition at line 118 of file generate_idefiles.py.

118def main(argv):
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 "
122 "c++ and Dart.")
123
124 parser.add_argument("-v",
125 "--verbose",
126 help="Verbose output.",
127 action="store_true")
128
129 parser.add_argument("-f",
130 "--force",
131 help="Override files.",
132 action="store_true")
133
134 parser.add_argument("-d",
135 "--dir",
136 help="Target directory.",
137 default=utils.DART_DIR)
138
139 parser.add_argument("-a",
140 "--arch",
141 help="Target architecture for runtime sources.",
142 default="x64")
143
144 parser.add_argument("-s",
145 "--os",
146 help="Target operating system for runtime sources.",
147 default=HOST_OS)
148
149 parser.add_argument('--sanitizer',
150 type=str,
151 help='Build variants (comma-separated).',
152 metavar='[none,asan,lsan,msan,tsan,ubsan]',
153 default='none')
154
155 options = parser.parse_args(argv[1:])
156
157 return GenerateIdeFiles(options)
158
159

Variable Documentation

◆ HOST_OS

generate_idefiles.HOST_OS = utils.GuessOS()

Definition at line 22 of file generate_idefiles.py.