Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
cpp_indexer Namespace Reference

Classes

class  _ClassInfo
 
class  _Indexer
 
class  Location
 
class  SymbolsIndex
 

Functions

 _change_working_directory_to (path)
 
 _create_compilation_database ()
 
 _get_current_commit_hash ()
 
SymbolsIndex _index_source ()
 
SymbolsIndex load_index (str filename)
 

Variables

 _libclang_path = None
 
 _clang_include_dir = None
 
 _path_to_llvm
 
str _DART_CONFIGURATION
 
tuple _DART_BUILD_DIR
 
 _SymbolsIndexSchema = class_schema(SymbolsIndex)()
 

Detailed Description

Clang based C++ code indexer which produces xref.json.

Function Documentation

◆ _change_working_directory_to()

cpp_indexer._change_working_directory_to (   path)
protected

Definition at line 48 of file cpp_indexer.py.

48def _change_working_directory_to(path):
49 oldpwd = os.getcwd()
50 os.chdir(path)
51 try:
52 yield
53 finally:
54 os.chdir(oldpwd)
55
56

◆ _create_compilation_database()

cpp_indexer._create_compilation_database ( )
protected
Create compilation database for the default configuration.

Extacts compilation database (compile_commands.json) for the default
build configuration and filters it down to commands taht builds just
the core VM pieces in the host configuration.

Definition at line 57 of file cpp_indexer.py.

57def _create_compilation_database():
58 """Create compilation database for the default configuration.
59
60 Extacts compilation database (compile_commands.json) for the default
61 build configuration and filters it down to commands taht builds just
62 the core VM pieces in the host configuration.
63 """
64 logging.info('Extracting compilation commands from build files for %s',
65 _DART_CONFIGURATION)
66 with _change_working_directory_to(_DART_BUILD_DIR):
67 commands = json.loads(
68 subprocess.check_output(['ninja', '-C', '.', '-t', 'compdb',
69 'cxx']))
70 pattern = re.compile(
71 r'libdart(_vm|_compiler)?_precompiler_host_targeting_host\.')
72 with open('compile_commands.json', 'w', encoding='utf-8') as outfile:
73 json.dump([
74 cmd for cmd in commands
75 if pattern.search(cmd['command']) is not None
76 ], outfile)
77
78

◆ _get_current_commit_hash()

cpp_indexer._get_current_commit_hash ( )
protected

Definition at line 79 of file cpp_indexer.py.

79def _get_current_commit_hash():
80 return subprocess.check_output(['git', 'merge-base', 'main', 'HEAD'],
81 text=True).strip()
82
83
84@dataclass

◆ _index_source()

SymbolsIndex cpp_indexer._index_source ( )
protected

Definition at line 233 of file cpp_indexer.py.

233def _index_source() -> SymbolsIndex:
234 indexer = _Indexer()
235
236 _create_compilation_database()
237 with _change_working_directory_to(_DART_BUILD_DIR):
238 index = Index.create()
239 compdb = CompilationDatabase.fromDirectory('.')
240
241 commands = list(compdb.getAllCompileCommands())
242 with ShadyBar('Indexing',
243 max=len(commands),
244 suffix='%(percent)d%% eta %(eta_td)s') as progress_bar:
245 for command in commands:
246 args = [
247 arg for arg in command.arguments
248 if arg.startswith('-I') or arg.startswith('-W') or
249 arg.startswith('-D') or arg.startswith('-i') or
250 arg.startswith('sdk/') or arg.startswith('-std')
251 ] + [
252 '-Wno-macro-redefined', '-Wno-unused-const-variable',
253 '-Wno-unused-function', '-Wno-unused-variable'
254 ]
255
256 if _clang_include_dir is not None:
257 args.append(f'-I{_clang_include_dir}')
258
259 unit = index.parse(command.filename, args=args)
260 for diag in unit.diagnostics:
261 print(diag.format())
262
263 indexer.index(unit)
264 progress_bar.next()
265
266 return indexer.symbols_index
267
268
void print(void *str)
Definition bridge.cpp:126

◆ load_index()

SymbolsIndex cpp_indexer.load_index ( str  filename)
Load symbols index from the given file.

If index is out of date or missing it will be generated.

Definition at line 272 of file cpp_indexer.py.

272def load_index(filename: str) -> SymbolsIndex:
273 """Load symbols index from the given file.
274
275 If index is out of date or missing it will be generated.
276 """
277 index: SymbolsIndex
278
279 if os.path.exists(filename):
280 with open(filename, 'r', encoding='utf-8') as json_file:
281 index = _SymbolsIndexSchema.loads(json_file.read())
282 if _get_current_commit_hash() == index.commit:
283 logging.info('Loaded symbols index from %s', filename)
284 return index
285 logging.warning(
286 '%s is generated for commit %s while current commit is %s',
287 filename, index.commit, _get_current_commit_hash())
288
289 index = _index_source()
290 with open(filename, 'w', encoding='utf-8') as json_file:
291 json_file.write(_SymbolsIndexSchema.dumps(index))
292 logging.info(
293 'Successfully indexed C++ source and written symbols index into %s',
294 filename)
295 return index

Variable Documentation

◆ _clang_include_dir

cpp_indexer._clang_include_dir = None
protected

Definition at line 25 of file cpp_indexer.py.

◆ _DART_BUILD_DIR

tuple cpp_indexer._DART_BUILD_DIR
protected
Initial value:
1= ('xcodebuild' if platform.system() == 'Darwin' else
2 'out') + '/' + _DART_CONFIGURATION

Definition at line 43 of file cpp_indexer.py.

◆ _DART_CONFIGURATION

str cpp_indexer._DART_CONFIGURATION
protected
Initial value:
1= 'Release' + (
2 'ARM64' if platform.uname().machine == 'arm64' else 'X64')

Definition at line 41 of file cpp_indexer.py.

◆ _libclang_path

str cpp_indexer._libclang_path = None
protected

Definition at line 24 of file cpp_indexer.py.

◆ _path_to_llvm

cpp_indexer._path_to_llvm
protected
Initial value:
1= subprocess.check_output(['brew', '--prefix', 'llvm'],
2 encoding='utf-8').strip()

Definition at line 27 of file cpp_indexer.py.

◆ _SymbolsIndexSchema

cpp_indexer._SymbolsIndexSchema = class_schema(SymbolsIndex)()
protected

Definition at line 269 of file cpp_indexer.py.