diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2025-03-12 18:02:46 -0400 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-03-14 12:58:28 -0700 |
| commit | a6af244442a2f3b80e8fb2ccb1649eb09cf25541 (patch) | |
| tree | c6d32228a311d7109a7e1eedaa0152d9fc6bf2f6 | |
| parent | 7679c164dc357650a15643b3c0a5d89ac7a90e89 (diff) | |
| download | meson-a6af244442a2f3b80e8fb2ccb1649eb09cf25541.tar.gz | |
Move options loading to InterpreterBase
| -rw-r--r-- | mesonbuild/ast/introspection.py | 11 | ||||
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 31 | ||||
| -rw-r--r-- | mesonbuild/interpreterbase/interpreterbase.py | 34 |
3 files changed, 37 insertions, 39 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index 9e00c8d25..0d6470adc 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -10,7 +10,7 @@ import copy import os import typing as T -from .. import compilers, environment, mesonlib, optinterpreter, options +from .. import compilers, environment, mesonlib, options from .. import coredata as cdata from ..build import Executable, Jar, SharedLibrary, SharedModule, StaticLibrary from ..compilers import detect_compiler_for @@ -112,14 +112,7 @@ class IntrospectionInterpreter(AstInterpreter): proj_license_files = _str_list(kwargs.get('license_files', None)) or [] self.project_data = {'descriptive_name': proj_name, 'version': proj_vers, 'license': proj_license, 'license_files': proj_license_files} - optfile = os.path.join(self.source_root, self.subdir, 'meson.options') - if not os.path.exists(optfile): - optfile = os.path.join(self.source_root, self.subdir, 'meson_options.txt') - if os.path.exists(optfile): - oi = optinterpreter.OptionInterpreter(self.coredata.optstore, self.subproject) - oi.process(optfile) - assert isinstance(proj_name, str), 'for mypy' - self.coredata.update_project_options(oi.options, T.cast('SubProject', proj_name)) + self._load_option_file() def_opts = self.flatten_args(kwargs.get('default_options', [])) _project_default_options = mesonlib.stringlistify(def_opts) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 1247dfe3b..e4183bf87 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -4,7 +4,7 @@ from __future__ import annotations -import hashlib, io, sys, traceback +import io, sys, traceback from .. import mparser from .. import environment @@ -13,7 +13,6 @@ from .. import dependencies from .. import mlog from .. import options from .. import build -from .. import optinterpreter from .. import compilers from .. import envconfig from ..wrap import wrap, WrapMode @@ -1181,33 +1180,7 @@ class Interpreter(InterpreterBase, HoldableObject): else: mesonlib.project_meson_versions[self.subproject] = mesonlib.NoProjectVersion() - # Load "meson.options" before "meson_options.txt", and produce a warning if - # it is being used with an old version. I have added check that if both - # exist the warning isn't raised - option_file = os.path.join(self.source_root, self.subdir, 'meson.options') - old_option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt') - - if os.path.exists(option_file): - if os.path.exists(old_option_file): - if os.path.samefile(option_file, old_option_file): - mlog.debug("Not warning about meson.options with version minimum < 1.1 because meson_options.txt also exists") - else: - raise MesonException("meson.options and meson_options.txt both exist, but are not the same file.") - else: - FeatureNew.single_use('meson.options file', '1.1', self.subproject, 'Use meson_options.txt instead') - else: - option_file = old_option_file - if os.path.exists(option_file): - with open(option_file, 'rb') as f: - # We want fast not cryptographically secure, this is just to - # see if the option file has changed - self.coredata.options_files[self.subproject] = (option_file, hashlib.sha1(f.read()).hexdigest()) - oi = optinterpreter.OptionInterpreter(self.environment.coredata.optstore, self.subproject) - oi.process(option_file) - self.coredata.update_project_options(oi.options, self.subproject) - self.add_build_def_file(option_file) - else: - self.coredata.options_files[self.subproject] = None + self._load_option_file() self.project_default_options = kwargs['default_options'] if isinstance(self.project_default_options, str): diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 2dcb81b0f..53d62c385 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -27,13 +27,14 @@ from .exceptions import ( SubdirDoneRequest, ) +from .. import mlog from .decorators import FeatureNew from .disabler import Disabler, is_disabled from .helpers import default_resolve_key, flatten, resolve_second_level_holders, stringifyUserArguments from .operator import MesonOperator from ._unholder import _unholder -import os, copy, re, pathlib +import os, copy, hashlib, re, pathlib import typing as T import textwrap @@ -675,6 +676,37 @@ class InterpreterBase: def validate_extraction(self, buildtarget: mesonlib.HoldableObject) -> None: raise InterpreterException('validate_extraction is not implemented in this context (please file a bug)') + def _load_option_file(self) -> None: + from .. import optinterpreter # prevent circular import + + # Load "meson.options" before "meson_options.txt", and produce a warning if + # it is being used with an old version. I have added check that if both + # exist the warning isn't raised + option_file = os.path.join(self.source_root, self.subdir, 'meson.options') + old_option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt') + + if os.path.exists(option_file): + if os.path.exists(old_option_file): + if os.path.samefile(option_file, old_option_file): + mlog.debug("Not warning about meson.options with version minimum < 1.1 because meson_options.txt also exists") + else: + raise mesonlib.MesonException("meson.options and meson_options.txt both exist, but are not the same file.") + else: + FeatureNew.single_use('meson.options file', '1.1', self.subproject, 'Use meson_options.txt instead') + else: + option_file = old_option_file + if os.path.exists(option_file): + with open(option_file, 'rb') as f: + # We want fast not cryptographically secure, this is just to + # see if the option file has changed + self.coredata.options_files[self.subproject] = (option_file, hashlib.sha1(f.read()).hexdigest()) + oi = optinterpreter.OptionInterpreter(self.environment.coredata.optstore, self.subproject) + oi.process(option_file) + self.coredata.update_project_options(oi.options, self.subproject) + self.build_def_files.add(option_file) + else: + self.coredata.options_files[self.subproject] = None + def _resolve_subdir(self, rootdir: str, new_subdir: str) -> T.Tuple[str, bool]: subdir = os.path.join(self.subdir, new_subdir) absdir = os.path.join(rootdir, subdir) |
