aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-01-06 15:33:07 -0800
committerJussi Pakkanen <jpakkane@gmail.com>2018-04-17 23:33:31 +0300
commit92487ea33db9d882929d755308853d2ed82abd0d (patch)
tree0272fa81d53e2f08b72e70e906bdc4d0df65f23e /mesonbuild/dependencies
parent1952ef5ae13376084dc277de38ff3a6dafb8e595 (diff)
downloadmeson-92487ea33db9d882929d755308853d2ed82abd0d.zip
meson-92487ea33db9d882929d755308853d2ed82abd0d.tar.gz
meson-92487ea33db9d882929d755308853d2ed82abd0d.tar.bz2
Add partial_dependency method to dependencies
This adds a new method, partial_dependency to all dependencies. These sub dependencies are copies of the original dependency, but with one or more of the attributes replaced with an empty list. This allows creating a sub dependency that has only cflags or drops link_arguments, for example.
Diffstat (limited to 'mesonbuild/dependencies')
-rw-r--r--mesonbuild/dependencies/base.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 2a19544..27a5fcb 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -1,4 +1,4 @@
-# Copyright 2013-2017 The Meson development team
+# Copyright 2013-2018 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
# This file contains the detection logic for external dependencies.
# Custom logic for several other packages are in separate files.
+import copy
import os
import re
import stat
@@ -146,6 +147,23 @@ class Dependency:
def get_configtool_variable(self, variable_name):
raise DependencyException('{!r} is not a config-tool dependency'.format(self.name))
+ def get_partial_dependency(self, *, compile_args=False, link_args=False,
+ links=False, includes=False, sources=False):
+ """Create a new dependency that contains part of the parent dependency.
+
+ The following options can be inherited:
+ links -- all link_with arguemnts
+ includes -- all include_directory and -I/-isystem calls
+ sources -- any source, header, or generated sources
+ compile_args -- any compile args
+ link_args -- any link args
+
+ Additionally the new dependency will have the version parameter of it's
+ parent (if any) and the requested values of any dependencies will be
+ added as well.
+ """
+ RuntimeError('Unreachable code in partial_dependency called')
+
class InternalDependency(Dependency):
def __init__(self, version, incdirs, compile_args, link_args, libraries, whole_libraries, sources, ext_deps):
@@ -168,6 +186,21 @@ class InternalDependency(Dependency):
raise DependencyException('Method "get_configtool_variable()" is '
'invalid for an internal dependency')
+ def get_partial_dependency(self, *, compile_args=False, link_args=False,
+ links=False, includes=False, sources=False):
+ compile_args = self.compile_args.copy() if compile_args else []
+ link_args = self.link_args.copy() if link_args else []
+ libraries = self.libraries.copy() if links else []
+ whole_libraries = self.whole_libraries.copy() if links else []
+ sources = self.sources.copy() if sources else []
+ includes = self.include_directories.copy() if includes else []
+ deps = [d.get_partial_dependency(
+ compile_args=compile_args, link_args=link_args, links=links,
+ includes=includes, sources=sources) for d in self.ext_deps]
+ return InternalDependency(
+ self.version, includes, compile_args, link_args, libraries,
+ whole_libraries, sources, deps)
+
class ExternalDependency(Dependency):
def __init__(self, type_name, environment, language, kwargs):
@@ -211,6 +244,18 @@ class ExternalDependency(Dependency):
def get_compiler(self):
return self.compiler
+ def get_partial_dependency(self, *, compile_args=False, link_args=False,
+ links=False, includes=False, sources=False):
+ new = copy.copy(self)
+ if not compile_args:
+ new.compile_args = []
+ if not link_args:
+ new.link_args = []
+ if not sources:
+ new.sources = []
+
+ return new
+
class ConfigToolDependency(ExternalDependency):
@@ -887,6 +932,15 @@ class ExternalLibrary(ExternalDependency):
return []
return self.link_args
+ def get_partial_dependency(self, *, compile_args=False, link_args=False,
+ links=False, includes=False, sources=False):
+ # External library only has link_args, so ignore the rest of the
+ # interface.
+ new = copy.copy(self)
+ if not link_args:
+ new.link_args = []
+ return new
+
class ExtraFrameworkDependency(ExternalDependency):
def __init__(self, name, required, path, env, lang, kwargs):