diff options
Diffstat (limited to 'mesonbuild/modules')
-rw-r--r-- | mesonbuild/modules/python.py | 54 | ||||
-rw-r--r-- | mesonbuild/modules/qt.py | 73 | ||||
-rw-r--r-- | mesonbuild/modules/sourceset.py | 9 | ||||
-rw-r--r-- | mesonbuild/modules/unstable_external_project.py | 3 | ||||
-rw-r--r-- | mesonbuild/modules/unstable_rust.py | 29 |
5 files changed, 85 insertions, 83 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index f3bcfab..46fd27b 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -50,6 +50,7 @@ class PythonDependency(SystemDependency): self.variables = python_holder.variables self.paths = python_holder.paths self.link_libpython = python_holder.link_libpython + self.info: T.Optional[T.Dict[str, str]] = None if mesonlib.version_compare(self.version, '>= 3.0'): self.major_version = 3 else: @@ -278,12 +279,20 @@ print (json.dumps ({ })) ''' +class PythonExternalProgram(ExternalProgram): + def __init__(self, name: str, command: T.Optional[T.List[str]] = None, ext_prog: T.Optional[ExternalProgram] = None): + if ext_prog is None: + super().__init__(name, command=command, silent=True) + else: + self.name = ext_prog.name + self.command = ext_prog.command + self.path = ext_prog.path + self.info: T.Dict[str, str] = {} class PythonInstallation(ExternalProgramHolder): - def __init__(self, interpreter, python, info): - ExternalProgramHolder.__init__(self, python, interpreter.subproject) - self.interpreter = interpreter - self.subproject = self.interpreter.subproject + def __init__(self, python, interpreter): + ExternalProgramHolder.__init__(self, python, interpreter) + info = python.info prefix = self.interpreter.environment.coredata.get_option(mesonlib.OptionKey('prefix')) self.variables = info['variables'] self.paths = info['paths'] @@ -325,11 +334,10 @@ class PythonInstallation(ExternalProgramHolder): # behavior. See https://github.com/mesonbuild/meson/issues/4117 if not self.link_libpython: new_deps = [] - for holder in mesonlib.extract_as_list(kwargs, 'dependencies'): - dep = holder.held_object + for dep in mesonlib.extract_as_list(kwargs, 'dependencies'): if isinstance(dep, PythonDependency): - holder = self.interpreter.holderify(dep.get_partial_dependency(compile_args=True)) - new_deps.append(holder) + dep = dep.get_partial_dependency(compile_args=True) + new_deps.append(dep) kwargs['dependencies'] = new_deps suffix = self.variables.get('EXT_SUFFIX') or self.variables.get('SO') or self.variables.get('.so') @@ -360,7 +368,7 @@ class PythonInstallation(ExternalProgramHolder): dep = PythonDependency(self, self.interpreter.environment, kwargs) if required and not dep.found(): raise mesonlib.MesonException('Python dependency not found') - return self.interpreter.holderify(dep) + return dep @permittedKwargs(['pure', 'subdir']) def install_sources_method(self, args, kwargs): @@ -377,7 +385,7 @@ class PythonInstallation(ExternalProgramHolder): else: kwargs['install_dir'] = os.path.join(self.platlib_install_path, subdir) - return self.interpreter.holderify(self.interpreter.func_install_data(None, args, kwargs)) + return self.interpreter.func_install_data(None, args, kwargs) @noPosargs @permittedKwargs(['pure', 'subdir']) @@ -519,25 +527,26 @@ class PythonModule(ExtensionModule): if disabled: mlog.log('Program', name_or_path or 'python', 'found:', mlog.red('NO'), '(disabled by:', mlog.bold(feature), ')') - return ExternalProgramHolder(NonExistingExternalProgram(), state.subproject) + return NonExistingExternalProgram() if not name_or_path: - python = ExternalProgram('python3', mesonlib.python_command, silent=True) + python = PythonExternalProgram('python3', mesonlib.python_command) else: - python = ExternalProgram.from_entry('python3', name_or_path) + tmp_python = ExternalProgram.from_entry('python3', name_or_path) + python = PythonExternalProgram('python3', ext_prog=tmp_python) if not python.found() and mesonlib.is_windows(): pythonpath = self._get_win_pythonpath(name_or_path) if pythonpath is not None: name_or_path = pythonpath - python = ExternalProgram(name_or_path, silent=True) + python = PythonExternalProgram(name_or_path) # Last ditch effort, python2 or python3 can be named python # on various platforms, let's not give up just yet, if an executable # named python is available and has a compatible version, let's use # it if not python.found() and name_or_path in ['python2', 'python3']: - python = ExternalProgram('python', silent=True) + python = PythonExternalProgram('python') if python.found() and want_modules: for mod in want_modules: @@ -566,11 +575,11 @@ class PythonModule(ExtensionModule): if not python.found(): if required: raise mesonlib.MesonException('{} not found'.format(name_or_path or 'python')) - res = ExternalProgramHolder(NonExistingExternalProgram(), state.subproject) + return NonExistingExternalProgram() elif missing_modules: if required: raise mesonlib.MesonException('{} is missing modules: {}'.format(name_or_path or 'python', ', '.join(missing_modules))) - res = ExternalProgramHolder(NonExistingExternalProgram(), state.subproject) + return NonExistingExternalProgram() else: # Sanity check, we expect to have something that at least quacks in tune try: @@ -586,14 +595,17 @@ class PythonModule(ExtensionModule): mlog.debug(stderr) if isinstance(info, dict) and 'version' in info and self._check_version(name_or_path, info['version']): - res = PythonInstallation(self.interpreter, python, info) + python.info = info + return python else: - res = ExternalProgramHolder(NonExistingExternalProgram(), state.subproject) if required: raise mesonlib.MesonException(f'{python} is not a valid python or it is missing setuptools') + return NonExistingExternalProgram() - return res + raise mesonlib.MesonBugException('Unreachable code was reached (PythonModule.find_installation).') def initialize(*args, **kwargs): - return PythonModule(*args, **kwargs) + mod = PythonModule(*args, **kwargs) + mod.interpreter.append_holder_map(PythonExternalProgram, PythonInstallation) + return mod diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 8c673de..ae45e4d 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from mesonbuild import coredata import os import shutil import typing as T @@ -20,21 +21,19 @@ import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule from .. import build -from .. import mesonlib from .. import mlog -from ..dependencies import find_external_dependency +from ..dependencies import find_external_dependency, Dependency, ExternalLibrary +from ..mesonlib import MesonException, File, FileOrString, version_compare, Popen_safe +from . import ModuleReturnValue, ExtensionModule from ..interpreter import extract_required_kwarg -from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder, FeatureOptionHolder, GeneratedListHolder from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, KwargInfo, noPosargs, FeatureNew, typed_kwargs -from ..mesonlib import MesonException, File -from ..programs import NonExistingExternalProgram +from ..programs import ExternalProgram, NonExistingExternalProgram if T.TYPE_CHECKING: from . import ModuleState from ..dependencies.qt import QtPkgConfigDependency, QmakeQtDependency from ..interpreter import Interpreter from ..interpreter import kwargs - from ..programs import ExternalProgram QtDependencyType = T.Union[QtPkgConfigDependency, QmakeQtDependency] @@ -45,7 +44,7 @@ if T.TYPE_CHECKING: """Keyword arguments for the Resource Compiler method.""" name: T.Optional[str] - sources: T.List[mesonlib.FileOrString] + sources: T.List[FileOrString] extra_args: T.List[str] method: str @@ -53,7 +52,7 @@ if T.TYPE_CHECKING: """Keyword arguments for the Ui Compiler method.""" - sources: T.List[mesonlib.FileOrString] + sources: T.List[FileOrString] extra_args: T.List[str] method: str @@ -61,25 +60,25 @@ if T.TYPE_CHECKING: """Keyword arguments for the Moc Compiler method.""" - sources: T.List[mesonlib.FileOrString] - headers: T.List[mesonlib.FileOrString] + sources: T.List[FileOrString] + headers: T.List[FileOrString] extra_args: T.List[str] method: str - include_directories: T.List[T.Union[str, IncludeDirsHolder]] - dependencies: T.List[T.Union[DependencyHolder, ExternalLibraryHolder]] + include_directories: T.List[T.Union[str, build.IncludeDirs]] + dependencies: T.List[T.Union[Dependency, ExternalLibrary]] class PreprocessKwArgs(TypedDict): - sources: T.List[mesonlib.FileOrString] - moc_sources: T.List[mesonlib.FileOrString] - moc_headers: T.List[mesonlib.FileOrString] - qresources: T.List[mesonlib.FileOrString] - ui_files: T.List[mesonlib.FileOrString] + sources: T.List[FileOrString] + moc_sources: T.List[FileOrString] + moc_headers: T.List[FileOrString] + qresources: T.List[FileOrString] + ui_files: T.List[FileOrString] moc_extra_arguments: T.List[str] rcc_extra_arguments: T.List[str] uic_extra_arguments: T.List[str] - include_directories: T.List[T.Union[str, IncludeDirsHolder]] - dependencies: T.List[T.Union[DependencyHolder, ExternalLibraryHolder]] + include_directories: T.List[T.Union[str, build.IncludeDirs]] + dependencies: T.List[T.Union[Dependency, ExternalLibrary]] method: str class HasToolKwArgs(kwargs.ExtractRequired): @@ -104,10 +103,10 @@ class QtBaseModule(ExtensionModule): def __init__(self, interpreter: 'Interpreter', qt_version: int = 5): ExtensionModule.__init__(self, interpreter) self.qt_version = qt_version - self.moc: 'ExternalProgram' = NonExistingExternalProgram('moc') - self.uic: 'ExternalProgram' = NonExistingExternalProgram('uic') - self.rcc: 'ExternalProgram' = NonExistingExternalProgram('rcc') - self.lrelease: 'ExternalProgram' = NonExistingExternalProgram('lrelease') + self.moc: ExternalProgram = NonExistingExternalProgram('moc') + self.uic: ExternalProgram = NonExistingExternalProgram('uic') + self.rcc: ExternalProgram = NonExistingExternalProgram('rcc') + self.lrelease: ExternalProgram = NonExistingExternalProgram('lrelease') self.methods.update({ 'has_tools': self.has_tools, 'preprocess': self.preprocess, @@ -141,14 +140,14 @@ class QtBaseModule(ExtensionModule): if name == 'lrelease': arg = ['-version'] - elif mesonlib.version_compare(qt_dep.version, '>= 5'): + elif version_compare(qt_dep.version, '>= 5'): arg = ['--version'] else: arg = ['-v'] # Ensure that the version of qt and each tool are the same - def get_version(p: 'ExternalProgram') -> str: - _, out, err = mesonlib.Popen_safe(p.get_command() + arg) + def get_version(p: ExternalProgram) -> str: + _, out, err = Popen_safe(p.get_command() + arg) if b.startswith('lrelease') or not qt_dep.version.startswith('4'): care = out else: @@ -157,7 +156,7 @@ class QtBaseModule(ExtensionModule): p = state.find_program(b, required=False, version_func=get_version, - wanted=wanted).held_object + wanted=wanted) if p.found(): setattr(self, name, p) @@ -172,7 +171,7 @@ class QtBaseModule(ExtensionModule): if qt.found(): # Get all tools and then make sure that they are the right version self.compilers_detect(state, qt) - if mesonlib.version_compare(qt.version, '>=5.14.0'): + if version_compare(qt.version, '>=5.14.0'): self._rcc_supports_depfiles = True else: mlog.warning('rcc dependencies will not work properly until you move to Qt >= 5.14:', @@ -185,7 +184,7 @@ class QtBaseModule(ExtensionModule): self.lrelease = NonExistingExternalProgram(name='lrelease' + suffix) @staticmethod - def _qrc_nodes(state: 'ModuleState', rcc_file: 'mesonlib.FileOrString') -> T.Tuple[str, T.List[str]]: + def _qrc_nodes(state: 'ModuleState', rcc_file: 'FileOrString') -> T.Tuple[str, T.List[str]]: abspath: str if isinstance(rcc_file, str): abspath = os.path.join(state.environment.source_dir, state.subdir, rcc_file) @@ -210,7 +209,7 @@ class QtBaseModule(ExtensionModule): except Exception: raise MesonException(f'Unable to parse resource file {abspath}') - def _parse_qrc_deps(self, state: 'ModuleState', rcc_file: 'mesonlib.FileOrString') -> T.List[File]: + def _parse_qrc_deps(self, state: 'ModuleState', rcc_file: 'FileOrString') -> T.List[File]: rcc_dirname, nodes = self._qrc_nodes(state, rcc_file) result: T.List[File] = [] for resource_path in nodes: @@ -243,7 +242,7 @@ class QtBaseModule(ExtensionModule): @noPosargs @typed_kwargs( 'qt.has_tools', - KwargInfo('required', (bool, FeatureOptionHolder), default=False), + KwargInfo('required', (bool, coredata.UserFeatureOption), default=False), KwargInfo('method', str, default='auto'), ) def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs: 'HasToolKwArgs') -> bool: @@ -351,7 +350,7 @@ class QtBaseModule(ExtensionModule): kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@'], ['ui_@BASENAME@.h'], name=f'Qt{self.qt_version} ui') - out = GeneratedListHolder(gen.process_files(kwargs['sources'], state)) + out = gen.process_files(kwargs['sources'], state) return ModuleReturnValue(out, [out]) @FeatureNew('qt.compile_moc', '0.59.0') @@ -362,8 +361,8 @@ class QtBaseModule(ExtensionModule): KwargInfo('headers', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True, default=[]), KwargInfo('method', str, default='auto'), - KwargInfo('include_directories', ContainerTypeInfo(list, (IncludeDirsHolder, str)), listify=True, default=[]), - KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True, default=[]), + KwargInfo('include_directories', ContainerTypeInfo(list, (build.IncludeDirs, str)), listify=True, default=[]), + KwargInfo('dependencies', ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), ) def compile_moc(self, state: 'ModuleState', args: T.Tuple, kwargs: 'MocCompilerKwArgs') -> ModuleReturnValue: self._detect_tools(state, kwargs['method']) @@ -378,7 +377,7 @@ class QtBaseModule(ExtensionModule): inc = state.get_include_args(include_dirs=kwargs['include_directories']) compile_args: T.List[str] = [] for dep in kwargs['dependencies']: - compile_args.extend([a for a in dep.held_object.get_all_compile_args() if a.startswith(('-I', '-D'))]) + compile_args.extend([a for a in dep.get_all_compile_args() if a.startswith(('-I', '-D'))]) output: T.List[build.GeneratedList] = [] @@ -408,8 +407,8 @@ class QtBaseModule(ExtensionModule): KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[], since='0.49.0'), KwargInfo('uic_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[], since='0.49.0'), KwargInfo('method', str, default='auto'), - KwargInfo('include_directories', ContainerTypeInfo(list, (IncludeDirsHolder, str)), listify=True, default=[]), - KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True, default=[]), + KwargInfo('include_directories', ContainerTypeInfo(list, (build.IncludeDirs, str)), listify=True, default=[]), + KwargInfo('dependencies', ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), ) def preprocess(self, state: 'ModuleState', args: T.List[T.Union[str, File]], kwargs: 'PreprocessKwArgs') -> ModuleReturnValue: _sources = args[1:] diff --git a/mesonbuild/modules/sourceset.py b/mesonbuild/modules/sourceset.py index eea3dbd..ba8b300 100644 --- a/mesonbuild/modules/sourceset.py +++ b/mesonbuild/modules/sourceset.py @@ -14,16 +14,13 @@ from collections import namedtuple from .. import mesonlib +from .. import build from ..mesonlib import listify, OrderedSet from . import ExtensionModule, ModuleObject, MutableModuleObject from ..interpreterbase import ( noPosargs, noKwargs, permittedKwargs, InterpreterException, InvalidArguments, InvalidCode, FeatureNew, ) -from ..interpreter import ( - GeneratedListHolder, CustomTargetHolder, - CustomTargetIndexHolder -) SourceSetRule = namedtuple('SourceSetRule', 'keys sources if_false sourcesets dependencies extra_deps') SourceFiles = namedtuple('SourceFiles', 'sources dependencies') @@ -49,8 +46,8 @@ class SourceSet(MutableModuleObject): deps = [] for x in arg: if isinstance(x, (str, mesonlib.File, - GeneratedListHolder, CustomTargetHolder, - CustomTargetIndexHolder)): + build.GeneratedList, build.CustomTarget, + build.CustomTargetIndex)): sources.append(x) elif hasattr(x, 'found'): if not allow_deps: diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index f10c7aa..e997f6a 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -22,7 +22,6 @@ from ..mesonlib import (MesonException, Popen_safe, MachineChoice, get_variable_regex, do_replacement, extract_as_list) from ..interpreterbase import InterpreterException, FeatureNew from ..interpreterbase import permittedKwargs, typed_pos_args -from ..interpreter import DependencyHolder from ..compilers.compilers import CFLAGS_MAPPING, CEXE_MAPPING from ..dependencies import InternalDependency, PkgConfigDependency from ..mesonlib import OptionKey @@ -237,7 +236,7 @@ class ExternalProject(ModuleObject): variables = [] dep = InternalDependency(version, incdir, compile_args, link_args, libs, libs_whole, sources, final_deps, variables) - return DependencyHolder(dep, self.subproject) + return dep class ExternalProjectModule(ExtensionModule): diff --git a/mesonbuild/modules/unstable_rust.py b/mesonbuild/modules/unstable_rust.py index e5af2d7..995370a 100644 --- a/mesonbuild/modules/unstable_rust.py +++ b/mesonbuild/modules/unstable_rust.py @@ -19,15 +19,11 @@ from . import ExtensionModule, ModuleReturnValue from .. import mlog from ..build import BuildTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments, IncludeDirs, CustomTarget from ..interpreter.interpreter import TEST_KWARGS -from ..interpreter.interpreterobjects import ( - BuildTargetHolder, - CustomTargetHolder, - DependencyHolder, - ExecutableHolder, - ExternalLibraryHolder, -) from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, permittedKwargs, FeatureNew, typed_kwargs, typed_pos_args, noPosargs -from ..mesonlib import stringlistify, unholder, listify, typeslistify, File +from ..mesonlib import stringlistify, listify, typeslistify, File +from ..dependencies import Dependency, ExternalLibrary +from ..interpreterbase import InterpreterException, permittedKwargs, FeatureNew, typed_pos_args, noPosargs +from ..mesonlib import stringlistify, listify, typeslistify, File if T.TYPE_CHECKING: from . import ModuleState @@ -38,7 +34,7 @@ if T.TYPE_CHECKING: class FuncTest(_kwargs.BaseTest): - dependencies: T.List[T.Union[DependencyHolder, ExternalLibraryHolder]] + dependencies: T.List[T.Union[Dependency, ExternalLibrary]] is_parallel: bool @@ -55,18 +51,18 @@ class RustModule(ExtensionModule): 'bindgen': self.bindgen, }) - @typed_pos_args('rust.test', str, BuildTargetHolder) + @typed_pos_args('rust.test', str, BuildTarget) @typed_kwargs( 'rust.test', *TEST_KWARGS, KwargInfo('is_parallel', bool, default=False), KwargInfo( 'dependencies', - ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), + ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), ) - def test(self, state: 'ModuleState', args: T.Tuple[str, BuildTargetHolder], kwargs: 'FuncTest') -> ModuleReturnValue: + def test(self, state: 'ModuleState', args: T.Tuple[str, BuildTarget], kwargs: 'FuncTest') -> ModuleReturnValue: """Generate a rust test target from a given rust target. Rust puts it's unitests inside it's main source files, unlike most @@ -151,11 +147,10 @@ class RustModule(ExtensionModule): new_target_kwargs ) - e = ExecutableHolder(new_target, self.interpreter) test = self.interpreter.make_test( - self.interpreter.current_node, (name, e), tkwargs) + self.interpreter.current_node, (name, new_target), tkwargs) - return ModuleReturnValue(None, [e, test]) + return ModuleReturnValue(None, [new_target, test]) @noPosargs @permittedKwargs({'input', 'output', 'include_directories', 'c_args', 'args'}) @@ -184,7 +179,7 @@ class RustModule(ExtensionModule): bind_args: T.List[str] = stringlistify(listify(kwargs.get('args', []))) # Split File and Target dependencies to add pass to CustomTarget - depends: T.List[T.Union[GeneratedList, BuildTarget, CustomTargetIndex]] = [] + depends: T.List[T.Union[GeneratedList, BuildTarget, CustomTargetIndex, CustomTarget]] = [] depend_files: T.List[File] = [] for d in _deps: if isinstance(d, File): @@ -225,7 +220,7 @@ class RustModule(ExtensionModule): backend=state.backend, ) - return ModuleReturnValue([target], [CustomTargetHolder(target, self.interpreter)]) + return ModuleReturnValue([target], [target]) def initialize(*args: T.List, **kwargs: T.Dict) -> RustModule: |