diff --git a/.mypy.ini b/.mypy.ini index 2ee1e5973..70fdcd9f3 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -3,6 +3,7 @@ strict_optional = False show_error_context = False show_column_numbers = True ignore_missing_imports = True +implicit_reexport = False follow_imports = silent warn_redundant_casts = True diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 73741a441..e18906cca 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -202,7 +202,7 @@ class TestSerialisation: needs_exe_wrapper: bool is_parallel: bool cmd_args: T.List[str] - env: build.EnvironmentVariables + env: mesonlib.EnvironmentVariables should_fail: bool timeout: T.Optional[int] workdir: T.Optional[str] @@ -512,7 +512,7 @@ class Backend: extra_bdeps: T.Optional[T.List[build.BuildTarget]] = None, capture: T.Optional[bool] = None, feed: T.Optional[bool] = None, - env: T.Optional[build.EnvironmentVariables] = None, + env: T.Optional[mesonlib.EnvironmentVariables] = None, tag: T.Optional[str] = None, verbose: bool = False, installdir_map: T.Optional[T.Dict[str, str]] = None) -> 'ExecutableSerialisation': @@ -585,7 +585,7 @@ class Backend: capture: T.Optional[bool] = None, feed: T.Optional[bool] = None, force_serialize: bool = False, - env: T.Optional[build.EnvironmentVariables] = None, + env: T.Optional[mesonlib.EnvironmentVariables] = None, verbose: bool = False) -> T.Tuple[T.Sequence[T.Union[str, File, build.Target, programs.ExternalProgram]], str]: ''' Serialize an executable for running with a generator or a custom target @@ -1588,8 +1588,8 @@ class Backend: cmd = [i.replace('\\', '/') for i in cmd] return inputs, outputs, cmd - def get_run_target_env(self, target: build.RunTarget) -> build.EnvironmentVariables: - env = target.env if target.env else build.EnvironmentVariables() + def get_run_target_env(self, target: build.RunTarget) -> mesonlib.EnvironmentVariables: + env = target.env if target.env else mesonlib.EnvironmentVariables() if target.default_env: introspect_cmd = join_args(self.environment.get_build_command() + ['introspect']) env.set('MESON_SOURCE_ROOT', [self.environment.get_source_dir()]) @@ -1959,8 +1959,8 @@ class Backend: return [] - def get_devenv(self) -> build.EnvironmentVariables: - env = build.EnvironmentVariables() + def get_devenv(self) -> mesonlib.EnvironmentVariables: + env = mesonlib.EnvironmentVariables() extra_paths = set() library_paths = set() build_machine = self.environment.machines[MachineChoice.BUILD] diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0a4160fb1..d588c9db8 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -39,7 +39,7 @@ from .mesonlib import ( MesonBugException, EnvironmentVariables, pickle_load, ) from .compilers import ( - is_object, clink_langs, sort_clink, all_languages, + is_header, is_object, is_source, clink_langs, sort_clink, all_languages, is_known_suffix, detect_static_linker ) from .interpreterbase import FeatureNew, FeatureDeprecated @@ -47,12 +47,13 @@ from .interpreterbase import FeatureNew, FeatureDeprecated if T.TYPE_CHECKING: from typing_extensions import Literal from ._typing import ImmutableListProtocol - from .backend.backends import Backend, ExecutableSerialisation + from .backend.backends import Backend from .compilers import Compiler - from .interpreter.interpreter import Test, SourceOutputs, Interpreter + from .interpreter.interpreter import SourceOutputs, Interpreter + from .interpreter.interpreterobjects import Test from .interpreterbase import SubProject from .linkers.linkers import StaticLinker - from .mesonlib import FileMode, FileOrString + from .mesonlib import ExecutableSerialisation, FileMode, FileOrString from .modules import ModuleState from .mparser import BaseNode from .wrap import WrapMode @@ -434,7 +435,7 @@ class ExtractedObjects(HoldableObject): sources.append(s) # Filter out headers and all non-source files - return [s for s in sources if environment.is_source(s)] + return [s for s in sources if is_source(s)] def classify_all_sources(self, sources: T.List[FileOrString], generated_sources: T.Sequence['GeneratedTypes']) -> T.Dict['Compiler', T.List['FileOrString']]: sources_ = self.get_sources(sources, generated_sources) @@ -1494,14 +1495,14 @@ You probably should put it in link_with instead.''') if not pchlist: return elif len(pchlist) == 1: - if not environment.is_header(pchlist[0]): + if not is_header(pchlist[0]): raise InvalidArguments(f'PCH argument {pchlist[0]} is not a header.') elif len(pchlist) == 2: - if environment.is_header(pchlist[0]): - if not environment.is_source(pchlist[1]): + if is_header(pchlist[0]): + if not is_source(pchlist[1]): raise InvalidArguments('PCH definition must contain one header and at most one source.') - elif environment.is_source(pchlist[0]): - if not environment.is_header(pchlist[1]): + elif is_source(pchlist[0]): + if not is_header(pchlist[1]): raise InvalidArguments('PCH definition must contain one header and at most one source.') pchlist = [pchlist[1], pchlist[0]] else: diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index da361856c..251a7bf67 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -36,8 +36,7 @@ from ... import arglist from ... import mesonlib from ... import mlog from ...linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker -from ...mesonlib import LibType -from ...coredata import OptionKey +from ...mesonlib import LibType, OptionKey from .. import compilers from ..compilers import CompileCheckMode from .visualstudio import VisualStudioLikeCompiler diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index c6af04a27..ded158e81 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -17,9 +17,8 @@ import os.path import typing as T from .. import mlog -from ..mesonlib import EnvironmentException, version_compare, OptionKey - -from .compilers import CompileCheckMode, Compiler, LibType +from ..mesonlib import EnvironmentException, version_compare, LibType, OptionKey +from .compilers import CompileCheckMode, Compiler if T.TYPE_CHECKING: from ..envconfig import MachineInfo diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 0e4dab9a5..0a936e65e 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -28,7 +28,8 @@ from .pkgconfig import PkgConfigDependency from .misc import threads_factory if T.TYPE_CHECKING: - from ..environment import Environment, Properties + from ..envconfig import Properties + from ..environment import Environment # On windows 3 directory layouts are supported: # * The default layout (versioned) installed: diff --git a/mesonbuild/dependencies/coarrays.py b/mesonbuild/dependencies/coarrays.py index 5cb855614..1c59792e6 100644 --- a/mesonbuild/dependencies/coarrays.py +++ b/mesonbuild/dependencies/coarrays.py @@ -24,7 +24,8 @@ from .factory import factory_methods if T.TYPE_CHECKING: from . factory import DependencyGenerator - from ..environment import Environment, MachineChoice + from ..environment import Environment + from ..mesonlib import MachineChoice @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE, DependencyMethods.SYSTEM}) diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index d77566961..1a5502f69 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -30,13 +30,13 @@ from .factory import DependencyFactory, factory_methods from .pkgconfig import PkgConfigDependency if T.TYPE_CHECKING: - from ..environment import Environment, MachineChoice + from ..environment import Environment from .factory import DependencyGenerator @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE}) def netcdf_factory(env: 'Environment', - for_machine: 'MachineChoice', + for_machine: 'mesonlib.MachineChoice', kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']: language = kwargs.get('language', 'c') @@ -475,7 +475,7 @@ class OpensslSystemDependency(SystemDependency): @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM}) def curses_factory(env: 'Environment', - for_machine: 'MachineChoice', + for_machine: 'mesonlib.MachineChoice', kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']: candidates: T.List['DependencyGenerator'] = [] @@ -501,7 +501,7 @@ packages['curses'] = curses_factory @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM}) def shaderc_factory(env: 'Environment', - for_machine: 'MachineChoice', + for_machine: 'mesonlib.MachineChoice', kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']: """Custom DependencyFactory for ShaderC. diff --git a/mesonbuild/dependencies/mpi.py b/mesonbuild/dependencies/mpi.py index 910068143..240e6fd95 100644 --- a/mesonbuild/dependencies/mpi.py +++ b/mesonbuild/dependencies/mpi.py @@ -27,7 +27,8 @@ from .pkgconfig import PkgConfigDependency if T.TYPE_CHECKING: from .factory import DependencyGenerator - from ..environment import Environment, MachineChoice + from ..environment import Environment + from ..mesonlib import MachineChoice @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM}) diff --git a/mesonbuild/dependencies/pkgconfig.py b/mesonbuild/dependencies/pkgconfig.py index 0c40847c9..37f2ecb1c 100644 --- a/mesonbuild/dependencies/pkgconfig.py +++ b/mesonbuild/dependencies/pkgconfig.py @@ -16,7 +16,7 @@ from __future__ import annotations from pathlib import Path from .base import ExternalDependency, DependencyException, sort_libpaths, DependencyTypeName -from ..mesonlib import OptionKey, OrderedSet, PerMachine, Popen_safe, Popen_safe_logged +from ..mesonlib import EnvironmentVariables, OptionKey, OrderedSet, PerMachine, Popen_safe, Popen_safe_logged from ..programs import find_external_program, ExternalProgram from .. import mlog from pathlib import PurePath @@ -30,7 +30,6 @@ if T.TYPE_CHECKING: from ..mesonlib import MachineChoice from ..utils.core import EnvironOrDict from .._typing import ImmutableListProtocol - from ..build import EnvironmentVariables class PkgConfigDependency(ExternalDependency): # The class's copy of the pkg-config path. Avoids having to search for it @@ -128,7 +127,6 @@ class PkgConfigDependency(ExternalDependency): @staticmethod def get_env(environment: 'Environment', for_machine: MachineChoice, uninstalled: bool = False) -> 'EnvironmentVariables': - from ..build import EnvironmentVariables env = EnvironmentVariables() key = OptionKey('pkg_config_path', machine=for_machine) extra_paths: T.List[str] = environment.coredata.options[key].value[:] diff --git a/mesonbuild/dependencies/scalapack.py b/mesonbuild/dependencies/scalapack.py index 257e4aaaa..2442ede41 100644 --- a/mesonbuild/dependencies/scalapack.py +++ b/mesonbuild/dependencies/scalapack.py @@ -27,7 +27,8 @@ from .pkgconfig import PkgConfigDependency from .factory import factory_methods if T.TYPE_CHECKING: - from ..environment import Environment, MachineChoice + from ..environment import Environment + from ..mesonlib import MachineChoice from .factory import DependencyGenerator diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 363de547f..efca123ab 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -23,7 +23,7 @@ from .. import compilers from .. import envconfig from ..wrap import wrap, WrapMode from .. import mesonlib -from ..mesonlib import (MesonBugException, MesonException, HoldableObject, +from ..mesonlib import (EnvironmentVariables, ExecutableSerialisation, MesonBugException, MesonException, HoldableObject, FileMode, MachineChoice, OptionKey, listify, extract_as_list, has_path_sep, PerMachine) from ..programs import ExternalProgram, NonExistingExternalProgram @@ -36,7 +36,6 @@ from ..interpreterbase import Disabler, disablerIfNotFound from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureBroken, FeatureNewKwargs, FeatureDeprecatedKwargs from ..interpreterbase import ObjectHolder, ContextManagerObject from ..modules import ExtensionModule, ModuleObject, MutableModuleObject, NewExtensionModule, NotFoundExtensionModule -from ..backend.backends import ExecutableSerialisation from . import interpreterobjects as OBJ from . import compiler as compilerOBJ @@ -458,7 +457,7 @@ class Interpreter(InterpreterBase, HoldableObject): build.SymlinkData: OBJ.SymlinkDataHolder, build.InstallDir: OBJ.InstallDirHolder, build.IncludeDirs: OBJ.IncludeDirsHolder, - build.EnvironmentVariables: OBJ.EnvironmentVariablesHolder, + mesonlib.EnvironmentVariables: OBJ.EnvironmentVariablesHolder, build.StructuredSources: OBJ.StructuredSourcesHolder, compilers.RunResult: compilerOBJ.TryRunResultHolder, dependencies.ExternalLibrary: OBJ.ExternalLibraryHolder, @@ -2166,10 +2165,10 @@ class Interpreter(InterpreterBase, HoldableObject): kwargs: 'kwtypes.FuncTest') -> None: self.add_test(node, args, kwargs, True) - def unpack_env_kwarg(self, kwargs: T.Union[build.EnvironmentVariables, T.Dict[str, 'TYPE_var'], T.List['TYPE_var'], str]) -> build.EnvironmentVariables: + def unpack_env_kwarg(self, kwargs: T.Union[EnvironmentVariables, T.Dict[str, 'TYPE_var'], T.List['TYPE_var'], str]) -> EnvironmentVariables: envlist = kwargs.get('env') if envlist is None: - return build.EnvironmentVariables() + return EnvironmentVariables() msg = ENV_KW.validator(envlist) if msg: raise InvalidArguments(f'"env": {msg}') @@ -2687,7 +2686,7 @@ class Interpreter(InterpreterBase, HoldableObject): mlog.log('Configuring', mlog.bold(output), 'with command') cmd, *args = _cmd res = self.run_command_impl(node, (cmd, args), - {'capture': True, 'check': True, 'env': build.EnvironmentVariables()}, + {'capture': True, 'check': True, 'env': EnvironmentVariables()}, True) if kwargs['capture']: dst_tmp = ofile_abs + '~' @@ -2967,7 +2966,7 @@ class Interpreter(InterpreterBase, HoldableObject): @typed_pos_args('environment', optargs=[(str, list, dict)]) @typed_kwargs('environment', ENV_METHOD_KW, ENV_SEPARATOR_KW.evolve(since='0.62.0')) def func_environment(self, node: mparser.FunctionNode, args: T.Tuple[T.Union[None, str, T.List['TYPE_var'], T.Dict[str, 'TYPE_var']]], - kwargs: 'TYPE_kwargs') -> build.EnvironmentVariables: + kwargs: 'TYPE_kwargs') -> EnvironmentVariables: init = args[0] if init is not None: FeatureNew.single_use('environment positional arguments', '0.52.0', self.subproject, location=node) @@ -2977,7 +2976,7 @@ class Interpreter(InterpreterBase, HoldableObject): if isinstance(init, dict) and any(i for i in init.values() if isinstance(i, list)): FeatureNew.single_use('List of string in dictionary value', '0.62.0', self.subproject, location=node) return env_convertor_with_method(init, kwargs['method'], kwargs['separator']) - return build.EnvironmentVariables() + return EnvironmentVariables() @typed_pos_args('join_paths', varargs=str, min_varargs=1) @noKwargs diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index fac3b0e55..8648b487f 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -203,7 +203,7 @@ class RunProcess(MesonInterpreterObject): def __init__(self, cmd: ExternalProgram, args: T.List[str], - env: build.EnvironmentVariables, + env: mesonlib.EnvironmentVariables, source_dir: str, build_dir: str, subdir: str, @@ -224,7 +224,7 @@ class RunProcess(MesonInterpreterObject): def run_command(self, cmd: ExternalProgram, args: T.List[str], - env: build.EnvironmentVariables, + env: mesonlib.EnvironmentVariables, source_dir: str, build_dir: str, subdir: str, @@ -280,9 +280,9 @@ class RunProcess(MesonInterpreterObject): def stderr_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: return self.stderr -class EnvironmentVariablesHolder(ObjectHolder[build.EnvironmentVariables], MutableInterpreterObject): +class EnvironmentVariablesHolder(ObjectHolder[mesonlib.EnvironmentVariables], MutableInterpreterObject): - def __init__(self, obj: build.EnvironmentVariables, interpreter: 'Interpreter'): + def __init__(self, obj: mesonlib.EnvironmentVariables, interpreter: 'Interpreter'): super().__init__(obj, interpreter) self.methods.update({'set': self.set_method, 'append': self.append_method, @@ -711,7 +711,7 @@ class Test(MesonInterpreterObject): depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]], is_parallel: bool, cmd_args: T.List[T.Union[str, mesonlib.File, build.Target]], - env: build.EnvironmentVariables, + env: mesonlib.EnvironmentVariables, should_fail: bool, timeout: int, workdir: T.Optional[str], protocol: str, priority: int, verbose: bool): super().__init__() diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index cf476cefb..cc48e7ab1 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -12,7 +12,7 @@ from typing_extensions import TypedDict, Literal, Protocol from .. import build from .. import coredata from ..compilers import Compiler -from ..mesonlib import MachineChoice, File, FileMode, FileOrString, OptionKey +from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString, OptionKey from ..modules.cmake import CMakeSubprojectOptions from ..programs import ExternalProgram @@ -42,7 +42,7 @@ class BaseTest(TypedDict): workdir: T.Optional[str] depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]] priority: int - env: build.EnvironmentVariables + env: EnvironmentVariables suite: T.List[str] @@ -164,7 +164,7 @@ class RunTarget(TypedDict): command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, ExternalProgram, File]] depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]] - env: build.EnvironmentVariables + env: EnvironmentVariables class CustomTarget(TypedDict): @@ -179,7 +179,7 @@ class CustomTarget(TypedDict): depend_files: T.List[FileOrString] depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]] depfile: T.Optional[str] - env: build.EnvironmentVariables + env: EnvironmentVariables feed: bool input: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, build.ExtractedObjects, build.GeneratedList, ExternalProgram, File]] @@ -196,7 +196,7 @@ class AddTestSetup(TypedDict): timeout_multiplier: int is_default: bool exclude_suites: T.List[str] - env: build.EnvironmentVariables + env: EnvironmentVariables class Project(TypedDict): @@ -240,7 +240,7 @@ class RunCommand(TypedDict): check: bool capture: T.Optional[bool] - env: build.EnvironmentVariables + env: EnvironmentVariables class FeatureOptionRequire(TypedDict): diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index 73df5edd1..66029a019 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -21,14 +21,13 @@ from .primitives import MesonVersionString from .type_checking import NATIVE_KW, NoneType if T.TYPE_CHECKING: - from typing_extensions import Literal - from ..backend.backends import ExecutableSerialisation + from typing_extensions import Literal, TypedDict + from ..compilers import Compiler from ..interpreterbase import TYPE_kwargs, TYPE_var + from ..mesonlib import ExecutableSerialisation from .interpreter import Interpreter - from typing_extensions import TypedDict - class FuncOverrideDependency(TypedDict): native: mesonlib.MachineChoice @@ -456,15 +455,15 @@ class MesonMain(MesonInterpreterObject): @FeatureNew('add_devenv', '0.58.0') @typed_kwargs('environment', ENV_METHOD_KW, ENV_SEPARATOR_KW.evolve(since='0.62.0')) - @typed_pos_args('add_devenv', (str, list, dict, build.EnvironmentVariables)) - def add_devenv_method(self, args: T.Tuple[T.Union[str, list, dict, build.EnvironmentVariables]], + @typed_pos_args('add_devenv', (str, list, dict, mesonlib.EnvironmentVariables)) + def add_devenv_method(self, args: T.Tuple[T.Union[str, list, dict, mesonlib.EnvironmentVariables]], kwargs: 'AddDevenvKW') -> None: env = args[0] msg = ENV_KW.validator(env) if msg: raise build.InvalidArguments(f'"add_devenv": {msg}') converted = env_convertor_with_method(env, kwargs['method'], kwargs['separator']) - assert isinstance(converted, build.EnvironmentVariables) + assert isinstance(converted, mesonlib.EnvironmentVariables) self.build.devenv.append(converted) @noPosargs diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 64e02c270..10683fdbf 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -29,8 +29,7 @@ if T.TYPE_CHECKING: from typing_extensions import Protocol from .. import mparser - from .baseobjects import InterpreterObject, TV_func, TYPE_var, TYPE_kwargs - from .interpreterbase import SubProject + from .baseobjects import InterpreterObject, SubProject, TV_func, TYPE_var, TYPE_kwargs from .operator import MesonOperator _TV_IntegerObject = T.TypeVar('_TV_IntegerObject', bound=InterpreterObject, contravariant=True) diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 5f854d0fa..d039f6dfb 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -36,7 +36,6 @@ from .exceptions import ( InterpreterException, InvalidArguments, InvalidCode, - MesonException, SubdirDoneRequest, ) @@ -319,12 +318,12 @@ class InterpreterBase: def evaluate_comparison(self, node: mparser.ComparisonNode) -> InterpreterObject: val1 = self.evaluate_statement(node.left) if val1 is None: - raise MesonException('Cannot compare a void statement on the left-hand side') + raise mesonlib.MesonException('Cannot compare a void statement on the left-hand side') if isinstance(val1, Disabler): return val1 val2 = self.evaluate_statement(node.right) if val2 is None: - raise MesonException('Cannot compare a void statement on the right-hand side') + raise mesonlib.MesonException('Cannot compare a void statement on the right-hand side') if isinstance(val2, Disabler): return val2 @@ -350,7 +349,7 @@ class InterpreterBase: def evaluate_andstatement(self, cur: mparser.AndNode) -> InterpreterObject: l = self.evaluate_statement(cur.left) if l is None: - raise MesonException('Cannot compare a void statement on the left-hand side') + raise mesonlib.MesonException('Cannot compare a void statement on the left-hand side') if isinstance(l, Disabler): return l l_bool = l.operator_call(MesonOperator.BOOL, None) @@ -358,7 +357,7 @@ class InterpreterBase: return self._holderify(l_bool) r = self.evaluate_statement(cur.right) if r is None: - raise MesonException('Cannot compare a void statement on the right-hand side') + raise mesonlib.MesonException('Cannot compare a void statement on the right-hand side') if isinstance(r, Disabler): return r return self._holderify(r.operator_call(MesonOperator.BOOL, None)) @@ -366,7 +365,7 @@ class InterpreterBase: def evaluate_orstatement(self, cur: mparser.OrNode) -> InterpreterObject: l = self.evaluate_statement(cur.left) if l is None: - raise MesonException('Cannot compare a void statement on the left-hand side') + raise mesonlib.MesonException('Cannot compare a void statement on the left-hand side') if isinstance(l, Disabler): return l l_bool = l.operator_call(MesonOperator.BOOL, None) @@ -374,7 +373,7 @@ class InterpreterBase: return self._holderify(l_bool) r = self.evaluate_statement(cur.right) if r is None: - raise MesonException('Cannot compare a void statement on the right-hand side') + raise mesonlib.MesonException('Cannot compare a void statement on the right-hand side') if isinstance(r, Disabler): return r return self._holderify(r.operator_call(MesonOperator.BOOL, None)) @@ -413,7 +412,7 @@ class InterpreterBase: assert isinstance(node, mparser.TernaryNode) result = self.evaluate_statement(node.condition) if result is None: - raise MesonException('Cannot use a void statement as condition for ternary operator.') + raise mesonlib.MesonException('Cannot use a void statement as condition for ternary operator.') if isinstance(result, Disabler): return result result.current_node = node diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index ddd2ee2d7..d4ecce871 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -26,7 +26,7 @@ from . import environment from . import mesonlib from . import mintro from . import mlog -from .ast import AstIDGenerator +from .ast import AstIDGenerator, IntrospectionInterpreter from .mesonlib import MachineChoice, OptionKey if T.TYPE_CHECKING: @@ -81,7 +81,7 @@ class Conf: # Make sure that log entries in other parts of meson don't interfere with the JSON output with mlog.no_logging(): self.source_dir = os.path.abspath(os.path.realpath(self.build_dir)) - intr = mintro.IntrospectionInterpreter(self.source_dir, '', 'ninja', visitors = [AstIDGenerator()]) + intr = IntrospectionInterpreter(self.source_dir, '', 'ninja', visitors = [AstIDGenerator()]) intr.analyze() self.coredata = intr.coredata self.default_values_only = True diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py index 9c298478d..46b1b605d 100644 --- a/mesonbuild/mdevenv.py +++ b/mesonbuild/mdevenv.py @@ -8,7 +8,7 @@ import itertools from pathlib import Path from . import build, minstall -from .mesonlib import (MesonException, is_windows, setup_vsenv, OptionKey, +from .mesonlib import (EnvironmentVariables, MesonException, is_windows, setup_vsenv, OptionKey, get_wine_shortpath, MachineChoice) from . import mlog @@ -55,7 +55,7 @@ def reduce_winepath(env: T.Dict[str, str]) -> None: mlog.log('Meson detected wine and has set WINEPATH accordingly') def get_env(b: build.Build, dump_fmt: T.Optional[str]) -> T.Tuple[T.Dict[str, str], T.Set[str]]: - extra_env = build.EnvironmentVariables() + extra_env = EnvironmentVariables() extra_env.set('MESON_DEVENV', ['1']) extra_env.set('MESON_PROJECT_NAME', [b.project_name]) diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index 49006917e..a9c561f77 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -25,7 +25,7 @@ import sys import typing as T import re -from . import build, coredata, environment +from . import build, environment from .backend.backends import InstallData from .mesonlib import (MesonException, Popen_safe, RealPathAction, is_windows, is_aix, setup_vsenv, pickle_load, is_osx, OptionKey) @@ -40,10 +40,10 @@ except ImportError: if T.TYPE_CHECKING: from .backend.backends import ( - ExecutableSerialisation, InstallDataBase, InstallEmptyDir, + InstallDataBase, InstallEmptyDir, InstallSymlinkData, TargetInstallData ) - from .mesonlib import FileMode, EnvironOrDict + from .mesonlib import FileMode, EnvironOrDict, ExecutableSerialisation try: from typing import Protocol @@ -847,7 +847,7 @@ def run(opts: 'ArgumentType') -> int: b = build.load(opts.wd) need_vsenv = T.cast('bool', b.environment.coredata.get_option(OptionKey('vsenv'))) setup_vsenv(need_vsenv) - backend = T.cast('str', b.environment.coredata.get_option(coredata.OptionKey('backend'))) + backend = T.cast('str', b.environment.coredata.get_option(OptionKey('backend'))) if not rebuild_all(opts.wd, backend): sys.exit(-1) os.chdir(opts.wd) diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index ab303b3f5..1d1e858ac 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -444,7 +444,7 @@ def get_test_list(testdata: T.List[backends.TestSerialisation]) -> T.List[T.Dict else: fname = t.fname to['cmd'] = fname + t.cmd_args - if isinstance(t.env, build.EnvironmentVariables): + if isinstance(t.env, mesonlib.EnvironmentVariables): to['env'] = t.env.get_env({}) else: to['env'] = t.env diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index daac9edb6..b46b30077 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -30,7 +30,6 @@ if T.TYPE_CHECKING: from ..interpreterbase import TYPE_var, TYPE_kwargs from ..programs import OverrideProgram from ..wrap import WrapMode - from ..build import Executable from ..dependencies import Dependency class ModuleState: @@ -87,16 +86,16 @@ class ModuleState: def find_program(self, prog: T.Union[mesonlib.FileOrString, T.List[mesonlib.FileOrString]], required: bool = True, - version_func: T.Optional[T.Callable[[T.Union[ExternalProgram, Executable, OverrideProgram]], str]] = None, + version_func: T.Optional[T.Callable[[T.Union[ExternalProgram, build.Executable, OverrideProgram]], str]] = None, wanted: T.Optional[str] = None, silent: bool = False, - for_machine: MachineChoice = MachineChoice.HOST) -> T.Union[ExternalProgram, Executable, OverrideProgram]: + for_machine: MachineChoice = MachineChoice.HOST) -> T.Union[ExternalProgram, build.Executable, OverrideProgram]: if not isinstance(prog, list): prog = [prog] return self._interpreter.find_program_impl(prog, required=required, version_func=version_func, wanted=wanted, silent=silent, for_machine=for_machine) def find_tool(self, name: str, depname: str, varname: str, required: bool = True, - wanted: T.Optional[str] = None) -> T.Union['Executable', ExternalProgram, 'OverrideProgram']: + wanted: T.Optional[str] = None) -> T.Union['build.Executable', ExternalProgram, 'OverrideProgram']: # Look in overrides in case it's built as subproject progobj = self._interpreter.program_from_overrides([name], []) if progobj is not None: @@ -256,10 +255,10 @@ def is_module_library(fname: mesonlib.FileOrString) -> bool: class ModuleReturnValue: def __init__(self, return_value: T.Optional['TYPE_var'], - new_objects: T.Sequence[T.Union['TYPE_var', 'build.ExecutableSerialisation']]) -> None: + new_objects: T.Sequence[T.Union['TYPE_var', 'mesonlib.ExecutableSerialisation']]) -> None: self.return_value = return_value assert isinstance(new_objects, list) - self.new_objects: T.List[T.Union['TYPE_var', 'build.ExecutableSerialisation']] = new_objects + self.new_objects: T.List[T.Union['TYPE_var', 'mesonlib.ExecutableSerialisation']] = new_objects class GResourceTarget(build.CustomTarget): pass diff --git a/mesonbuild/modules/external_project.py b/mesonbuild/modules/external_project.py index a1d851491..fd7e7c885 100644 --- a/mesonbuild/modules/external_project.py +++ b/mesonbuild/modules/external_project.py @@ -39,6 +39,7 @@ if T.TYPE_CHECKING: from ..build import BuildTarget, CustomTarget from ..interpreter import Interpreter from ..interpreterbase import TYPE_var + from ..mesonlib import EnvironmentVariables class Dependency(TypedDict): @@ -49,7 +50,7 @@ if T.TYPE_CHECKING: configure_options: T.List[str] cross_configure_options: T.List[str] verbose: bool - env: build.EnvironmentVariables + env: EnvironmentVariables depends: T.List[T.Union[BuildTarget, CustomTarget]] @@ -62,7 +63,7 @@ class ExternalProject(NewExtensionModule): configure_command: str, configure_options: T.List[str], cross_configure_options: T.List[str], - env: build.EnvironmentVariables, + env: EnvironmentVariables, verbose: bool, extra_depends: T.List[T.Union['BuildTarget', 'CustomTarget']]): super().__init__() diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 755bf240b..32d53eff7 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -272,7 +272,7 @@ class GnomeModule(ExtensionModule): self.install_gtk_update_icon_cache = False self.install_update_desktop_database = False self.install_update_mime_database = False - self.devenv: T.Optional[build.EnvironmentVariables] = None + self.devenv: T.Optional[mesonlib.EnvironmentVariables] = None self.native_glib_version: T.Optional[str] = None self.methods.update({ 'post_install': self.post_install, @@ -328,7 +328,7 @@ class GnomeModule(ExtensionModule): @noPosargs @FeatureNew('gnome.post_install', '0.57.0') def post_install(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'PostInstall') -> ModuleReturnValue: - rv: T.List['build.ExecutableSerialisation'] = [] + rv: T.List['mesonlib.ExecutableSerialisation'] = [] datadir_abs = os.path.join(state.environment.get_prefix(), state.environment.get_datadir()) if kwargs['glib_compile_schemas'] and not self.install_glib_compile_schemas: self.install_glib_compile_schemas = True @@ -769,7 +769,7 @@ class GnomeModule(ExtensionModule): def _devenv_prepend(self, varname: str, value: str) -> None: if self.devenv is None: - self.devenv = build.EnvironmentVariables() + self.devenv = mesonlib.EnvironmentVariables() self.devenv.prepend(varname, [value]) def postconf_hook(self, b: build.Build) -> None: @@ -1522,7 +1522,7 @@ class GnomeModule(ExtensionModule): check_args = (targetname + '-check', check_cmd) check_workdir = os.path.join(state.environment.get_build_dir(), state.subdir) state.test(check_args, env=check_env, workdir=check_workdir, depends=[custom_target]) - res: T.List[T.Union[build.Target, build.ExecutableSerialisation]] = [custom_target, alias_target] + res: T.List[T.Union[build.Target, mesonlib.ExecutableSerialisation]] = [custom_target, alias_target] if kwargs['install']: res.append(state.backend.get_executable_serialisation(command + t_args, tag='doc')) return ModuleReturnValue(custom_target, res) diff --git a/mesonbuild/modules/hotdoc.py b/mesonbuild/modules/hotdoc.py index ad5ae3079..cf1a2477c 100644 --- a/mesonbuild/modules/hotdoc.py +++ b/mesonbuild/modules/hotdoc.py @@ -20,7 +20,7 @@ import subprocess from mesonbuild import mesonlib from mesonbuild import mlog, build -from mesonbuild.coredata import MesonException +from mesonbuild.mesonlib import MesonException from . import ModuleReturnValue, ModuleInfo from . import ExtensionModule from ..dependencies import Dependency, InternalDependency diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 9f71d952c..c6bc42d09 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -381,7 +381,7 @@ class PkgConfigModule(NewExtensionModule): # Track already generated pkg-config files This is stored as a class # variable so that multiple `import()`s share metadata - devenv: T.Optional[build.EnvironmentVariables] = None + devenv: T.Optional[mesonlib.EnvironmentVariables] = None _metadata: T.ClassVar[T.Dict[str, MetaData]] = {} def __init__(self) -> None: diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index ac74e13dc..1f05f08d4 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -43,7 +43,7 @@ if T.TYPE_CHECKING: from ..dependencies import Dependency from ..interpreter import Interpreter from ..interpreter.kwargs import ExtractRequired - from ..interpreterbase.interpreterbase import TYPE_var, TYPE_kwargs + from ..interpreterbase.baseobjects import TYPE_var, TYPE_kwargs class PyInstallKw(TypedDict): diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 88995c0fe..0e1086c35 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -44,9 +44,9 @@ import xml.etree.ElementTree as et from . import build from . import environment from . import mlog -from .coredata import MesonVersionMismatchException, OptionKey, major_versions_differ +from .coredata import MesonVersionMismatchException, major_versions_differ from .coredata import version as coredata_version -from .mesonlib import (MesonException, OrderedSet, RealPathAction, +from .mesonlib import (MesonException, OptionKey, OrderedSet, RealPathAction, get_wine_shortpath, join_args, split_args, setup_vsenv) from .mintro import get_infodir, load_info_file from .programs import ExternalProgram diff --git a/mesonbuild/programs.py b/mesonbuild/programs.py index 9bf1844c9..13b998193 100644 --- a/mesonbuild/programs.py +++ b/mesonbuild/programs.py @@ -103,13 +103,12 @@ class ExternalProgram(mesonlib.HoldableObject): def get_version(self, interpreter: T.Optional['Interpreter'] = None) -> str: if not self.cached_version: - from . import build raw_cmd = self.get_command() + ['--version'] if interpreter: res = interpreter.run_command_impl(interpreter.current_node, (self, ['--version']), {'capture': True, 'check': True, - 'env': build.EnvironmentVariables()}, + 'env': mesonlib.EnvironmentVariables()}, True) o, e = res.stdout, res.stderr else: diff --git a/mesonbuild/utils/posix.py b/mesonbuild/utils/posix.py index 51c3cd060..cd05d2758 100644 --- a/mesonbuild/utils/posix.py +++ b/mesonbuild/utils/posix.py @@ -20,7 +20,7 @@ from __future__ import annotations import fcntl import typing as T -from .universal import MesonException +from .core import MesonException from .platform import BuildDirLock as BuildDirLockBase __all__ = ['BuildDirLock'] diff --git a/mesonbuild/utils/vsenv.py b/mesonbuild/utils/vsenv.py index 3c2687884..550a8cf54 100644 --- a/mesonbuild/utils/vsenv.py +++ b/mesonbuild/utils/vsenv.py @@ -8,7 +8,8 @@ import shutil import tempfile from .. import mlog -from .universal import MesonException, is_windows, windows_detect_native_arch +from .core import MesonException +from .universal import is_windows, windows_detect_native_arch __all__ = [ diff --git a/mesonbuild/utils/win32.py b/mesonbuild/utils/win32.py index 2bd4cba8d..18ee0d04e 100644 --- a/mesonbuild/utils/win32.py +++ b/mesonbuild/utils/win32.py @@ -20,7 +20,7 @@ from __future__ import annotations import msvcrt import typing as T -from .universal import MesonException +from .core import MesonException from .platform import BuildDirLock as BuildDirLockBase __all__ = ['BuildDirLock']