Deduplicate command line arguments. Slight improvement to #671.

pull/836/head
Jussi Pakkanen 9 years ago
parent b164ed611b
commit 154763f81b
  1. 21
      mesonbuild/backend/backends.py
  2. 3
      mesonbuild/backend/ninjabackend.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

@ -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]

Loading…
Cancel
Save