diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-12-06 16:14:22 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-12-27 20:29:46 -0500 |
commit | 2fa074917597fea0cf3332c6620d3414034825e4 (patch) | |
tree | 787dc86c8affa560710340a76dcdbbbf7794ff86 /mesonbuild | |
parent | 26b83eee9427889b5b006079872aa288bc0ffaed (diff) | |
download | meson-2fa074917597fea0cf3332c6620d3414034825e4.zip meson-2fa074917597fea0cf3332c6620d3414034825e4.tar.gz meson-2fa074917597fea0cf3332c6620d3414034825e4.tar.bz2 |
add license_files kwarg to project
Hook this up to installed dependency manifests. This is often needed
above and beyond just an SPDX string -- e.g. many licenses have custom
copyright lines.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/backend/backends.py | 8 | ||||
-rw-r--r-- | mesonbuild/build.py | 3 | ||||
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 19 | ||||
-rw-r--r-- | mesonbuild/interpreter/mesonmain.py | 8 |
4 files changed, 35 insertions, 3 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 27004f8..843af5d 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1191,7 +1191,9 @@ class Backend: return ifilename = os.path.join(self.environment.get_build_dir(), 'depmf.json') ofilename = os.path.join(self.environment.get_prefix(), self.build.dep_manifest_name) + odirname = os.path.join(self.environment.get_prefix(), os.path.dirname(self.build.dep_manifest_name)) out_name = os.path.join('{prefix}', self.build.dep_manifest_name) + out_dir = os.path.join('{prefix}', os.path.dirname(self.build.dep_manifest_name)) 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: @@ -1199,6 +1201,12 @@ class Backend: # Copy file from, to, and with mode unchanged d.data.append(InstallDataBase(ifilename, ofilename, out_name, None, '', tag='devel', data_type='depmf')) + for m in self.build.dep_manifest.values(): + for ifilename, name in m.license_files: + ofilename = os.path.join(odirname, name.relative_name()) + out_name = os.path.join(out_dir, name.relative_name()) + d.data.append(InstallDataBase(ifilename, ofilename, out_name, None, + m.subproject, tag='devel', data_type='depmf')) def get_regen_filelist(self) -> T.List[str]: '''List of all files whose alteration means that the build diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 60cd0cf..db2c309 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -216,11 +216,14 @@ class InstallDir(HoldableObject): class DepManifest: version: str license: T.List[str] + license_files: T.List[T.Tuple[str, File]] + subproject: str def to_json(self) -> T.Dict[str, T.Union[str, T.List[str]]]: return { 'version': self.version, 'license': self.license, + 'license_files': [l[1].relative_name() for l in self.license_files], } diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index f112e4e..5347120 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1132,7 +1132,8 @@ class Interpreter(InterpreterBase, HoldableObject): validator=_project_version_validator, convertor=lambda x: x[0] if isinstance(x, list) else x, ), - KwargInfo('license', ContainerTypeInfo(list, str), default=['unknown'], listify=True), + KwargInfo('license', (ContainerTypeInfo(list, str), NoneType), default=None, listify=True), + KwargInfo('license_files', ContainerTypeInfo(list, str), default=[], listify=True, since='1.1.0'), KwargInfo('subproject_dir', str, default='subprojects'), ) def func_project(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str]], kwargs: 'kwtypes.Project') -> None: @@ -1198,8 +1199,20 @@ class Interpreter(InterpreterBase, HoldableObject): if self.build.project_version is None: self.build.project_version = self.project_version - proj_license = kwargs['license'] - self.build.dep_manifest[proj_name] = build.DepManifest(self.project_version, proj_license) + + if kwargs['license'] is None: + proj_license = ['unknown'] + if kwargs['license_files']: + raise InvalidArguments('Project `license` name must be specified when `license_files` is set') + else: + proj_license = kwargs['license'] + proj_license_files = [] + for i in self.source_strings_to_files(kwargs['license_files']): + ifname = i.absolute_path(self.environment.source_dir, + self.environment.build_dir) + proj_license_files.append((ifname, i)) + self.build.dep_manifest[proj_name] = build.DepManifest(self.project_version, proj_license, + proj_license_files, self.subproject) 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 01d0029..1a902ad 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2012-2021 The Meson development team # Copyright © 2021 Intel Corporation +from __future__ import annotations import os import typing as T @@ -74,6 +75,7 @@ class MesonMain(MesonInterpreterObject): 'override_find_program': self.override_find_program_method, 'project_version': self.project_version_method, 'project_license': self.project_license_method, + 'project_license_files': self.project_license_files_method, 'version': self.version_method, 'project_name': self.project_name_method, 'get_cross_property': self.get_cross_property_method, @@ -400,6 +402,12 @@ class MesonMain(MesonInterpreterObject): def project_license_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> T.List[str]: return self.build.dep_manifest[self.interpreter.active_projectname].license + @FeatureNew('meson.project_license_files()', '1.1.0') + @noPosargs + @noKwargs + def project_license_files_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> T.List[mesonlib.File]: + return [l[1] for l in self.build.dep_manifest[self.interpreter.active_projectname].license_files] + @noPosargs @noKwargs def version_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> MesonVersionString: |