From 79aec5f34226330712f606bf3655aa2d25377927 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 24 Aug 2018 04:16:48 +0530 Subject: CompilerArgs: Allow calling to_native() multiple times Add a keyword argument to to_native() to operate on a copy so that we can call it multiple times instead of modifying the original compiler args while iterating. This is used in the unit test, and might be used in Meson at some point too. --- mesonbuild/compilers/compilers.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'mesonbuild/compilers/compilers.py') diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 5af4b5d..95f937d 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -602,16 +602,20 @@ class CompilerArgs(list): return True return False - def to_native(self): + def to_native(self, copy=False): # Check if we need to add --start/end-group for circular dependencies # between static libraries, and for recursively searching for symbols # needed by static libraries that are provided by object files or # shared libraries. + if copy: + new = self.copy() + else: + new = self if get_compiler_uses_gnuld(self.compiler): global soregex group_start = -1 group_end = -1 - for i, each in enumerate(self): + for i, each in enumerate(new): if not each.startswith('-l') and not each.endswith('.a') and \ not soregex.match(each): continue @@ -621,9 +625,9 @@ class CompilerArgs(list): group_start = i if group_start >= 0: # Last occurrence of a library - self.insert(group_end + 1, '-Wl,--end-group') - self.insert(group_start, '-Wl,--start-group') - return self.compiler.unix_args_to_native(self) + new.insert(group_end + 1, '-Wl,--end-group') + new.insert(group_start, '-Wl,--start-group') + return self.compiler.unix_args_to_native(new) def append_direct(self, arg): ''' -- cgit v1.1