From 154763f81bba9b90d734ba92aa6a992123b273fc Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 26 Sep 2016 16:18:17 -0400 Subject: Deduplicate command line arguments. Slight improvement to #671. --- mesonbuild/backend/backends.py | 21 +++++++++++++++++++++ mesonbuild/backend/ninjabackend.py | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) 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] -- cgit v1.1