aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-04-19 15:32:24 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2017-05-08 20:59:46 +0200
commit7053d9abfdef64c1f507173609fad4c9866441eb (patch)
tree0eaa78e007a8c69066dfa152490edc64e01da636 /mesonbuild
parentccab7d64f474f00e010b2c6601e63d8034c5552a (diff)
downloadmeson-7053d9abfdef64c1f507173609fad4c9866441eb.zip
meson-7053d9abfdef64c1f507173609fad4c9866441eb.tar.gz
meson-7053d9abfdef64c1f507173609fad4c9866441eb.tar.bz2
Allow link_depends to take strings, Files or generated objects. Closes #1172
Currently only strings can be passed to the link_depends argument of executable and *library, which solves many cases, but not every one. This patch allows generated sources and Files to be passed as well. On the implementation side, it uses a helper method to keep the more complex logic separated from the __init__ method. This also requires that Targets set their link_depends paths as Files, and the backend is responsible for converting to strings when it wants them. This adds tests for the following cases: - Using a file in a subdir - Using a configure_file as an input - Using a custom_target as an input It does not support using a generator as an input, since currently that would require calling the generator twice, once for the -Wl argument, and once for the link_depends. Also updates the docs.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py10
-rw-r--r--mesonbuild/build.py41
2 files changed, 39 insertions, 12 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index f4c78a1..bbae408 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2316,8 +2316,8 @@ rule FORTRAN_DEP_HACK
# current compiler.
commands = commands.to_native()
dep_targets = [self.get_dependency_filename(t) for t in dependencies]
- dep_targets += [os.path.join(self.environment.source_dir,
- target.subdir, t) for t in target.link_depends]
+ dep_targets.extend([self.get_dependency_filename(t)
+ for t in target.link_depends])
elem = NinjaBuildElement(self.all_outputs, outname, linker_rule, obj_list)
elem.add_dep(dep_targets + custom_target_libraries)
elem.add_item('LINK_ARGS', commands)
@@ -2335,6 +2335,12 @@ rule FORTRAN_DEP_HACK
def get_dependency_filename(self, t):
if isinstance(t, build.SharedLibrary):
return os.path.join(self.get_target_private_dir(t), self.get_target_filename(t) + '.symbols')
+ elif isinstance(t, mesonlib.File):
+ if t.is_built:
+ return t.relative_name()
+ else:
+ return t.absolute_path(self.environment.get_source_dir(),
+ self.environment.get_build_dir())
return self.get_target_filename(t)
def generate_shlib_aliases(self, target, outdir):
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 1f1018f..0d58394 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -503,6 +503,34 @@ class BuildTarget(Target):
assert(len(self.compilers) == 1)
return
+ def process_link_depends(self, sources, environment):
+ """Process the link_depends keyword argument.
+
+ This is designed to handle strings, Files, and the output of Custom
+ Targets. Notably it doesn't handle generator() returned objects, since
+ adding them as a link depends would inherently cause them to be
+ generated twice, since the output needs to be passed to the ld_args and
+ link_depends.
+ """
+ if not isinstance(sources, list):
+ sources = [sources]
+ for s in sources:
+ if hasattr(s, 'held_object'):
+ s = s.held_object
+
+ if isinstance(s, File):
+ self.link_depends.append(s)
+ elif isinstance(s, str):
+ self.link_depends.append(
+ File.from_source_file(environment.source_dir, self.subdir, s))
+ elif hasattr(s, 'get_outputs'):
+ self.link_depends.extend(
+ [File.from_built_file(s.subdir, p) for p in s.get_outputs()])
+ else:
+ raise InvalidArguments(
+ 'Link_depends arguments must be strings, Files, '
+ 'or a Custom Target, or lists thereof.')
+
def get_original_kwargs(self):
return self.kwargs
@@ -616,12 +644,7 @@ class BuildTarget(Target):
for i in self.link_args:
if not isinstance(i, str):
raise InvalidArguments('Link_args arguments must be strings.')
- self.link_depends = kwargs.get('link_depends', [])
- if not isinstance(self.link_depends, list):
- self.link_depends = [self.link_depends]
- for i in self.link_depends:
- if not isinstance(i, str):
- raise InvalidArguments('Link_depends arguments must be strings.')
+ self.process_link_depends(kwargs.get('link_depends', []), environment)
# Target-specific include dirs must be added BEFORE include dirs from
# internal deps (added inside self.add_deps()) to override them.
inclist = kwargs.get('include_directories', [])
@@ -1264,13 +1287,11 @@ class SharedLibrary(BuildTarget):
self.vs_module_defs = File.from_absolute_file(path)
else:
self.vs_module_defs = File.from_source_file(environment.source_dir, self.subdir, path)
- # link_depends can be an absolute path or relative to self.subdir
- self.link_depends.append(path)
+ self.link_depends.append(self.vs_module_defs)
elif isinstance(path, File):
# When passing a generated file.
self.vs_module_defs = path
- # link_depends can be an absolute path or relative to self.subdir
- self.link_depends.append(path.absolute_path(environment.source_dir, environment.build_dir))
+ self.link_depends.append(path)
else:
raise InvalidArguments(
'Shared library vs_module_defs must be either a string, '