diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2025-03-12 17:35:53 -0400 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-03-14 12:58:28 -0700 |
| commit | 7679c164dc357650a15643b3c0a5d89ac7a90e89 (patch) | |
| tree | 14cbedb981339876932df3c55bbf5d498f63ef78 | |
| parent | e65c879925219685cbcbb9a8367006b8c687167e (diff) | |
| download | meson-7679c164dc357650a15643b3c0a5d89ac7a90e89.tar.gz | |
Move variables to InterpreterBase
subproject_dir, environment, and coredata
| -rw-r--r-- | mesonbuild/ast/interpreter.py | 4 | ||||
| -rw-r--r-- | mesonbuild/ast/introspection.py | 11 | ||||
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 5 | ||||
| -rw-r--r-- | mesonbuild/interpreterbase/interpreterbase.py | 7 | ||||
| -rw-r--r-- | unittests/datatests.py | 2 |
5 files changed, 12 insertions, 17 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index 878fb34ed..cd8156a3f 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -86,8 +86,8 @@ _V = T.TypeVar('_V') class AstInterpreter(InterpreterBase): - def __init__(self, source_root: str, subdir: str, subproject: SubProject, visitors: T.Optional[T.List[AstVisitor]] = None): - super().__init__(source_root, subdir, subproject) + def __init__(self, source_root: str, subdir: str, subproject: SubProject, subproject_dir: str, env: environment.Environment, visitors: T.Optional[T.List[AstVisitor]] = None): + super().__init__(source_root, subdir, subproject, subproject_dir, env) self.visitors = visitors if visitors is not None else [] self.assignments: T.Dict[str, BaseNode] = {} self.assign_vals: T.Dict[str, T.Any] = {} diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index a5b70eca0..9e00c8d25 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -55,16 +55,11 @@ class IntrospectionInterpreter(AstInterpreter): subproject: SubProject = SubProject(''), subproject_dir: str = 'subprojects', env: T.Optional[environment.Environment] = None): - super().__init__(source_root, subdir, subproject, visitors=visitors) - options = IntrospectionHelper(cross_file) + env_ = env or environment.Environment(source_root, None, options) + super().__init__(source_root, subdir, subproject, subproject_dir, env_, visitors=visitors) + self.cross_file = cross_file - if env is None: - self.environment = environment.Environment(source_root, None, options) - else: - self.environment = env - self.subproject_dir = subproject_dir - self.coredata = self.environment.get_coredata() self.backend = backend self.default_options = {OptionKey('backend'): self.backend} self.project_data: T.Dict[str, T.Any] = {} diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 1b378e304..1247dfe3b 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -274,15 +274,12 @@ class Interpreter(InterpreterBase, HoldableObject): relaxations: T.Optional[T.Set[InterpreterRuleRelaxation]] = None, user_defined_options: T.Optional[coredata.SharedCMDOptions] = None, ) -> None: - super().__init__(_build.environment.get_source_dir(), subdir, subproject) + super().__init__(_build.environment.get_source_dir(), subdir, subproject, subproject_dir, _build.environment) self.active_projectname = '' self.build = _build - self.environment = self.build.environment - self.coredata = self.environment.get_coredata() self.backend = backend self.summary: T.Dict[str, 'Summary'] = {} self.modules: T.Dict[str, NewExtensionModule] = {} - self.subproject_dir = subproject_dir self.relaxations = relaxations or set() if ast is None: self.load_root_meson_file() diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index e94ba70dc..2dcb81b0f 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -68,7 +68,7 @@ class InvalidCodeOnVoid(InvalidCode): class InterpreterBase: - def __init__(self, source_root: str, subdir: str, subproject: 'SubProject'): + def __init__(self, source_root: str, subdir: str, subproject: SubProject, subproject_dir: str, env: environment.Environment): self.source_root = source_root self.funcs: FunctionType = {} self.builtin: T.Dict[str, InterpreterObject] = {} @@ -80,6 +80,9 @@ class InterpreterBase: self.subdir = subdir self.root_subdir = subdir self.subproject = subproject + self.subproject_dir = subproject_dir + self.environment = env + self.coredata = env.get_coredata() self.variables: T.Dict[str, InterpreterObject] = {} self.argument_depth = 0 self.current_lineno = -1 @@ -685,7 +688,7 @@ class InterpreterBase: def _evaluate_subdir(self, rootdir: str, subdir: str, visitors: T.Optional[T.Iterable[AstVisitor]] = None) -> bool: buildfilename = os.path.join(subdir, environment.build_filename) self.build_def_files.add(buildfilename) - + absname = os.path.join(rootdir, buildfilename) if not os.path.isfile(absname): return False diff --git a/unittests/datatests.py b/unittests/datatests.py index 173f718ea..bd83b81f8 100644 --- a/unittests/datatests.py +++ b/unittests/datatests.py @@ -246,5 +246,5 @@ class DataTests(unittest.TestCase): del os.environ['MESON_RUNNING_IN_PROJECT_TESTS'] env = get_fake_env() interp = Interpreter(FakeBuild(env)) - astint = AstInterpreter('.', '', '') + astint = AstInterpreter('.', '', '', '', env) self.assertEqual(set(interp.funcs.keys()), set(astint.funcs.keys())) |
