diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2020-01-27 18:29:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-27 18:29:22 +0200 |
commit | a51c9af921d0ba05aa173b8a1a4351eacb575be0 (patch) | |
tree | 8207935e73c6c8e82f8c38c1ff130cbfe5642249 /mesonbuild/dependencies/base.py | |
parent | 9e07f8d8e6bb088252ac11b3e663ff3d93c8020a (diff) | |
parent | 202c89d0b665a536a738c59dcde1f374047a346e (diff) | |
download | meson-a51c9af921d0ba05aa173b8a1a4351eacb575be0.zip meson-a51c9af921d0ba05aa173b8a1a4351eacb575be0.tar.gz meson-a51c9af921d0ba05aa173b8a1a4351eacb575be0.tar.bz2 |
Merge pull request #6423 from dcbaker/declare-dependency-variables
Add ability to set and query arbitrary variables on declare_dependency objects
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r-- | mesonbuild/dependencies/base.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 282c314..e9cf9ac 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -223,7 +223,8 @@ class Dependency: self.ext_deps.append(dep_type(env, kwargs)) def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, - configtool: T.Optional[str] = None, default_value: T.Optional[str] = None, + configtool: T.Optional[str] = None, internal: T.Optional[str] = None, + default_value: T.Optional[str] = None, pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]: if default_value is not None: return default_value @@ -235,7 +236,8 @@ class Dependency: return new_dep class InternalDependency(Dependency): - def __init__(self, version, incdirs, compile_args, link_args, libraries, whole_libraries, sources, ext_deps): + def __init__(self, version, incdirs, compile_args, link_args, libraries, + whole_libraries, sources, ext_deps, variables: T.Dict[str, T.Any]): super().__init__('internal', {}) self.version = version self.is_found = True @@ -246,6 +248,7 @@ class InternalDependency(Dependency): self.whole_libraries = whole_libraries self.sources = sources self.ext_deps = ext_deps + self.variables = variables def get_pkgconfig_variable(self, variable_name, kwargs): raise DependencyException('Method "get_pkgconfig_variable()" is ' @@ -270,7 +273,17 @@ class InternalDependency(Dependency): return InternalDependency( self.version, final_includes, final_compile_args, final_link_args, final_libraries, final_whole_libraries, - final_sources, final_deps) + final_sources, final_deps, self.variables) + + def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, + configtool: T.Optional[str] = None, internal: T.Optional[str] = None, + default_value: T.Optional[str] = None, + pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]: + val = self.variables.get(internal, default_value) + if val is not None: + return val + raise DependencyException('Could not get an internal variable and no default provided for {!r}'.format(self)) + class HasNativeKwarg: def __init__(self, kwargs): @@ -554,7 +567,8 @@ class ConfigToolDependency(ExternalDependency): return self.type_name def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, - configtool: T.Optional[str] = None, default_value: T.Optional[str] = None, + configtool: T.Optional[str] = None, internal: T.Optional[str] = None, + default_value: T.Optional[str] = None, pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]: if configtool: # In the not required case '' (empty string) will be returned if the @@ -1013,7 +1027,8 @@ class PkgConfigDependency(ExternalDependency): return self.type_name def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, - configtool: T.Optional[str] = None, default_value: T.Optional[str] = None, + configtool: T.Optional[str] = None, internal: T.Optional[str] = None, + default_value: T.Optional[str] = None, pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]: if pkgconfig: kwargs = {} @@ -1550,7 +1565,8 @@ project(MesonTemp LANGUAGES {}) return '' def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, - configtool: T.Optional[str] = None, default_value: T.Optional[str] = None, + configtool: T.Optional[str] = None, internal: T.Optional[str] = None, + default_value: T.Optional[str] = None, pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]: if cmake: try: |