dependencies/base: Add a new method for setting internal dependencies
When we create a dependency as part of another dependency (say Threads), we want to pass down most of the methods (like required). Currently however, there is the possibility that we can pass down invalid keyword arguments, such as 'method'. This new method is meant to work around that my simplifying and centralizing how we pass these dependencies down.
This commit is contained in:
parent
98b7b0f5c2
commit
0654b1a2b1
|
@ -25,6 +25,7 @@ import textwrap
|
|||
import platform
|
||||
import itertools
|
||||
import ctypes
|
||||
import typing
|
||||
from typing import Any, Dict, List, Tuple
|
||||
from enum import Enum
|
||||
from pathlib import Path, PurePath
|
||||
|
@ -73,6 +74,8 @@ class Dependency:
|
|||
@classmethod
|
||||
def _process_method_kw(cls, kwargs):
|
||||
method = kwargs.get('method', 'auto')
|
||||
if isinstance(method, DependencyMethods):
|
||||
return method
|
||||
if method not in [e.value for e in DependencyMethods]:
|
||||
raise DependencyException('method {!r} is invalid'.format(method))
|
||||
method = DependencyMethods(method)
|
||||
|
@ -176,6 +179,20 @@ class Dependency:
|
|||
"""
|
||||
raise RuntimeError('Unreachable code in partial_dependency called')
|
||||
|
||||
def _add_sub_dependency(self, dep_type: typing.Type['Dependency'], env: Environment,
|
||||
kwargs: typing.Dict[str, typing.Any], *,
|
||||
method: DependencyMethods = DependencyMethods.AUTO) -> None:
|
||||
"""Add an internal dependency of of the given type.
|
||||
|
||||
This method is intended to simplify cases of adding a dependency on
|
||||
another dependency type (such as threads). This will by default set
|
||||
the method back to auto, but the 'method' keyword argument can be
|
||||
used to overwrite this behavior.
|
||||
"""
|
||||
kwargs = kwargs.copy()
|
||||
kwargs['method'] = method
|
||||
self.ext_deps.append(dep_type(env, kwargs))
|
||||
|
||||
|
||||
class InternalDependency(Dependency):
|
||||
def __init__(self, version, incdirs, compile_args, link_args, libraries, whole_libraries, sources, ext_deps):
|
||||
|
|
Loading…
Reference in New Issue