summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/compilers.py')
-rw-r--r--mesonbuild/compilers.py86
1 files changed, 55 insertions, 31 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 833071ea8..979a5ac18 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -430,6 +430,17 @@ class CompilerArgs(list):
to recursively search for symbols in the libraries. This is not needed
with other linkers.
'''
+
+ # A standalone argument must never be deduplicated because it is
+ # defined by what comes _after_ it. Thus dedupping this:
+ # -D FOO -D BAR
+ # would yield either
+ # -D FOO BAR
+ # or
+ # FOO -D BAR
+ # both of which are invalid.
+ if arg in cls.dedup2_prefixes:
+ return 0
if arg in cls.dedup2_args or \
arg.startswith(cls.dedup2_prefixes) or \
arg.endswith(cls.dedup2_suffixes):
@@ -465,6 +476,19 @@ class CompilerArgs(list):
self.insert(i + 1, '-Wl,--end-group')
return self.compiler.unix_args_to_native(self)
+ def append_direct(self, arg):
+ '''
+ Append the specified argument without any reordering or de-dup
+ '''
+ super().append(arg)
+
+ def extend_direct(self, iterable):
+ '''
+ Extend using the elements in the specified iterable without any
+ reordering or de-dup
+ '''
+ super().extend(iterable)
+
def __add__(self, args):
new = CompilerArgs(self, self.compiler)
new += args
@@ -731,35 +755,35 @@ class Compiler:
raise EnvironmentException('Language %s does not support linking whole archives.' % self.language)
def build_unix_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
- if not rpath_paths and not install_rpath:
- return []
- # The rpaths we write must be relative, because otherwise
- # they have different length depending on the build
- # directory. This breaks reproducible builds.
- rel_rpaths = []
- for p in rpath_paths:
- if p == from_dir:
- relative = '' # relpath errors out in this case
- else:
- relative = os.path.relpath(p, from_dir)
- rel_rpaths.append(relative)
- paths = ':'.join([os.path.join('$ORIGIN', p) for p in rel_rpaths])
- if len(paths) < len(install_rpath):
- padding = 'X' * (len(install_rpath) - len(paths))
- if not paths:
- paths = padding
- else:
- paths = paths + ':' + padding
- args = ['-Wl,-rpath,' + paths]
- if get_compiler_is_linuxlike(self):
- # Rpaths to use while linking must be absolute. These are not
- # written to the binary. Needed only with GNU ld:
- # https://sourceware.org/bugzilla/show_bug.cgi?id=16936
- # Not needed on Windows or other platforms that don't use RPATH
- # https://github.com/mesonbuild/meson/issues/1897
- lpaths = ':'.join([os.path.join(build_dir, p) for p in rpath_paths])
- args += ['-Wl,-rpath-link,' + lpaths]
- return args
+ if not rpath_paths and not install_rpath:
+ return []
+ # The rpaths we write must be relative, because otherwise
+ # they have different length depending on the build
+ # directory. This breaks reproducible builds.
+ rel_rpaths = []
+ for p in rpath_paths:
+ if p == from_dir:
+ relative = '' # relpath errors out in this case
+ else:
+ relative = os.path.relpath(p, from_dir)
+ rel_rpaths.append(relative)
+ paths = ':'.join([os.path.join('$ORIGIN', p) for p in rel_rpaths])
+ if len(paths) < len(install_rpath):
+ padding = 'X' * (len(install_rpath) - len(paths))
+ if not paths:
+ paths = padding
+ else:
+ paths = paths + ':' + padding
+ args = ['-Wl,-rpath,' + paths]
+ if get_compiler_is_linuxlike(self):
+ # Rpaths to use while linking must be absolute. These are not
+ # written to the binary. Needed only with GNU ld:
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=16936
+ # Not needed on Windows or other platforms that don't use RPATH
+ # https://github.com/mesonbuild/meson/issues/1897
+ lpaths = ':'.join([os.path.join(build_dir, p) for p in rpath_paths])
+ args += ['-Wl,-rpath-link,' + lpaths]
+ return args
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
@@ -1029,7 +1053,7 @@ class CCompiler(Compiler):
def _links_wrapper(self, code, env, extra_args, dependencies):
"Shares common code between self.links and self.run"
args = self._get_compiler_check_args(env, extra_args, dependencies, mode='link')
- return self.compile(code, args.to_native())
+ return self.compile(code, args)
def links(self, code, env, extra_args=None, dependencies=None):
with self._links_wrapper(code, env, extra_args, dependencies) as p:
@@ -1773,7 +1797,7 @@ class ValaCompiler(Compiler):
for d in extra_dirs:
vapi = os.path.join(d, libname + '.vapi')
if os.path.isfile(vapi):
- return vapi
+ return [vapi]
mlog.debug('Searched {!r} and {!r} wasn\'t found'.format(extra_dirs, libname))
return None