aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/cmake.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-02-28 15:12:35 -0800
committerDylan Baker <dylan@pnwbakers.com>2022-03-03 10:29:14 -0800
commitf4ae32c2ad4f4912867e1be6333371955bdaf83b (patch)
tree346af978dcb84fea339e658bbeef1cb06e641122 /mesonbuild/modules/cmake.py
parent5e4ea9f0f444120e566e364aba0b12f2520bd9ac (diff)
downloadmeson-f4ae32c2ad4f4912867e1be6333371955bdaf83b.zip
meson-f4ae32c2ad4f4912867e1be6333371955bdaf83b.tar.gz
meson-f4ae32c2ad4f4912867e1be6333371955bdaf83b.tar.bz2
modules/cmake: add type annotations for subproject method
This will be used to handle the interpreter subproject as well
Diffstat (limited to 'mesonbuild/modules/cmake.py')
-rw-r--r--mesonbuild/modules/cmake.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py
index b046371..f996087 100644
--- a/mesonbuild/modules/cmake.py
+++ b/mesonbuild/modules/cmake.py
@@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
+from __future__ import annotations
import re
import os, os.path, pathlib
import shutil
@@ -21,11 +23,10 @@ from . import ExtensionModule, ModuleReturnValue, ModuleObject
from .. import build, mesonlib, mlog, dependencies
from ..cmake import SingleTargetOptions, TargetOptions, cmake_defines_to_args
from ..interpreter import SubprojectHolder
-from ..interpreter.type_checking import NoneType, in_set_validator
+from ..interpreter.type_checking import REQUIRED_KW, NoneType, in_set_validator
from ..interpreterbase import (
FeatureNew,
FeatureNewKwargs,
- FeatureDeprecatedKwargs,
stringArgs,
permittedKwargs,
@@ -35,6 +36,7 @@ from ..interpreterbase import (
InvalidArguments,
InterpreterException,
+ typed_pos_args,
typed_kwargs,
KwargInfo,
ContainerTypeInfo,
@@ -43,6 +45,9 @@ from ..interpreterbase import (
if T.TYPE_CHECKING:
from typing_extensions import TypedDict
+ from . import ModuleState
+ from ..interpreter import kwargs
+
class WriteBasicPackageVersionFile(TypedDict):
arch_independent: bool
@@ -58,6 +63,12 @@ if T.TYPE_CHECKING:
install_dir: T.Optional[str]
name: str
+ class Subproject(kwargs.ExtractRequired):
+
+ options: T.Optional[CMakeSubprojectOptions]
+ cmake_options: T.List[str]
+
+
COMPATIBILITIES = ['AnyNewerVersion', 'SameMajorVersion', 'SameMinorVersion', 'ExactVersion']
# Taken from https://github.com/Kitware/CMake/blob/master/Modules/CMakePackageConfigHelpers.cmake
@@ -91,7 +102,7 @@ endmacro()
'''
class CMakeSubproject(ModuleObject):
- def __init__(self, subp, pv):
+ def __init__(self, subp: SubprojectHolder):
assert isinstance(subp, SubprojectHolder)
assert hasattr(subp, 'cm_interpreter')
super().__init__()
@@ -400,20 +411,28 @@ class CmakeModule(ExtensionModule):
return res
@FeatureNew('subproject', '0.51.0')
- @FeatureNewKwargs('subproject', '0.55.0', ['options'])
- @FeatureDeprecatedKwargs('subproject', '0.55.0', ['cmake_options'])
- @permittedKwargs({'cmake_options', 'required', 'options'})
- @stringArgs
- def subproject(self, state, args, kwargs):
- if len(args) != 1:
- raise InterpreterException('Subproject takes exactly one argument')
- if 'cmake_options' in kwargs and 'options' in kwargs:
+ @typed_pos_args('cmake.subproject', str)
+ @typed_kwargs(
+ 'cmake.subproject',
+ REQUIRED_KW,
+ KwargInfo('options', (CMakeSubprojectOptions, NoneType), since='0.55.0'),
+ KwargInfo(
+ 'cmake_options',
+ ContainerTypeInfo(list, str),
+ default=[],
+ listify=True,
+ deprecated='0.55.0',
+ deprecated_message='Use options instead',
+ ),
+ )
+ def subproject(self, state: ModuleState, args: T.Tuple[str], kwargs: Subproject) -> T.Union[SubprojectHolder, CMakeSubproject]:
+ if kwargs['cmake_options'] and kwargs['options'] is not None:
raise InterpreterException('"options" cannot be used together with "cmake_options"')
dirname = args[0]
subp = self.interpreter.do_subproject(dirname, 'cmake', kwargs)
if not subp.found():
return subp
- return CMakeSubproject(subp, dirname)
+ return CMakeSubproject(subp)
@FeatureNew('subproject_options', '0.55.0')
@noKwargs