msubprojects: Speedup subproject_dir extraction

The interpreter takes significant amount of time to initialize
everything in project() function. We only need to extract a string from
AST, just like we do in handle_meson_version_from_ast().
1.2
Xavier Claessens 1 year ago committed by Nirbheek Chauhan
parent de1ba4eb8c
commit ca42c7029f
  1. 19
      mesonbuild/ast/introspection.py
  2. 8
      mesonbuild/msubprojects.py

@ -362,3 +362,22 @@ class IntrospectionInterpreter(AstInterpreter):
self.sanity_check_ast()
self.parse_project()
self.run()
def extract_subproject_dir(self) -> T.Optional[str]:
'''Fast path to extract subproject_dir kwarg.
This is faster than self.parse_project() which also initialize options
and also calls parse_project() on every subproject.
'''
if not self.ast.lines:
return
project = self.ast.lines[0]
# first line is always project()
if not isinstance(project, FunctionNode):
return
for kw, val in project.args.kwargs.items():
assert isinstance(kw, IdNode), 'for mypy'
if kw.value == 'subproject_dir':
# mypy does not understand "and isinstance"
if isinstance(val, StringNode):
return val.value
return None

@ -14,7 +14,7 @@ import tarfile
import zipfile
from . import mlog
from .ast import IntrospectionInterpreter, AstIDGenerator
from .ast import IntrospectionInterpreter
from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree
from .wrap.wrap import (Resolver, WrapException, ALL_TYPES, PackageDefinition,
parse_patch_url, update_wrap_file, get_releases)
@ -691,11 +691,9 @@ def run(options: 'Arguments') -> int:
mlog.error('Directory', mlog.bold(source_dir), 'does not seem to be a Meson source directory.')
return 1
with mlog.no_logging():
intr = IntrospectionInterpreter(source_dir, '', 'none', visitors = [AstIDGenerator()])
intr = IntrospectionInterpreter(source_dir, '', 'none')
intr.load_root_meson_file()
intr.sanity_check_ast()
intr.parse_project()
subproject_dir = intr.subproject_dir
subproject_dir = intr.extract_subproject_dir() or 'subprojects'
if not os.path.isdir(os.path.join(source_dir, subproject_dir)):
mlog.log('Directory', mlog.bold(source_dir), 'does not seem to have subprojects.')
return 0

Loading…
Cancel
Save