aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-08-31 15:25:31 -0400
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2023-09-12 17:32:17 +0530
commit1b6c9ad02ab88d92fd055ccc1307456105c064fe (patch)
tree932a1a777a94131ec2c4273d3aa1453a57edbbe4
parent57178e8ae7f6fc7bc898e55fed1a18d32d25c2ce (diff)
downloadmeson-1b6c9ad02ab88d92fd055ccc1307456105c064fe.zip
meson-1b6c9ad02ab88d92fd055ccc1307456105c064fe.tar.gz
meson-1b6c9ad02ab88d92fd055ccc1307456105c064fe.tar.bz2
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().
-rw-r--r--mesonbuild/ast/introspection.py19
-rwxr-xr-xmesonbuild/msubprojects.py8
2 files changed, 22 insertions, 5 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index e8055c5..987e355 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.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
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index d1b51f0..64a09b0 100755
--- a/mesonbuild/msubprojects.py
+++ b/mesonbuild/msubprojects.py
@@ -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,
parse_patch_url, update_wrap_file, get_releases)
@@ -693,11 +693,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