aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-02-21 05:09:05 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-02-21 22:56:55 +0530
commit510553f437d2f7514bf97527c499574b1880c748 (patch)
tree0cc079b42ea110a033580b4fa0d265dc6ea60106
parentc708c52ca22503f2d798ba12c4654bad90d4fe0c (diff)
downloadmeson-510553f437d2f7514bf97527c499574b1880c748.zip
meson-510553f437d2f7514bf97527c499574b1880c748.tar.gz
meson-510553f437d2f7514bf97527c499574b1880c748.tar.bz2
macOS: Remove more unused linkerlike args
`-L` and `-headerpad_max_install_names` are both linker arguments that are commonly passed in CFLAGS too. Closes https://github.com/mesonbuild/meson/issues/6294
-rw-r--r--mesonbuild/compilers/compilers.py20
-rwxr-xr-xrun_unittests.py5
2 files changed, 24 insertions, 1 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 0e52a82..2f1e104 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1065,7 +1065,25 @@ class Compiler:
return self.linker.get_undefined_link_args()
def remove_linkerlike_args(self, args):
- return [x for x in args if not x.startswith('-Wl')]
+ rm_exact = ('-headerpad_max_install_names',)
+ rm_prefixes = ('-Wl,', '-L',)
+ rm_next = ('-L',)
+ ret = []
+ iargs = iter(args)
+ for arg in iargs:
+ # Remove this argument
+ if arg in rm_exact:
+ continue
+ # If the argument starts with this, but is not *exactly* this
+ # f.ex., '-L' should match ['-Lfoo'] but not ['-L', 'foo']
+ if arg.startswith(rm_prefixes) and arg not in rm_prefixes:
+ continue
+ # Ignore this argument and the one after it
+ if arg in rm_next:
+ next(iargs)
+ continue
+ ret.append(arg)
+ return ret
def get_lto_compile_args(self) -> T.List[str]:
return []
diff --git a/run_unittests.py b/run_unittests.py
index fe88f52..b42b9db 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -4796,6 +4796,11 @@ class DarwinTests(BasePlatformTests):
self.build()
self.install()
+ def test_removing_unused_linker_args(self):
+ testdir = os.path.join(self.common_test_dir, '108 has arg')
+ env = {'CFLAGS': '-L/tmp -L /var/tmp -headerpad_max_install_names -Wl,-export_dynamic'}
+ self.init(testdir, override_envvars=env)
+
@unittest.skipUnless(not is_windows(), "requires something Unix-like")
class LinuxlikeTests(BasePlatformTests):