aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-09-26 16:18:17 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2016-09-28 16:18:08 -0400
commit154763f81bba9b90d734ba92aa6a992123b273fc (patch)
tree5e0d31486b5620c22d389c61dd73cea8545d675a
parentb164ed611b7a66a2d760c34f3c9653ccd92d23ff (diff)
downloadmeson-154763f81bba9b90d734ba92aa6a992123b273fc.zip
meson-154763f81bba9b90d734ba92aa6a992123b273fc.tar.gz
meson-154763f81bba9b90d734ba92aa6a992123b273fc.tar.bz2
Deduplicate command line arguments. Slight improvement to #671.
-rw-r--r--mesonbuild/backend/backends.py21
-rw-r--r--mesonbuild/backend/ninjabackend.py3
2 files changed, 23 insertions, 1 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 4139ace..5681f7c 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -630,3 +630,24 @@ class Backend():
for s in self.build.postconf_scripts:
cmd = s['exe'].get_command() + s['args']
subprocess.check_call(cmd, env=child_env)
+
+ # Subprojects of subprojects may cause the same dep args to be used
+ # multiple times. Remove duplicates here. Note that we can't dedup
+ # libraries based on name alone, because "-lfoo -lbar -lfoo" is
+ # a completely valid (though pathological) sequence and removing the
+ # latter may fail. Usually only applies to static libs, though.
+ def dedup_arguments(self, commands):
+ includes = {}
+ final_commands = []
+ previous = '-fsuch_arguments=woof'
+ for c in commands:
+ if c.startswith(('-I' '-L', '/LIBPATH')):
+ if c in includes:
+ continue
+ includes[c] = True
+ if previous == c:
+ continue
+ previous = c
+ final_commands.append(c)
+ return final_commands
+
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 251f7ee..41f96f1 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1674,6 +1674,7 @@ rule FORTRAN_DEP_HACK
element.add_orderdep(d)
element.add_orderdep(pch_dep)
element.add_orderdep(extra_orderdeps)
+ commands = self.dedup_arguments(commands)
for i in self.get_fortran_orderdeps(target, compiler):
element.add_orderdep(i)
element.add_item('DEPFILE', dep_file)
@@ -1836,7 +1837,7 @@ rule FORTRAN_DEP_HACK
custom_target_libraries = self.get_custom_target_provided_libraries(target)
commands += extra_args
commands += custom_target_libraries
- commands = linker.unix_link_flags_to_native(commands)
+ commands = linker.unix_link_flags_to_native(self.dedup_arguments(commands))
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]