diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 4570b0033..bc2b74ac3 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1144,7 +1144,8 @@ class Backend: ifilename = os.path.join(self.environment.get_build_dir(), 'depmf.json') ofilename = os.path.join(self.environment.get_prefix(), self.build.dep_manifest_name) out_name = os.path.join('{prefix}', self.build.dep_manifest_name) - mfobj = {'type': 'dependency manifest', 'version': '1.0', 'projects': self.build.dep_manifest} + mfobj = {'type': 'dependency manifest', 'version': '1.0', + 'projects': {k: v.to_json() for k, v in self.build.dep_manifest.items()}} with open(ifilename, 'w', encoding='utf-8') as f: f.write(json.dumps(mfobj)) # Copy file from, to, and with mode unchanged diff --git a/mesonbuild/build.py b/mesonbuild/build.py index ed3fc076a..464b0961b 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -206,6 +206,19 @@ class InstallDir(HoldableObject): self.install_tag = install_tag +class DepManifest: + + def __init__(self, version: str, license: T.List[str]): + self.version = version + self.license = license + + def to_json(self) -> T.Dict[str, T.Union[str, T.List[str]]]: + return { + 'version': self.version, + 'license': self.license, + } + + class Build: """A class that holds the status of one build including all dependencies and so on. @@ -235,7 +248,7 @@ class Build: self.dist_scripts: T.List['ExecutableSerialisation'] = [] self.install_dirs: T.List[InstallDir] = [] self.dep_manifest_name: T.Optional[str] = None - self.dep_manifest: T.Dict[str, T.Dict[str, T.Any]] = {} # TODO: what should this dict be? + self.dep_manifest: T.Dict[str, DepManifest] = {} self.stdlibs = PerMachine({}, {}) self.test_setups: T.Dict[str, TestSetup] = {} self.test_setup_default_name = None diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 1d360eb99..c6aafb93f 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1060,8 +1060,7 @@ external dependencies (including libraries) must go to "dependencies".''') if self.build.project_version is None: self.build.project_version = self.project_version proj_license = mesonlib.stringlistify(kwargs.get('license', 'unknown')) - self.build.dep_manifest[proj_name] = {'version': self.project_version, - 'license': proj_license} + self.build.dep_manifest[proj_name] = build.DepManifest(self.project_version, proj_license) if self.subproject in self.build.projects: raise InvalidCode('Second call to project().') diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index 144029c3d..8c62f87f0 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -384,14 +384,14 @@ class MesonMain(MesonInterpreterObject): @noPosargs @noKwargs - def project_version_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str: - return self.build.dep_manifest[self.interpreter.active_projectname]['version'] + def project_version_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> T.List[str]: + return self.build.dep_manifest[self.interpreter.active_projectname].version @FeatureNew('meson.project_license()', '0.45.0') @noPosargs @noKwargs def project_license_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str: - return self.build.dep_manifest[self.interpreter.active_projectname]['license'] + return self.build.dep_manifest[self.interpreter.active_projectname].license @noPosargs @noKwargs diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 8f641200a..0129909a5 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -45,7 +45,7 @@ class ModuleState: self.current_lineno = interpreter.current_lineno self.environment = interpreter.environment self.project_name = interpreter.build.project_name - self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname] + self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname].version # The backend object is under-used right now, but we will need it: # https://github.com/mesonbuild/meson/issues/1419 self.backend = interpreter.backend diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index f73e16882..7be479667 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -12,18 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os from pathlib import PurePath +import os +import typing as T +from . import ExtensionModule +from . import ModuleReturnValue from .. import build from .. import dependencies -from ..dependencies import ThreadDependency from .. import mesonlib from .. import mlog -from . import ModuleReturnValue -from . import ExtensionModule +from ..dependencies import ThreadDependency from ..interpreterbase import permittedKwargs, FeatureNew, FeatureNewKwargs +if T.TYPE_CHECKING: + from . import ModuleState + already_warned_objs = set() class DependenciesHelper: @@ -451,8 +455,8 @@ class PkgConfigModule(ExtensionModule): 'install_dir', 'extra_cflags', 'variables', 'url', 'd_module_versions', 'dataonly', 'conflicts', 'uninstalled_variables', 'unescaped_variables', 'unescaped_uninstalled_variables'}) - def generate(self, state, args, kwargs): - default_version = state.project_version['version'] + def generate(self, state: 'ModuleState', args, kwargs): + default_version = state.project_version default_install_dir = None default_description = None default_name = None diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index 8bd3c1c4a..87b0ab694 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -232,7 +232,7 @@ class ExternalProject(NewExtensionModule): abs_includedir = Path(abs_includedir, subdir) abs_libdir = Path(self.install_dir, self.rel_prefix, self.libdir) - version = self.project_version['version'] + version = self.project_version incdir = [] compile_args = [f'-I{abs_includedir}'] link_args = [f'-L{abs_libdir}', f'-l{libname}']